diff --git a/dist/cjs/js/dom-util.js b/dist/cjs/js/dom-util.js index 1972abff..5cd47070 100644 --- a/dist/cjs/js/dom-util.js +++ b/dist/cjs/js/dom-util.js @@ -1,2 +1,2 @@ -var h=Object.create;var c=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var k=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var M=(e,t)=>{for(var r in t)c(e,r,{get:t[r],enumerable:!0})},d=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of _(t))!I.call(e,o)&&o!==r&&c(e,o,{get:()=>t[o],enumerable:!(s=C(t,o))||s.enumerable});return e};var v=(e,t,r)=>(r=e!=null?h(k(e)):{},d(t||!e||!e.__esModule?c(r,"default",{value:e,enumerable:!0}):r,e)),P=e=>d(c({},"__esModule",{value:!0}),e);var A={};M(A,{getDirectionality:()=>m,getNamespaceURI:()=>w,getSlottedTextContent:()=>f,isContentEditable:()=>O,isInShadowTree:()=>D,isInclusive:()=>$,isNamespaceDeclared:()=>S,isPreceding:()=>g,prepareDOMObjects:()=>U,sortNodes:()=>R,verifyNode:()=>E});module.exports=P(A);var x=v(require("bidi-js"),1),i=require("./constant.js");const E=e=>{if(!e||!e.nodeType||!e.nodeName){const r=`Unexpected type ${Object.prototype.toString.call(e).slice(i.TYPE_FROM,i.TYPE_TO)}`;throw new TypeError(r)}else if(!(e.nodeType===i.DOCUMENT_NODE||e.nodeType===i.DOCUMENT_FRAGMENT_NODE||e.nodeType===i.ELEMENT_NODE)){const t=`Unexpected node ${e.nodeName}`;throw new TypeError(t)}return e},U=e=>{e=E(e);let t,r;switch(e.nodeType){case i.DOCUMENT_NODE:{t=e,r=e;break}case i.DOCUMENT_FRAGMENT_NODE:{t=e.ownerDocument,r=e;break}case i.ELEMENT_NODE:default:{t=e.ownerDocument;let o=e;for(;o&&o.parentNode;)o=o.parentNode;r=o;break}}return[t.defaultView,t,r]},D=(e={})=>{let t;if(e.nodeType===i.ELEMENT_NODE||e.nodeType===i.DOCUMENT_FRAGMENT_NODE){let r=e;for(;r;){const{host:s,mode:o,nodeType:a,parentNode:p}=r;if(s&&o&&a===i.DOCUMENT_FRAGMENT_NODE&&i.REG_SHADOW_MODE.test(o)){t=!0;break}r=p}}return!!t},f=(e={})=>{let t;if(e.localName==="slot"&&D(e)){const r=e.assignedNodes();if(r.length){for(const s of r)if(t=s.textContent.trim(),t)break}else t=e.textContent.trim()}return t??null},m=(e={})=>{let t;if(e.nodeType===i.ELEMENT_NODE){const{dir:r,localName:s,parentNode:o}=e,{getEmbeddingLevels:a}=(0,x.default)(),p=/^(?:ltr|rtl)$/;if(p.test(r))t=r;else if(r==="auto"){let l;switch(s){case"input":{(!e.type||/^(?:(?:butto|hidde)n|(?:emai|te|ur)l|(?:rese|submi|tex)t|password|search)$/.test(e.type))&&(l=e.value);break}case"slot":{l=f(e);break}case"textarea":{l=e.value;break}default:{const n=[].slice.call(e.childNodes);for(const u of n){const{dir:T,localName:N,nodeType:y,textContent:b}=u;if(y===i.TEXT_NODE?l=b.trim():y===i.ELEMENT_NODE&&!/^(?:bdi|s(?:cript|tyle)|textarea)$/.test(N)&&(!T||!p.test(T))&&(N==="slot"?l=f(u):l=b.trim()),l)break}}}if(l){const{paragraphs:[{level:n}]}=a(l);n%2===1?t="rtl":t="ltr"}if(!t)if(o){const{nodeType:n}=o;n===i.ELEMENT_NODE?t=m(o):(n===i.DOCUMENT_NODE||n===i.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}else t="ltr"}else if(s==="bdi"){const l=e.textContent.trim();if(l){const{paragraphs:[{level:n}]}=a(l);n%2===1?t="rtl":t="ltr"}t||o||(t="ltr")}else if(s==="input"&&e.type==="tel")t="ltr";else if(o){if(s==="slot"){const l=f(e);if(l){const{paragraphs:[{level:n}]}=a(l);n%2===1?t="rtl":t="ltr"}}if(!t){const{nodeType:l}=o;l===i.ELEMENT_NODE?t=m(o):(l===i.DOCUMENT_NODE||l===i.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}}else t="ltr"}return t??null},O=(e={})=>{let t;if(e.nodeType===i.ELEMENT_NODE){if(typeof e.isContentEditable=="boolean")t=e.isContentEditable;else if(e.ownerDocument.designMode==="on")t=!0;else if(e.hasAttribute("contenteditable")){const r=e.getAttribute("contenteditable");if(r===""||/^(?:plaintext-only|true)$/.test(r))t=!0;else if(r==="inherit"){let s=e.parentNode;for(;s;){if(O(s)){t=!0;break}s=s.parentNode}}}}return!!t},w=(e,t)=>{let r;if(e&&typeof e=="string"&&t?.nodeType===i.ELEMENT_NODE){const{attributes:s}=t;for(const o of s){const{name:a,namespaceURI:p,prefix:l,value:n}=o;if(a===`xmlns:${e}`){r=n;break}else if(l===e){r=p;break}}}return r??null},S=(e="",t={})=>{let r;if(e&&typeof e=="string"&&t.nodeType===i.ELEMENT_NODE){const s=t.ownerDocument.documentElement;let o=t;for(;o&&(r=w(e,o),!(r||o===s));)o=o.parentNode}return!!r},$=(e={},t={})=>{let r;if(e.nodeType===i.ELEMENT_NODE&&t.nodeType===i.ELEMENT_NODE){const s=t.compareDocumentPosition(e);r=s&i.DOCUMENT_POSITION_CONTAINS||s&i.DOCUMENT_POSITION_CONTAINED_BY}return!!r},g=(e={},t={})=>{let r;if(e.nodeType===i.ELEMENT_NODE&&t.nodeType===i.ELEMENT_NODE){const s=t.compareDocumentPosition(e);r=s&i.DOCUMENT_POSITION_PRECEDING||s&i.DOCUMENT_POSITION_CONTAINS}return!!r},R=(e=[])=>{const t=[...e];return t.length>1&&t.sort((r,s)=>{let o;return g(s,r)?o=1:o=-1,o}),t};0&&(module.exports={getDirectionality,getNamespaceURI,getSlottedTextContent,isContentEditable,isInShadowTree,isInclusive,isNamespaceDeclared,isPreceding,prepareDOMObjects,sortNodes,verifyNode}); +var h=Object.create;var c=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var k=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var M=(e,t)=>{for(var r in t)c(e,r,{get:t[r],enumerable:!0})},x=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of _(t))!I.call(e,o)&&o!==r&&c(e,o,{get:()=>t[o],enumerable:!(s=C(t,o))||s.enumerable});return e};var U=(e,t,r)=>(r=e!=null?h(k(e)):{},x(t||!e||!e.__esModule?c(r,"default",{value:e,enumerable:!0}):r,e)),v=e=>x(c({},"__esModule",{value:!0}),e);var A={};M(A,{getDirectionality:()=>m,getNamespaceURI:()=>w,getSlottedTextContent:()=>f,isContentEditable:()=>O,isInShadowTree:()=>D,isInclusive:()=>R,isNamespaceDeclared:()=>S,isPreceding:()=>g,prepareDOMObjects:()=>P,sortNodes:()=>$,verifyNode:()=>d});module.exports=v(A);var E=U(require("bidi-js"),1),i=require("./constant.js");const d=e=>{if(!e||!e.nodeType||!e.nodeName){const r=`Unexpected type ${Object.prototype.toString.call(e).slice(i.TYPE_FROM,i.TYPE_TO)}`;throw new TypeError(r)}else if(!(e.nodeType===i.DOCUMENT_NODE||e.nodeType===i.DOCUMENT_FRAGMENT_NODE||e.nodeType===i.ELEMENT_NODE)){const t=`Unexpected node ${e.nodeName}`;throw new TypeError(t)}return e},P=e=>{e=d(e);let t,r;switch(e.nodeType){case i.DOCUMENT_NODE:{t=e,r=e;break}case i.DOCUMENT_FRAGMENT_NODE:{t=e.ownerDocument,r=e;break}case i.ELEMENT_NODE:default:{t=e.ownerDocument;let o=e;for(;o&&o.parentNode;)o=o.parentNode;r=o;break}}return[t.defaultView,t,r]},D=(e={})=>{let t;if(e.nodeType===i.ELEMENT_NODE||e.nodeType===i.DOCUMENT_FRAGMENT_NODE){let r=e;for(;r;){const{host:s,mode:o,nodeType:a,parentNode:p}=r;if(s&&o&&a===i.DOCUMENT_FRAGMENT_NODE&&i.REG_SHADOW_MODE.test(o)){t=!0;break}r=p}}return!!t},f=(e={})=>{let t;if(e.localName==="slot"&&D(e)){const r=e.assignedNodes();if(r.length){for(const s of r)if(t=s.textContent.trim(),t)break}else t=e.textContent.trim()}return t??null},m=(e={})=>{let t;if(e.nodeType===i.ELEMENT_NODE){const{dir:r,localName:s,parentNode:o}=e,{getEmbeddingLevels:a}=(0,E.default)(),p=/^(?:ltr|rtl)$/;if(p.test(r))t=r;else if(r==="auto"){let l;switch(s){case"input":{(!e.type||/^(?:(?:butto|hidde)n|(?:emai|te|ur)l|(?:rese|submi|tex)t|password|search)$/.test(e.type))&&(l=e.value);break}case"slot":{l=f(e);break}case"textarea":{l=e.value;break}default:{const n=[].slice.call(e.childNodes);for(const u of n){const{dir:T,localName:N,nodeType:y,textContent:b}=u;if(y===i.TEXT_NODE?l=b.trim():y===i.ELEMENT_NODE&&!/^(?:bdi|s(?:cript|tyle)|textarea)$/.test(N)&&(!T||!p.test(T))&&(N==="slot"?l=f(u):l=b.trim()),l)break}}}if(l){const{paragraphs:[{level:n}]}=a(l);n%2===1?t="rtl":t="ltr"}if(!t)if(o){const{nodeType:n}=o;n===i.ELEMENT_NODE?t=m(o):(n===i.DOCUMENT_NODE||n===i.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}else t="ltr"}else if(s==="bdi"){const l=e.textContent.trim();if(l){const{paragraphs:[{level:n}]}=a(l);n%2===1?t="rtl":t="ltr"}t||o||(t="ltr")}else if(s==="input"&&e.type==="tel")t="ltr";else if(o){if(s==="slot"){const l=f(e);if(l){const{paragraphs:[{level:n}]}=a(l);n%2===1?t="rtl":t="ltr"}}if(!t){const{nodeType:l}=o;l===i.ELEMENT_NODE?t=m(o):(l===i.DOCUMENT_NODE||l===i.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}}else t="ltr"}return t??null},O=(e={})=>{let t;if(e.nodeType===i.ELEMENT_NODE){if(typeof e.isContentEditable=="boolean")t=e.isContentEditable;else if(e.ownerDocument.designMode==="on")t=!0;else if(e.hasAttribute("contenteditable")){const r=e.getAttribute("contenteditable");if(r===""||/^(?:plaintext-only|true)$/.test(r))t=!0;else if(r==="inherit"){let s=e.parentNode;for(;s;){if(O(s)){t=!0;break}s=s.parentNode}}}}return!!t},w=(e,t)=>{let r;if(e&&typeof e=="string"&&t?.nodeType===i.ELEMENT_NODE){const{attributes:s}=t;for(const o of s){const{name:a,namespaceURI:p,prefix:l,value:n}=o;if(a===`xmlns:${e}`){r=n;break}else if(l===e){r=p;break}}}return r??null},S=(e="",t={})=>{let r;if(e&&typeof e=="string"&&t.nodeType===i.ELEMENT_NODE&&(r=t.lookupNamespaceURI(e),!r)){const s=t.ownerDocument.documentElement;let o=t;for(;o&&(r=w(e,o),!(r||o===s));)o=o.parentNode}return!!r},R=(e={},t={})=>{let r;if(e.nodeType===i.ELEMENT_NODE&&t.nodeType===i.ELEMENT_NODE){const s=t.compareDocumentPosition(e);r=s&i.DOCUMENT_POSITION_CONTAINS||s&i.DOCUMENT_POSITION_CONTAINED_BY}return!!r},g=(e={},t={})=>{let r;if(e.nodeType===i.ELEMENT_NODE&&t.nodeType===i.ELEMENT_NODE){const s=t.compareDocumentPosition(e);r=s&i.DOCUMENT_POSITION_PRECEDING||s&i.DOCUMENT_POSITION_CONTAINS}return!!r},$=(e=[])=>{const t=[...e];return t.length>1&&t.sort((r,s)=>{let o;return g(s,r)?o=1:o=-1,o}),t};0&&(module.exports={getDirectionality,getNamespaceURI,getSlottedTextContent,isContentEditable,isInShadowTree,isInclusive,isNamespaceDeclared,isPreceding,prepareDOMObjects,sortNodes,verifyNode}); //# sourceMappingURL=dom-util.js.map diff --git a/dist/cjs/js/dom-util.js.map b/dist/cjs/js/dom-util.js.map index e24ba5b8..3fecda71 100644 --- a/dist/cjs/js/dom-util.js.map +++ b/dist/cjs/js/dom-util.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../../../src/js/dom-util.js"], - "sourcesContent": ["/**\n * dom-util.js\n */\n\n/* import */\nimport bidiFactory from 'bidi-js';\n\n/* constants */\nimport {\n DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINS,\n DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_PRECEDING, ELEMENT_NODE,\n REG_SHADOW_MODE, TEXT_NODE, TYPE_FROM, TYPE_TO\n} from './constant.js';\n\n/**\n * verify node\n * @param {*} node - node\n * @throws\n * @returns {object} - Document, DocumentFragment, Element node\n */\nexport const verifyNode = node => {\n if (!node || !node.nodeType || !node.nodeName) {\n const type = Object.prototype.toString.call(node).slice(TYPE_FROM, TYPE_TO);\n const msg = `Unexpected type ${type}`;\n throw new TypeError(msg);\n } else if (!(node.nodeType === DOCUMENT_NODE ||\n node.nodeType === DOCUMENT_FRAGMENT_NODE ||\n node.nodeType === ELEMENT_NODE)) {\n const msg = `Unexpected node ${node.nodeName}`;\n throw new TypeError(msg);\n }\n return node;\n};\n\n/**\n * prepare window, document, root node\n * @param {object} node - Document, DocumentFragment, Element node\n * @returns {Array.} - array of window, document, root node\n */\nexport const prepareDOMObjects = node => {\n node = verifyNode(node);\n let document;\n let root;\n switch (node.nodeType) {\n case DOCUMENT_NODE: {\n document = node;\n root = node;\n break;\n }\n case DOCUMENT_FRAGMENT_NODE: {\n document = node.ownerDocument;\n root = node;\n break;\n }\n case ELEMENT_NODE:\n default: {\n document = node.ownerDocument;\n let parent = node;\n while (parent) {\n if (parent.parentNode) {\n parent = parent.parentNode;\n } else {\n break;\n }\n }\n root = parent;\n break;\n }\n }\n // NOTE: nullable\n const window = document.defaultView;\n return [\n window,\n document,\n root\n ];\n};\n\n/**\n * is in shadow tree\n * @param {object} node - node\n * @returns {boolean} - result;\n */\nexport const isInShadowTree = (node = {}) => {\n let bool;\n if (node.nodeType === ELEMENT_NODE ||\n node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n let refNode = node;\n while (refNode) {\n const { host, mode, nodeType, parentNode } = refNode;\n if (host && mode && nodeType === DOCUMENT_FRAGMENT_NODE &&\n REG_SHADOW_MODE.test(mode)) {\n bool = true;\n break;\n }\n refNode = parentNode;\n }\n }\n return !!bool;\n};\n\n/**\n * get slotted text content\n * @param {object} node - Element node\n * @returns {?string} - text content\n */\nexport const getSlottedTextContent = (node = {}) => {\n let res;\n if (node.localName === 'slot' && isInShadowTree(node)) {\n const nodes = node.assignedNodes();\n if (nodes.length) {\n for (const item of nodes) {\n res = item.textContent.trim();\n if (res) {\n break;\n }\n }\n } else {\n res = node.textContent.trim();\n }\n }\n return res ?? null;\n};\n\n/**\n * get directionality of node\n * @see https://html.spec.whatwg.org/multipage/dom.html#the-dir-attribute\n * @param {object} node - Element node\n * @returns {?string} - 'ltr' / 'rtl'\n */\nexport const getDirectionality = (node = {}) => {\n let res;\n if (node.nodeType === ELEMENT_NODE) {\n const { dir: nodeDir, localName, parentNode } = node;\n const { getEmbeddingLevels } = bidiFactory();\n const regDir = /^(?:ltr|rtl)$/;\n if (regDir.test(nodeDir)) {\n res = nodeDir;\n } else if (nodeDir === 'auto') {\n let text;\n switch (localName) {\n case 'input': {\n if (!node.type || /^(?:(?:butto|hidde)n|(?:emai|te|ur)l|(?:rese|submi|tex)t|password|search)$/.test(node.type)) {\n text = node.value;\n }\n break;\n }\n case 'slot': {\n text = getSlottedTextContent(node);\n break;\n }\n case 'textarea': {\n text = node.value;\n break;\n }\n default: {\n const items = [].slice.call(node.childNodes);\n for (const item of items) {\n const {\n dir: itemDir, localName: itemLocalName, nodeType: itemNodeType,\n textContent: itemTextContent\n } = item;\n if (itemNodeType === TEXT_NODE) {\n text = itemTextContent.trim();\n } else if (itemNodeType === ELEMENT_NODE) {\n if (!/^(?:bdi|s(?:cript|tyle)|textarea)$/.test(itemLocalName) &&\n (!itemDir || !regDir.test(itemDir))) {\n if (itemLocalName === 'slot') {\n text = getSlottedTextContent(item);\n } else {\n text = itemTextContent.trim();\n }\n }\n }\n if (text) {\n break;\n }\n }\n }\n }\n if (text) {\n const { paragraphs: [{ level }] } = getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n if (!res) {\n if (parentNode) {\n const { nodeType: parentNodeType } = parentNode;\n if (parentNodeType === ELEMENT_NODE) {\n res = getDirectionality(parentNode);\n } else if (parentNodeType === DOCUMENT_NODE ||\n parentNodeType === DOCUMENT_FRAGMENT_NODE) {\n res = 'ltr';\n }\n } else {\n res = 'ltr';\n }\n }\n } else if (localName === 'bdi') {\n const text = node.textContent.trim();\n if (text) {\n const { paragraphs: [{ level }] } = getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n if (!(res || parentNode)) {\n res = 'ltr';\n }\n } else if (localName === 'input' && node.type === 'tel') {\n res = 'ltr';\n } else if (parentNode) {\n if (localName === 'slot') {\n const text = getSlottedTextContent(node);\n if (text) {\n const { paragraphs: [{ level }] } = getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n }\n if (!res) {\n const { nodeType: parentNodeType } = parentNode;\n if (parentNodeType === ELEMENT_NODE) {\n res = getDirectionality(parentNode);\n } else if (parentNodeType === DOCUMENT_NODE ||\n parentNodeType === DOCUMENT_FRAGMENT_NODE) {\n res = 'ltr';\n }\n }\n } else {\n res = 'ltr';\n }\n }\n return res ?? null;\n};\n\n/**\n * is content editable\n * NOTE: not implemented in jsdom https://github.com/jsdom/jsdom/issues/1670\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isContentEditable = (node = {}) => {\n let res;\n if (node.nodeType === ELEMENT_NODE) {\n if (typeof node.isContentEditable === 'boolean') {\n res = node.isContentEditable;\n } else if (node.ownerDocument.designMode === 'on') {\n res = true;\n } else if (node.hasAttribute('contenteditable')) {\n const attr = node.getAttribute('contenteditable');\n if (attr === '' || /^(?:plaintext-only|true)$/.test(attr)) {\n res = true;\n } else if (attr === 'inherit') {\n let parent = node.parentNode;\n while (parent) {\n if (isContentEditable(parent)) {\n res = true;\n break;\n }\n parent = parent.parentNode;\n }\n }\n }\n }\n return !!res;\n};\n\n/**\n * get namespace URI\n * @param {string} ns - namespace prefix\n * @param {Array} node - Element node\n * @returns {?string} - namespace URI\n */\nexport const getNamespaceURI = (ns, node) => {\n let res;\n if (ns && typeof ns === 'string' && node?.nodeType === ELEMENT_NODE) {\n const { attributes } = node;\n for (const attr of attributes) {\n const { name, namespaceURI, prefix, value } = attr;\n if (name === `xmlns:${ns}`) {\n res = value;\n break;\n } else if (prefix === ns) {\n res = namespaceURI;\n break;\n }\n }\n }\n return res ?? null;\n};\n\n/**\n * is namespace declared\n * @param {string} ns - namespace\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isNamespaceDeclared = (ns = '', node = {}) => {\n let res;\n if (ns && typeof ns === 'string' && node.nodeType === ELEMENT_NODE) {\n const root = node.ownerDocument.documentElement;\n let parent = node;\n while (parent) {\n res = getNamespaceURI(ns, parent);\n if (res || parent === root) {\n break;\n }\n parent = parent.parentNode;\n }\n }\n return !!res;\n};\n\n/**\n * is inclusive - nodeA and nodeB are in inclusive relation\n * @param {object} nodeA - Element node\n * @param {object} nodeB - Element node\n * @returns {boolean} - result\n */\nexport const isInclusive = (nodeA = {}, nodeB = {}) => {\n let res;\n if (nodeA.nodeType === ELEMENT_NODE && nodeB.nodeType === ELEMENT_NODE) {\n const posBit = nodeB.compareDocumentPosition(nodeA);\n res = posBit & DOCUMENT_POSITION_CONTAINS ||\n posBit & DOCUMENT_POSITION_CONTAINED_BY;\n }\n return !!res;\n};\n\n/**\n * is preceding - nodeA precedes and/or contains nodeB\n * @param {object} nodeA - Element node\n * @param {object} nodeB - Element node\n * @returns {boolean} - result\n */\nexport const isPreceding = (nodeA = {}, nodeB = {}) => {\n let res;\n if (nodeA.nodeType === ELEMENT_NODE && nodeB.nodeType === ELEMENT_NODE) {\n const posBit = nodeB.compareDocumentPosition(nodeA);\n res = posBit & DOCUMENT_POSITION_PRECEDING ||\n posBit & DOCUMENT_POSITION_CONTAINS;\n }\n return !!res;\n};\n\n/**\n * sort nodes\n * @param {Array.|Set.} nodes - collection of nodes\n * @returns {Array.} - collection of sorted nodes\n */\nexport const sortNodes = (nodes = []) => {\n const arr = [...nodes];\n if (arr.length > 1) {\n arr.sort((a, b) => {\n let res;\n if (isPreceding(b, a)) {\n res = 1;\n } else {\n res = -1;\n }\n return res;\n });\n }\n return arr;\n};\n"], - "mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,EAAA,oBAAAC,EAAA,0BAAAC,EAAA,sBAAAC,EAAA,mBAAAC,EAAA,gBAAAC,EAAA,wBAAAC,EAAA,gBAAAC,EAAA,sBAAAC,EAAA,cAAAC,EAAA,eAAAC,IAAA,eAAAC,EAAAb,GAKA,IAAAc,EAAwB,wBAGxBC,EAIO,yBAQA,MAAMH,EAAaI,GAAQ,CAChC,GAAI,CAACA,GAAQ,CAACA,EAAK,UAAY,CAACA,EAAK,SAAU,CAE7C,MAAMC,EAAM,mBADC,OAAO,UAAU,SAAS,KAAKD,CAAI,EAAE,MAAM,YAAW,SAAO,CACvC,GACnC,MAAM,IAAI,UAAUC,CAAG,CACzB,SAAW,EAAED,EAAK,WAAa,iBAClBA,EAAK,WAAa,0BAClBA,EAAK,WAAa,gBAAe,CAC5C,MAAMC,EAAM,mBAAmBD,EAAK,QAAQ,GAC5C,MAAM,IAAI,UAAUC,CAAG,CACzB,CACA,OAAOD,CACT,EAOaN,EAAoBM,GAAQ,CACvCA,EAAOJ,EAAWI,CAAI,EACtB,IAAIE,EACAC,EACJ,OAAQH,EAAK,SAAU,CACrB,KAAK,gBAAe,CAClBE,EAAWF,EACXG,EAAOH,EACP,KACF,CACA,KAAK,yBAAwB,CAC3BE,EAAWF,EAAK,cAChBG,EAAOH,EACP,KACF,CACA,KAAK,eACL,QAAS,CACPE,EAAWF,EAAK,cAChB,IAAII,EAASJ,EACb,KAAOI,GACDA,EAAO,YACTA,EAASA,EAAO,WAKpBD,EAAOC,EACP,KACF,CACF,CAGA,MAAO,CADQF,EAAS,YAGtBA,EACAC,CACF,CACF,EAOab,EAAiB,CAACU,EAAO,CAAC,IAAM,C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G,EAAOH,EAAK,cAAc,gBAChC,IAAII,EAASJ,EACb,KAAOI,IACLO,EAAMxB,EAAgByC,EAAIxB,CAAM,EAC5B,EAAAO,GAAOP,IAAWD,KAGtBC,EAASA,EAAO,UAEpB,CACA,MAAO,CAAC,CAACO,CACX,EAQapB,EAAc,CAAC2C,EAAQ,CAAC,EAAGC,EAAQ,CAAC,IAAM,CACrD,IAAIxB,EACJ,GAAIuB,EAAM,WAAa,gBAAgBC,EAAM,WAAa,eAAc,CACtE,MAAMC,EAASD,EAAM,wBAAwBD,CAAK,EAClDvB,EAAMyB,EAAS,8BACTA,EAAS,gCACjB,CACA,MAAO,CAAC,CAACzB,CACX,EAQalB,EAAc,CAACyC,EAAQ,CAAC,EAAGC,EAAQ,CAAC,IAAM,CACrD,IAAIxB,EACJ,GAAIuB,EAAM,WAAa,gBAAgBC,EAAM,WAAa,eAAc,CACtE,MAAMC,EAASD,EAAM,wBAAwBD,CAAK,EAClDvB,EAAMyB,EAAS,+BACTA,EAAS,4BACjB,CACA,MAAO,CAAC,CAACzB,CACX,EAOahB,EAAY,CAACiB,EAAQ,CAAC,IAAM,CACvC,MAAMyB,EAAM,CAAC,GAAGzB,CAAK,EACrB,OAAIyB,EAAI,OAAS,GACfA,EAAI,KAAK,CAACC,EAAGC,IAAM,CACjB,IAAI5B,EACJ,OAAIlB,EAAY8C,EAAGD,CAAC,EAClB3B,EAAM,EAENA,EAAM,GAEDA,CACT,CAAC,EAEI0B,CACT", + "sourcesContent": ["/**\n * dom-util.js\n */\n\n/* import */\nimport bidiFactory from 'bidi-js';\n\n/* constants */\nimport {\n DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINS,\n DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_PRECEDING, ELEMENT_NODE,\n REG_SHADOW_MODE, TEXT_NODE, TYPE_FROM, TYPE_TO\n} from './constant.js';\n\n/**\n * verify node\n * @param {*} node - node\n * @throws\n * @returns {object} - Document, DocumentFragment, Element node\n */\nexport const verifyNode = node => {\n if (!node || !node.nodeType || !node.nodeName) {\n const type = Object.prototype.toString.call(node).slice(TYPE_FROM, TYPE_TO);\n const msg = `Unexpected type ${type}`;\n throw new TypeError(msg);\n } else if (!(node.nodeType === DOCUMENT_NODE ||\n node.nodeType === DOCUMENT_FRAGMENT_NODE ||\n node.nodeType === ELEMENT_NODE)) {\n const msg = `Unexpected node ${node.nodeName}`;\n throw new TypeError(msg);\n }\n return node;\n};\n\n/**\n * prepare window, document, root node\n * @param {object} node - Document, DocumentFragment, Element node\n * @returns {Array.} - array of window, document, root node\n */\nexport const prepareDOMObjects = node => {\n node = verifyNode(node);\n let document;\n let root;\n switch (node.nodeType) {\n case DOCUMENT_NODE: {\n document = node;\n root = node;\n break;\n }\n case DOCUMENT_FRAGMENT_NODE: {\n document = node.ownerDocument;\n root = node;\n break;\n }\n case ELEMENT_NODE:\n default: {\n document = node.ownerDocument;\n let parent = node;\n while (parent) {\n if (parent.parentNode) {\n parent = parent.parentNode;\n } else {\n break;\n }\n }\n root = parent;\n break;\n }\n }\n // NOTE: nullable\n const window = document.defaultView;\n return [\n window,\n document,\n root\n ];\n};\n\n/**\n * is in shadow tree\n * @param {object} node - node\n * @returns {boolean} - result;\n */\nexport const isInShadowTree = (node = {}) => {\n let bool;\n if (node.nodeType === ELEMENT_NODE ||\n node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n let refNode = node;\n while (refNode) {\n const { host, mode, nodeType, parentNode } = refNode;\n if (host && mode && nodeType === DOCUMENT_FRAGMENT_NODE &&\n REG_SHADOW_MODE.test(mode)) {\n bool = true;\n break;\n }\n refNode = parentNode;\n }\n }\n return !!bool;\n};\n\n/**\n * get slotted text content\n * @param {object} node - Element node\n * @returns {?string} - text content\n */\nexport const getSlottedTextContent = (node = {}) => {\n let res;\n if (node.localName === 'slot' && isInShadowTree(node)) {\n const nodes = node.assignedNodes();\n if (nodes.length) {\n for (const item of nodes) {\n res = item.textContent.trim();\n if (res) {\n break;\n }\n }\n } else {\n res = node.textContent.trim();\n }\n }\n return res ?? null;\n};\n\n/**\n * get directionality of node\n * @see https://html.spec.whatwg.org/multipage/dom.html#the-dir-attribute\n * @param {object} node - Element node\n * @returns {?string} - 'ltr' / 'rtl'\n */\nexport const getDirectionality = (node = {}) => {\n let res;\n if (node.nodeType === ELEMENT_NODE) {\n const { dir: nodeDir, localName, parentNode } = node;\n const { getEmbeddingLevels } = bidiFactory();\n const regDir = /^(?:ltr|rtl)$/;\n if (regDir.test(nodeDir)) {\n res = nodeDir;\n } else if (nodeDir === 'auto') {\n let text;\n switch (localName) {\n case 'input': {\n if (!node.type || /^(?:(?:butto|hidde)n|(?:emai|te|ur)l|(?:rese|submi|tex)t|password|search)$/.test(node.type)) {\n text = node.value;\n }\n break;\n }\n case 'slot': {\n text = getSlottedTextContent(node);\n break;\n }\n case 'textarea': {\n text = node.value;\n break;\n }\n default: {\n const items = [].slice.call(node.childNodes);\n for (const item of items) {\n const {\n dir: itemDir, localName: itemLocalName, nodeType: itemNodeType,\n textContent: itemTextContent\n } = item;\n if (itemNodeType === TEXT_NODE) {\n text = itemTextContent.trim();\n } else if (itemNodeType === ELEMENT_NODE) {\n if (!/^(?:bdi|s(?:cript|tyle)|textarea)$/.test(itemLocalName) &&\n (!itemDir || !regDir.test(itemDir))) {\n if (itemLocalName === 'slot') {\n text = getSlottedTextContent(item);\n } else {\n text = itemTextContent.trim();\n }\n }\n }\n if (text) {\n break;\n }\n }\n }\n }\n if (text) {\n const { paragraphs: [{ level }] } = getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n if (!res) {\n if (parentNode) {\n const { nodeType: parentNodeType } = parentNode;\n if (parentNodeType === ELEMENT_NODE) {\n res = getDirectionality(parentNode);\n } else if (parentNodeType === DOCUMENT_NODE ||\n parentNodeType === DOCUMENT_FRAGMENT_NODE) {\n res = 'ltr';\n }\n } else {\n res = 'ltr';\n }\n }\n } else if (localName === 'bdi') {\n const text = node.textContent.trim();\n if (text) {\n const { paragraphs: [{ level }] } = getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n if (!(res || parentNode)) {\n res = 'ltr';\n }\n } else if (localName === 'input' && node.type === 'tel') {\n res = 'ltr';\n } else if (parentNode) {\n if (localName === 'slot') {\n const text = getSlottedTextContent(node);\n if (text) {\n const { paragraphs: [{ level }] } = getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n }\n if (!res) {\n const { nodeType: parentNodeType } = parentNode;\n if (parentNodeType === ELEMENT_NODE) {\n res = getDirectionality(parentNode);\n } else if (parentNodeType === DOCUMENT_NODE ||\n parentNodeType === DOCUMENT_FRAGMENT_NODE) {\n res = 'ltr';\n }\n }\n } else {\n res = 'ltr';\n }\n }\n return res ?? null;\n};\n\n/**\n * is content editable\n * NOTE: not implemented in jsdom https://github.com/jsdom/jsdom/issues/1670\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isContentEditable = (node = {}) => {\n let res;\n if (node.nodeType === ELEMENT_NODE) {\n if (typeof node.isContentEditable === 'boolean') {\n res = node.isContentEditable;\n } else if (node.ownerDocument.designMode === 'on') {\n res = true;\n } else if (node.hasAttribute('contenteditable')) {\n const attr = node.getAttribute('contenteditable');\n if (attr === '' || /^(?:plaintext-only|true)$/.test(attr)) {\n res = true;\n } else if (attr === 'inherit') {\n let parent = node.parentNode;\n while (parent) {\n if (isContentEditable(parent)) {\n res = true;\n break;\n }\n parent = parent.parentNode;\n }\n }\n }\n }\n return !!res;\n};\n\n/**\n * get namespace URI\n * @param {string} ns - namespace prefix\n * @param {Array} node - Element node\n * @returns {?string} - namespace URI\n */\nexport const getNamespaceURI = (ns, node) => {\n let res;\n if (ns && typeof ns === 'string' && node?.nodeType === ELEMENT_NODE) {\n const { attributes } = node;\n for (const attr of attributes) {\n const { name, namespaceURI, prefix, value } = attr;\n if (name === `xmlns:${ns}`) {\n res = value;\n break;\n } else if (prefix === ns) {\n res = namespaceURI;\n break;\n }\n }\n }\n return res ?? null;\n};\n\n/**\n * is namespace declared\n * @param {string} ns - namespace\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isNamespaceDeclared = (ns = '', node = {}) => {\n let res;\n if (ns && typeof ns === 'string' && node.nodeType === ELEMENT_NODE) {\n res = node.lookupNamespaceURI(ns);\n if (!res) {\n const root = node.ownerDocument.documentElement;\n let parent = node;\n while (parent) {\n res = getNamespaceURI(ns, parent);\n if (res || parent === root) {\n break;\n }\n parent = parent.parentNode;\n }\n }\n }\n return !!res;\n};\n\n/**\n * is inclusive - nodeA and nodeB are in inclusive relation\n * @param {object} nodeA - Element node\n * @param {object} nodeB - Element node\n * @returns {boolean} - result\n */\nexport const isInclusive = (nodeA = {}, nodeB = {}) => {\n let res;\n if (nodeA.nodeType === ELEMENT_NODE && nodeB.nodeType === ELEMENT_NODE) {\n const posBit = nodeB.compareDocumentPosition(nodeA);\n res = posBit & DOCUMENT_POSITION_CONTAINS ||\n posBit & DOCUMENT_POSITION_CONTAINED_BY;\n }\n return !!res;\n};\n\n/**\n * is preceding - nodeA precedes and/or contains nodeB\n * @param {object} nodeA - Element node\n * @param {object} nodeB - Element node\n * @returns {boolean} - result\n */\nexport const isPreceding = (nodeA = {}, nodeB = {}) => {\n let res;\n if (nodeA.nodeType === ELEMENT_NODE && nodeB.nodeType === ELEMENT_NODE) {\n const posBit = nodeB.compareDocumentPosition(nodeA);\n res = posBit & DOCUMENT_POSITION_PRECEDING ||\n posBit & DOCUMENT_POSITION_CONTAINS;\n }\n return !!res;\n};\n\n/**\n * sort nodes\n * @param {Array.|Set.} nodes - collection of nodes\n * @returns {Array.} - collection of sorted nodes\n */\nexport const sortNodes = (nodes = []) => {\n const arr = [...nodes];\n if (arr.length > 1) {\n arr.sort((a, b) => {\n let res;\n if (isPreceding(b, a)) {\n res = 1;\n } else {\n res = -1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B,EAAgByC,EAAIxB,CAAM,EAC5B,EAAAO,GAAOP,IAAWD,KAGtBC,EAASA,EAAO,UAEpB,CAEF,MAAO,CAAC,CAACO,CACX,EAQapB,EAAc,CAAC2C,EAAQ,CAAC,EAAGC,EAAQ,CAAC,IAAM,CACrD,IAAIxB,EACJ,GAAIuB,EAAM,WAAa,gBAAgBC,EAAM,WAAa,eAAc,CACtE,MAAMC,EAASD,EAAM,wBAAwBD,CAAK,EAClDvB,EAAMyB,EAAS,8BACTA,EAAS,gCACjB,CACA,MAAO,CAAC,CAACzB,CACX,EAQalB,EAAc,CAACyC,EAAQ,CAAC,EAAGC,EAAQ,CAAC,IAAM,CACrD,IAAIxB,EACJ,GAAIuB,EAAM,WAAa,gBAAgBC,EAAM,WAAa,eAAc,CACtE,MAAMC,EAASD,EAAM,wBAAwBD,CAAK,EAClDvB,EAAMyB,EAAS,+BACTA,EAAS,4BACjB,CACA,MAAO,CAAC,CAACzB,CACX,EAOahB,EAAY,CAACiB,EAAQ,CAAC,IAAM,CACvC,MAAMyB,EAAM,CAAC,GAAGzB,CAAK,EACrB,OAAIyB,EAAI,OAAS,GACfA,EAAI,KAAK,CAACC,EAAGC,IAAM,CACjB,IAAI5B,EACJ,OAAIlB,EAAY8C,EAAGD,CAAC,EAClB3B,EAAM,EAENA,EAAM,GAEDA,CACT,CAAC,EAEI0B,CACT", "names": ["dom_util_exports", "__export", "getDirectionality", "getNamespaceURI", "getSlottedTextContent", "isContentEditable", "isInShadowTree", "isInclusive", "isNamespaceDeclared", "isPreceding", "prepareDOMObjects", "sortNodes", "verifyNode", "__toCommonJS", "import_bidi_js", "import_constant", "node", "msg", "document", "root", "parent", "bool", "refNode", "host", "mode", "nodeType", "parentNode", "res", "nodes", "item", "nodeDir", "localName", "getEmbeddingLevels", "bidiFactory", "regDir", "text", "items", "itemDir", "itemLocalName", "itemNodeType", "itemTextContent", "level", "parentNodeType", "attr", "ns", "attributes", "name", "namespaceURI", "prefix", "value", "nodeA", "nodeB", "posBit", "arr", "a", "b"] } diff --git a/dist/cjs/js/finder.js b/dist/cjs/js/finder.js index 64d48c46..2e32978f 100644 --- a/dist/cjs/js/finder.js +++ b/dist/cjs/js/finder.js @@ -1,2 +1,2 @@ -var j=Object.create;var U=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var B=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var q=(T,a)=>{for(var e in a)U(T,e,{get:a[e],enumerable:!0})},I=(T,a,e,c)=>{if(a&&typeof a=="object"||typeof a=="function")for(let i of H(a))!G.call(T,i)&&i!==e&&U(T,i,{get:()=>a[i],enumerable:!(c=F(a,i))||c.enumerable});return T};var V=(T,a,e)=>(e=T!=null?j(B(T)):{},I(a||!T||!T.__esModule?U(e,"default",{value:T,enumerable:!0}):e,T)),X=T=>I(U({},"__esModule",{value:!0}),T);var K={};q(K,{Finder:()=>Y});module.exports=X(K);var z=V(require("is-potential-custom-element-name"),1),x=require("./dom-util.js"),R=require("./matcher.js"),v=require("./parser.js"),f=require("./constant.js");const C="next",O="prev",L="all",$="first",M="lineal",P="self",W=f.SHOW_DOCUMENT|f.SHOW_DOCUMENT_FRAGMENT|f.SHOW_ELEMENT;class Y{#a;#l;#t;#r;#e;#n;#b;#c;#s;#h;#o;#d;#i;#f;constructor(){this.#l=new WeakMap}_onError(a){if(!this.#b)if(a instanceof DOMException||this.#f&&a instanceof this.#f.DOMException)if(a.name===f.NOT_SUPPORTED_ERR)this.#i&&console.warn(a.message);else throw this.#f?new this.#f.DOMException(a.message,a.name):a;else throw a}_setup(a,e,c={}){const{noexcept:i,warn:t}=c;return this.#b=!!i,this.#i=!!t,this.#e=e,[this.#f,this.#t,this.#s]=(0,x.prepareDOMObjects)(e),this.#h=(0,x.isInShadowTree)(e),[this.#a,this.#n]=this._correspond(a),this.#c=new WeakMap,e}_correspond(a){const e=[];let c,i=this.#t&&this.#l.get(this.#t);if(i&&i.has(`${a}`)&&(c=i.get(a)),c){const t=c.length;for(let n=0;n0&&t<=u){if(k.size){let p=0;for(b=this._traverse(h,r),n?b=r.lastChild():b=r.firstChild();b;){if(k.has(b)){if(p===t-1){l.add(b);break}p++}n?b=r.previousSibling():b=r.nextSibling()}}else if(!o){let p=0;for(b=this._traverse(h,r),n?b=r.lastChild():b=r.firstChild();b;){if(p===t-1){l.add(b);break}n?b=r.previousSibling():b=r.nextSibling(),p++}}}}else{let p=t-1;if(i>0)for(;p<0;)p+=i;if(p>=0&&p0?0:t-1;for(b=this._traverse(h,r),n?b=r.lastChild():b=r.firstChild();b&&(b&&p>=0&&p0?N++:N--):g===p&&(o||l.add(b),p+=i),n?b=r.previousSibling():b=r.nextSibling(),g++}}if(n&&l.size>1){const p=[...l];l=new Set(p.reverse())}}else if(e===this.#s&&i+t===1)if(s){let r;for(const u of s)if(r=this._matchLeaves(u,e,c),r)break;r&&l.add(e)}else l.add(e);return l}_collectNthOfType(a,e){const{a:c,b:i,reverse:t}=a,{localName:n,parentNode:o,prefix:h}=e;let l=new Set;if(o){const s=this.#t.createTreeWalker(o,W);let r=0,u=s.firstChild();for(;u;)r++,u=s.nextSibling();if(c===0){if(i>0&&i<=r){let b=0;for(u=this._traverse(o,s),t?u=s.lastChild():u=s.firstChild();u;){const{localName:k,prefix:p}=u;if(k===n&&p===h){if(b===i-1){l.add(u);break}b++}t?u=s.previousSibling():u=s.nextSibling()}}}else{let b=i-1;if(c>0)for(;b<0;)b+=c;if(b>=0&&b0?0:i-1;for(u=this._traverse(o,s),t?u=s.lastChild():u=s.firstChild();u;){const{localName:p,prefix:g}=u;if(p===n&&g===h){if(k===b&&(l.add(u),b+=c),b<0||b>=r)break;c>0?k++:k--}t?u=s.previousSibling():u=s.nextSibling()}}}if(t&&l.size>1){const b=[...l];l=new Set(b.reverse())}}else e===this.#s&&c+i===1&&l.add(e);return l}_matchAnPlusB(a,e,c,i){const{nth:{a:t,b:n,name:o},selector:h}=a,l=(0,v.unescapeSelector)(o),s=new Map;l?(l==="even"?(s.set("a",2),s.set("b",0)):l==="odd"&&(s.set("a",2),s.set("b",1)),c.indexOf("last")>-1&&s.set("reverse",!0)):(typeof t=="string"&&/-?\d+/.test(t)?s.set("a",t*1):s.set("a",0),typeof n=="string"&&/-?\d+/.test(n)?s.set("b",n*1):s.set("b",0),c.indexOf("last")>-1&&s.set("reverse",!0));let r=new Set;if(s.has("a")&&s.has("b")){if(/^nth-(?:last-)?child$/.test(c)){h&&s.set("selector",h);const u=Object.fromEntries(s),b=this._collectNthChild(u,e,i);b.size&&(r=b)}else if(/^nth-(?:last-)?of-type$/.test(c)){const u=Object.fromEntries(s),b=this._collectNthOfType(u,e);b.size&&(r=b)}}return r}_matchDirectionPseudoClass(a,e){const c=(0,v.unescapeSelector)(a.name),i=(0,x.getDirectionality)(e);let t;return c===i&&(t=e),t??null}_matchLanguagePseudoClass(a,e){const c=(0,v.unescapeSelector)(a.name);let i;if(c==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(i=e);else{let t=e.parentNode;for(;t&&t.nodeType===f.ELEMENT_NODE;){if(t.hasAttribute("lang")){t.getAttribute("lang")&&(i=e);break}t=t.parentNode}}else if(c){const t=`(?:-${f.ALPHA_NUM})*`;if(new RegExp(`^(?:\\*-)?${f.ALPHA_NUM}${t}$`,"i").test(c)){let o;if(c.indexOf("-")>-1){const[h,l,...s]=c.split("-");let r;h==="*"?r=`${f.ALPHA_NUM}${t}`:r=`${h}${t}`;const u=`-${l}${t}`,b=s.length;let k="";if(b)for(let p=0;p0){let g=new Set([e]);for(let N=k-1;N>=0;N--){const S=b[N],d=[];c.dir=O;for(const m of g){const w=this._matchCombinator(S,m,c);w.size&&d.push(...w)}if(d.length)N===0?r=!0:g=new Set(d);else{r=!1;break}}}if(r)break}i==="not"?r||(h=e):r&&(h=e)}return h??null}_matchPseudoClassSelector(a,e,c={}){const{children:i}=a,{localName:t,parentNode:n}=e,{forgive:o,warn:h=this.#i}=c,l=(0,v.unescapeSelector)(a.name);let s=new Set;if(f.REG_LOGICAL_PSEUDO.test(l)){let r;if(this.#l.has(a))r=this.#l.get(a);else{const b=(0,v.walkAST)(a),k=[],p=[];for(const[...g]of b){for(const m of g){const w=(0,v.generateCSS)(m);k.push(w)}const N=[],S=new Set;let d=g.shift();for(;d;)if(d.type===f.COMBINATOR?(N.push({combo:d,leaves:[...S]}),S.clear()):d&&S.add(d),g.length)d=g.shift();else{N.push({combo:null,leaves:[...S]}),S.clear();break}p.push(N)}r={astName:l,branches:b,twigBranches:p,selector:k.join(",")},this.#l.set(a,r)}const u=this._matchLogicalPseudoFunc(r,e,c);u&&s.add(u)}else if(Array.isArray(i)){const[r]=i;if(/^nth-(?:last-)?(?:child|of-type)$/.test(l)){const u=this._matchAnPlusB(r,e,l,c);u.size&&(s=u)}else if(l==="dir"){const u=this._matchDirectionPseudoClass(r,e);u&&s.add(u)}else if(l==="lang"){const u=this._matchLanguagePseudoClass(r,e);u&&s.add(u)}else switch(l){case"current":case"nth-col":case"nth-last-col":{if(h){const u=`Unsupported pseudo-class :${l}()`;throw new DOMException(u,f.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;default:if(!o){const u=`Unknown pseudo-class :${l}()`;throw new DOMException(u,f.SYNTAX_ERR)}}}else{const r=/^a(?:rea)?$/,u=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,b=/^(?:(?:inpu|selec)t|button|form|textarea)$/,k=/^d(?:etails|ialog)$/,p=/^(?:checkbox|radio)$/,g=/^(?:date(?:time-local)?|month|time|week)$/,N=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,S=/^(?:(?:emai|te|ur)l|number|password|search|text)$/;switch(l){case"any-link":case"link":{r.test(t)&&e.hasAttribute("href")&&s.add(e);break}case"local-link":{if(r.test(t)&&e.hasAttribute("href")){const{href:d,origin:m,pathname:w}=new URL(this.#t.URL),_=new URL(e.getAttribute("href"),d);_.origin===m&&_.pathname===w&&s.add(e)}break}case"visited":break;case"target":{const{hash:d}=new URL(this.#t.URL);e.id&&d===`#${e.id}`&&this.#t.contains(e)&&s.add(e);break}case"target-within":{const{hash:d}=new URL(this.#t.URL);if(d){const m=d.replace(/^#/,"");let w=this.#t.getElementById(m);for(;w;){if(w===e){s.add(e);break}w=w.parentNode}}break}case"scope":{this.#e.nodeType===f.ELEMENT_NODE?e===this.#e&&s.add(e):e===this.#t.documentElement&&s.add(e);break}case"focus":{if(e===this.#t.activeElement){let d=!0,m=e;for(;m;){if(m.hasAttribute("hidden")){d=!1;break}else if(m.hasAttribute("style")){const{display:w,visibility:_}=m.style;if(d=!(w==="none"||_==="hidden"),!d)break}if(m.parentNode&&m.parentNode.nodeType===f.ELEMENT_NODE)m=m.parentNode;else break}d&&s.add(e)}break}case"focus-within":{let d,m=this.#t.activeElement;for(;m;){if(m===e){d=!0;break}m=m.parentNode}if(d){let w=!0,_=e;for(;_;){if(_.hasAttribute("hidden")){w=!1;break}else if(_.hasAttribute("style")){const{display:y,visibility:E}=_.style;if(w=!(y==="none"||E==="hidden"),!w)break}if(_.parentNode&&_.parentNode.nodeType===f.ELEMENT_NODE)_=_.parentNode;else break}w&&s.add(e)}break}case"open":{k.test(t)&&e.hasAttribute("open")&&s.add(e);break}case"closed":{k.test(t)&&!e.hasAttribute("open")&&s.add(e);break}case"disabled":{if(u.test(t)||(0,z.default)(t))if(e.disabled||e.hasAttribute("disabled"))s.add(e);else{let d=n;for(;d&&d.localName!=="fieldset";)d=d.parentNode;d&&n.localName!=="legend"&&d.hasAttribute("disabled")&&s.add(e)}break}case"enabled":{(u.test(t)||(0,z.default)(t))&&!(e.disabled&&e.hasAttribute("disabled"))&&s.add(e);break}case"read-only":{switch(t){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&s.add(e);break}case"input":{(!e.type||g.test(e.type)||S.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&s.add(e);break}default:(0,x.isContentEditable)(e)||s.add(e)}break}case"read-write":{switch(t){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||s.add(e);break}case"input":{(!e.type||g.test(e.type)||S.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&s.add(e);break}default:(0,x.isContentEditable)(e)&&s.add(e)}break}case"placeholder-shown":{let d;t==="textarea"?d=e:t==="input"&&(e.hasAttribute("type")?S.test(e.getAttribute("type"))&&(d=e):d=e),d&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&s.add(e);break}case"checked":{(e.checked&&t==="input"&&e.hasAttribute("type")&&p.test(e.getAttribute("type"))||e.selected&&t==="option")&&s.add(e);break}case"indeterminate":{if(e.indeterminate&&t==="input"&&e.type==="checkbox"||t==="progress"&&!e.hasAttribute("value"))s.add(e);else if(t==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const d=e.name;let m=e.parentNode;for(;m&&m.localName!=="form";)m=m.parentNode;m||(m=this.#t.documentElement);let w;const _=m.getElementsByTagName("input"),y=_.length;if(y)for(let E=0;E0;let l=new Set,s=!1;if(this.#h)s=!0;else switch(n){case f.SELECTOR_PSEUDO_ELEMENT:{(0,R.matchPseudoElementSelector)(o,c);break}case f.SELECTOR_ID:{if(this.#s.nodeType===f.ELEMENT_NODE)s=!0;else{const r=this.#s.getElementById(o);r&&r!==e&&e.contains(r)&&(h?this._matchLeaves(t,r,c)&&l.add(r):l.add(r))}break}case f.SELECTOR_CLASS:{const r=e.getElementsByClassName(o);l=this._matchHTMLCollection(r,{compound:h,filterLeaves:t});break}case f.SELECTOR_TYPE:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(o)){const r=e.getElementsByTagName(o);l=this._matchHTMLCollection(r,{compound:h,filterLeaves:t})}else s=!0;break}default:s=!0}return{nodes:l,pending:s}}_matchCombinator(a,e,c={}){const{combo:i,leaves:t}=a,{name:n}=i,{dir:o}=c;let h=new Set;if(o===C)switch(n){case"+":{const l=e.nextElementSibling;l&&this._matchLeaves(t,l,c)&&h.add(l);break}case"~":{const{parentNode:l}=e;if(l){const s=this.#t.createTreeWalker(l,f.SHOW_ELEMENT);let r=this._traverse(e,s);for(r===e&&(r=s.nextSibling());r;)this._matchLeaves(t,r,c)&&h.add(r),r=s.nextSibling()}break}case">":{const l=this.#t.createTreeWalker(e,f.SHOW_ELEMENT);let s=l.firstChild();for(;s;)this._matchLeaves(t,s,c)&&h.add(s),s=l.nextSibling();break}case" ":default:{const{nodes:l,pending:s}=this._findDescendantNodes(t,e);if(l.size)h=l;else if(s){const r=this.#t.createTreeWalker(e,f.SHOW_ELEMENT);let u=r.nextNode();for(;u;)this._matchLeaves(t,u,c)&&h.add(u),u=r.nextNode()}}}else switch(n){case"+":{const l=e.previousElementSibling;l&&this._matchLeaves(t,l,c)&&h.add(l);break}case"~":{const l=this.#t.createTreeWalker(e.parentNode,f.SHOW_ELEMENT);let s=l.firstChild();for(;s&&s!==e;)this._matchLeaves(t,s,c)&&h.add(s),s=l.nextSibling();break}case">":{const l=e.parentNode;l&&this._matchLeaves(t,l,c)&&h.add(l);break}case" ":default:{const l=[];let s=e.parentNode;for(;s;)this._matchLeaves(t,s,c)&&l.push(s),s=s.parentNode;l.length&&(h=new Set(l.reverse()))}}return h}_findNode(a,e={}){const{node:c}=e;let i,t=this._traverse(c,this.#r);if(t)for(t.nodeType!==f.ELEMENT_NODE?t=this.#r.nextNode():t===c&&t!==this.#s&&(t=this.#r.nextNode());t;){let n;if(this.#e.nodeType===f.ELEMENT_NODE?t===this.#e?n=!0:n=this.#e.contains(t):n=!0,n&&this._matchLeaves(a,t,{warn:this.#i})){i=t;break}t=this.#r.nextNode()}return i??null}_matchSelf(a){const e=[];let c=!1;return this._matchLeaves(a,this.#e)&&(e.push(this.#e),c=!0),[e,c]}_findLineal(a,e={}){const{complex:c,compound:i,filterLeaves:t}=e,n=[];let o=!1,h=this._matchLeaves([a],this.#e);if(h&&!c&&(i?(h=this._matchLeaves(t,this.#e),h&&(n.push(this.#e),o=!0)):(n.push(this.#e),o=!0)),!h||c){h&&(n.push(this.#e),i||(o=!0));let l=this.#e.parentNode;for(;l&&(h=this._matchLeaves([a],l),h&&(n.push(l),i||(o=!0)),l.parentNode);)l=l.parentNode}return[n,o]}_findFirst(a){const e=[];let c=!1;const i=this._findNode(a,{node:this.#e});return i&&(e.push(i),c=!0),[e,c]}_findFromHTMLCollection(a,e={}){const{compound:c,filterLeaves:i}=e;let t=[],n=!1;const o=a.length;if(o)if(this.#e.nodeType===f.ELEMENT_NODE)for(let h=0;h0;let s=[],r=!1,u=!1;switch(o){case f.SELECTOR_PSEUDO_ELEMENT:{(0,R.matchPseudoElementSelector)(h,{warn:this.#i});break}case f.SELECTOR_ID:{if(e===P)[s,r]=this._matchSelf(i);else if(e===M)[s,r]=this._findLineal(t,{complex:c,compound:l,filterLeaves:n});else if(e===$&&this.#s.nodeType!==f.ELEMENT_NODE){const b=this.#s.getElementById(h);b&&(l?this._matchLeaves(n,b,{warn:this.#i})&&(s.push(b),r=!0):(s.push(b),r=!0))}else u=!0;break}case f.SELECTOR_CLASS:{if(e===P)[s,r]=this._matchSelf(i);else if(e===M)[s,r]=this._findLineal(t,{complex:c,compound:l,filterLeaves:n});else if(e===$)[s,r]=this._findFirst(i);else if(this.#s.nodeType===f.DOCUMENT_NODE){const b=this.#s.getElementsByClassName(h);[s,r]=this._findFromHTMLCollection(b,{compound:l,filterLeaves:n})}else u=!0;break}case f.SELECTOR_TYPE:{if(e===P)[s,r]=this._matchSelf(i);else if(e===M)[s,r]=this._findLineal(t,{complex:c,compound:l,filterLeaves:n});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===f.DOCUMENT_NODE&&!/[*|]/.test(h)){const b=this.#s.getElementsByTagName(h);[s,r]=this._findFromHTMLCollection(b,{compound:l,filterLeaves:n})}else u=!0;break}default:if(e!==M&&f.REG_SHADOW_HOST.test(h)){if(this.#h&&this.#e.nodeType===f.DOCUMENT_FRAGMENT_NODE){const b=this._matchShadowHostPseudoClass(t,this.#e);b&&(s.push(b),r=!0)}}else e===P?[s,r]=this._matchSelf(i):e===M?[s,r]=this._findLineal(t,{complex:c,compound:l,filterLeaves:n}):e===$?[s,r]=this._findFirst(i):u=!0}return{compound:l,filtered:r,nodes:s,pending:u}}_getEntryTwig(a,e){const c=a.length,i=c>1,t=a[0];let n,o;if(i){const{combo:h,leaves:[{name:l,type:s}]}=t,r=a[c-1],{leaves:[{name:u,type:b}]}=r;if(b===f.SELECTOR_PSEUDO_ELEMENT||b===f.SELECTOR_ID)n=O,o=r;else if(s===f.SELECTOR_PSEUDO_ELEMENT||s===f.SELECTOR_ID)n=C,o=t;else if(e===L)if(l==="*"&&s===f.SELECTOR_TYPE)n=O,o=r;else if(u==="*"&&b===f.SELECTOR_TYPE)n=C,o=t;else if(c===2){const{name:k}=h;/^[+~]$/.test(k)?(n=O,o=r):(n=C,o=t)}else n=C,o=t;else if(u==="*"&&b===f.SELECTOR_TYPE)n=C,o=t;else if(l==="*"&&s===f.SELECTOR_TYPE)n=O,o=r;else{let k,p;for(const{combo:g,leaves:[N]}of a){const{type:S}=N,d=(0,v.unescapeSelector)(N.name);if(S===f.SELECTOR_PSEUDO_CLASS&&d==="dir"){k=!1;break}if(g&&!p){const{name:m}=g;/^[+~]$/.test(m)&&(k=!0,p=!0)}}k?(n=C,o=t):(n=O,o=r)}}else n=O,o=t;return{complex:i,dir:n,twig:o}}_collectNodes(a){const e=this.#a.values();if(a===L||a===$){const c=new Set;let i=0;for(const{branch:t}of e){const{complex:n,dir:o,twig:h}=this._getEntryTwig(t,a),{compound:l,filtered:s,nodes:r,pending:u}=this._findEntryNodes(h,a,n);r.length?(this.#a[i].find=!0,this.#n[i]=r):u&&c.add(new Map([["index",i],["twig",h]])),this.#a[i].dir=o,this.#a[i].filtered=s||!l,i++}if(c.size){let t,n;this.#e!==this.#s&&this.#e.nodeType===f.ELEMENT_NODE?(t=this.#e,n=this.#r):(t=this.#s,n=this.#d);let o=this._traverse(t,n);for(;o;){let h=!1;if(this.#e.nodeType===f.ELEMENT_NODE?o===this.#e?h=!0:h=this.#e.contains(o):h=!0,h)for(const l of c){const{leaves:s}=l.get("twig");if(this._matchLeaves(s,o,{warn:this.#i})){const u=l.get("index");this.#a[u].filtered=!0,this.#a[u].find=!0,this.#n[u].push(o)}}o=n.nextNode()}}}else{let c=0;for(const{branch:i}of e){const t=i[i.length-1],n=i.length>1,{compound:o,filtered:h,nodes:l}=this._findEntryNodes(t,a,n);l.length&&(this.#a[c].find=!0,this.#n[c]=l),this.#a[c].dir=O,this.#a[c].filtered=h||!o,c++}}return[this.#a,this.#n]}_matchNodes(a){const[...e]=this.#a,c=e.length;let i=new Set;for(let t=0;t=0;d--){const m=n[d],w=[];for(const _ of S){const y=this._matchCombinator(m,_,{dir:o,warn:this.#i});y.size&&w.push(...y)}if(w.length)d===0?(i.add(N),p=!0,a===L&&s>1&&i.size>1&&(this.#o=!0)):(S=new Set(w),p=!1);else{p=!1;break}}if(p&&a!==L)break}if(!p&&a===$){const[g]=[...r];let N=this._findNode(k,{node:g});for(;N;){let S=new Set([N]);for(let d=b-1;d>=0;d--){const m=n[d],w=[];for(const _ of S){const y=this._matchCombinator(m,_,{dir:o,warn:this.#i});y.size&&w.push(...y)}if(w.length)d===0?(i.add(N),p=!0):(S=new Set(w),p=!1);else{p=!1;break}}if(p)break;N=this._findNode(k,{node:N}),S=new Set([N])}}}}}return i}_find(a){return this._collectNodes(a),this._matchNodes(a)}matches(a,e,c){let i;try{if(this.#e=this._setup(a,e,c),e.nodeType!==f.ELEMENT_NODE){const n=`Unexpected node ${e.nodeName}`;throw new TypeError(n)}i=this._find(P).size}catch(t){this._onError(t)}return!!i}closest(a,e,c){let i;try{if(this.#e=this._setup(a,e,c),e.nodeType!==f.ELEMENT_NODE){const n=`Unexpected node ${e.nodeName}`;throw new TypeError(n)}const t=this._find(M);if(t.size){let n=this.#e;for(;n;){if(t.has(n)){i=n;break}n=n.parentNode}}}catch(t){this._onError(t)}return i??null}querySelector(a,e,c){let i;try{this.#e=this._setup(a,e,c),this._prepareTreeWalkers(e);const t=this._find($);t.delete(this.#e),t.size&&([i]=(0,x.sortNodes)(t))}catch(t){this._onError(t)}return i??null}querySelectorAll(a,e,c){let i;try{this.#e=this._setup(a,e,c),this._prepareTreeWalkers(e);const t=this._find(L);t.delete(this.#e),t.size&&(this.#o?i=(0,x.sortNodes)(t):i=[...t])}catch(t){this._onError(t)}return i??[]}}0&&(module.exports={Finder}); +var j=Object.create;var U=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var B=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var q=(T,a)=>{for(var e in a)U(T,e,{get:a[e],enumerable:!0})},I=(T,a,e,c)=>{if(a&&typeof a=="object"||typeof a=="function")for(let i of H(a))!G.call(T,i)&&i!==e&&U(T,i,{get:()=>a[i],enumerable:!(c=F(a,i))||c.enumerable});return T};var V=(T,a,e)=>(e=T!=null?j(B(T)):{},I(a||!T||!T.__esModule?U(e,"default",{value:T,enumerable:!0}):e,T)),X=T=>I(U({},"__esModule",{value:!0}),T);var K={};q(K,{Finder:()=>Y});module.exports=X(K);var z=V(require("is-potential-custom-element-name"),1),x=require("./dom-util.js"),R=require("./matcher.js"),v=require("./parser.js"),f=require("./constant.js");const C="next",O="prev",L="all",$="first",M="lineal",P="self",W=f.SHOW_DOCUMENT|f.SHOW_DOCUMENT_FRAGMENT|f.SHOW_ELEMENT;class Y{#a;#l;#t;#r;#e;#n;#b;#c;#s;#h;#o;#d;#i;#f;constructor(){this.#l=new WeakMap}_onError(a){if(!this.#b)if(a instanceof DOMException||this.#f&&a instanceof this.#f.DOMException)if(a.name===f.NOT_SUPPORTED_ERR)this.#i&&console.warn(a.message);else throw this.#f?new this.#f.DOMException(a.message,a.name):a;else throw a}_setup(a,e,c={}){const{noexcept:i,warn:t}=c;return this.#b=!!i,this.#i=!!t,this.#e=e,[this.#f,this.#t,this.#s]=(0,x.prepareDOMObjects)(e),this.#h=(0,x.isInShadowTree)(e),[this.#a,this.#n]=this._correspond(a),this.#c=new WeakMap,e}_correspond(a){const e=[];let c,i=this.#t&&this.#l.get(this.#t);if(i&&i.has(`${a}`)&&(c=i.get(a)),c){const t=c.length;for(let n=0;n0&&t<=u){if(k.size){let p=0;for(b=this._traverse(h,r),n?b=r.lastChild():b=r.firstChild();b;){if(k.has(b)){if(p===t-1){l.add(b);break}p++}n?b=r.previousSibling():b=r.nextSibling()}}else if(!o){let p=0;for(b=this._traverse(h,r),n?b=r.lastChild():b=r.firstChild();b;){if(p===t-1){l.add(b);break}n?b=r.previousSibling():b=r.nextSibling(),p++}}}}else{let p=t-1;if(i>0)for(;p<0;)p+=i;if(p>=0&&p0?0:t-1;for(b=this._traverse(h,r),n?b=r.lastChild():b=r.firstChild();b&&(b&&p>=0&&p0?N++:N--):g===p&&(o||l.add(b),p+=i),n?b=r.previousSibling():b=r.nextSibling(),g++}}if(n&&l.size>1){const p=[...l];l=new Set(p.reverse())}}else if(e===this.#s&&i+t===1)if(s){let r;for(const u of s)if(r=this._matchLeaves(u,e,c),r)break;r&&l.add(e)}else l.add(e);return l}_collectNthOfType(a,e){const{a:c,b:i,reverse:t}=a,{localName:n,parentNode:o,prefix:h}=e;let l=new Set;if(o){const s=this.#t.createTreeWalker(o,W);let r=0,u=s.firstChild();for(;u;)r++,u=s.nextSibling();if(c===0){if(i>0&&i<=r){let b=0;for(u=this._traverse(o,s),t?u=s.lastChild():u=s.firstChild();u;){const{localName:k,prefix:p}=u;if(k===n&&p===h){if(b===i-1){l.add(u);break}b++}t?u=s.previousSibling():u=s.nextSibling()}}}else{let b=i-1;if(c>0)for(;b<0;)b+=c;if(b>=0&&b0?0:i-1;for(u=this._traverse(o,s),t?u=s.lastChild():u=s.firstChild();u;){const{localName:p,prefix:g}=u;if(p===n&&g===h){if(k===b&&(l.add(u),b+=c),b<0||b>=r)break;c>0?k++:k--}t?u=s.previousSibling():u=s.nextSibling()}}}if(t&&l.size>1){const b=[...l];l=new Set(b.reverse())}}else e===this.#s&&c+i===1&&l.add(e);return l}_matchAnPlusB(a,e,c,i){const{nth:{a:t,b:n,name:o},selector:h}=a,l=(0,v.unescapeSelector)(o),s=new Map;l?(l==="even"?(s.set("a",2),s.set("b",0)):l==="odd"&&(s.set("a",2),s.set("b",1)),c.indexOf("last")>-1&&s.set("reverse",!0)):(typeof t=="string"&&/-?\d+/.test(t)?s.set("a",t*1):s.set("a",0),typeof n=="string"&&/-?\d+/.test(n)?s.set("b",n*1):s.set("b",0),c.indexOf("last")>-1&&s.set("reverse",!0));let r=new Set;if(s.has("a")&&s.has("b")){if(/^nth-(?:last-)?child$/.test(c)){h&&s.set("selector",h);const u=Object.fromEntries(s),b=this._collectNthChild(u,e,i);b.size&&(r=b)}else if(/^nth-(?:last-)?of-type$/.test(c)){const u=Object.fromEntries(s),b=this._collectNthOfType(u,e);b.size&&(r=b)}}return r}_matchDirectionPseudoClass(a,e){const c=(0,v.unescapeSelector)(a.name),i=(0,x.getDirectionality)(e);let t;return c===i&&(t=e),t??null}_matchLanguagePseudoClass(a,e){const c=(0,v.unescapeSelector)(a.name);let i;if(c==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(i=e);else{let t=e.parentNode;for(;t&&t.nodeType===f.ELEMENT_NODE;){if(t.hasAttribute("lang")){t.getAttribute("lang")&&(i=e);break}t=t.parentNode}}else if(c){const t=`(?:-${f.ALPHA_NUM})*`;if(new RegExp(`^(?:\\*-)?${f.ALPHA_NUM}${t}$`,"i").test(c)){let o;if(c.indexOf("-")>-1){const[h,l,...s]=c.split("-");let r;h==="*"?r=`${f.ALPHA_NUM}${t}`:r=`${h}${t}`;const u=`-${l}${t}`,b=s.length;let k="";if(b)for(let p=0;p0){let g=new Set([e]);for(let N=k-1;N>=0;N--){const S=b[N],d=[];c.dir=O;for(const m of g){const w=this._matchCombinator(S,m,c);w.size&&d.push(...w)}if(d.length)N===0?r=!0:g=new Set(d);else{r=!1;break}}}if(r)break}i==="not"?r||(h=e):r&&(h=e)}return h??null}_matchPseudoClassSelector(a,e,c={}){const{children:i}=a,{localName:t,parentNode:n}=e,{forgive:o,warn:h=this.#i}=c,l=(0,v.unescapeSelector)(a.name);let s=new Set;if(f.REG_LOGICAL_PSEUDO.test(l)){let r;if(this.#l.has(a))r=this.#l.get(a);else{const b=(0,v.walkAST)(a),k=[],p=[];for(const[...g]of b){for(const m of g){const w=(0,v.generateCSS)(m);k.push(w)}const N=[],S=new Set;let d=g.shift();for(;d;)if(d.type===f.COMBINATOR?(N.push({combo:d,leaves:[...S]}),S.clear()):d&&S.add(d),g.length)d=g.shift();else{N.push({combo:null,leaves:[...S]}),S.clear();break}p.push(N)}r={astName:l,branches:b,twigBranches:p,selector:k.join(",")},this.#l.set(a,r)}const u=this._matchLogicalPseudoFunc(r,e,c);u&&s.add(u)}else if(Array.isArray(i)){const[r]=i;if(/^nth-(?:last-)?(?:child|of-type)$/.test(l)){const u=this._matchAnPlusB(r,e,l,c);u.size&&(s=u)}else if(l==="dir"){const u=this._matchDirectionPseudoClass(r,e);u&&s.add(u)}else if(l==="lang"){const u=this._matchLanguagePseudoClass(r,e);u&&s.add(u)}else switch(l){case"current":case"nth-col":case"nth-last-col":{if(h){const u=`Unsupported pseudo-class :${l}()`;throw new DOMException(u,f.NOT_SUPPORTED_ERR)}break}case"host":case"host-context":break;default:if(!o){const u=`Unknown pseudo-class :${l}()`;throw new DOMException(u,f.SYNTAX_ERR)}}}else{const r=/^a(?:rea)?$/,u=/^(?:(?:fieldse|inpu|selec)t|button|opt(?:group|ion)|textarea)$/,b=/^(?:(?:inpu|selec)t|button|form|textarea)$/,k=/^d(?:etails|ialog)$/,p=/^(?:checkbox|radio)$/,g=/^(?:date(?:time-local)?|month|time|week)$/,N=/(?:(?:rang|tim)e|date(?:time-local)?|month|number|week)$/,S=/^(?:(?:emai|te|ur)l|number|password|search|text)$/;switch(l){case"any-link":case"link":{r.test(t)&&e.hasAttribute("href")&&s.add(e);break}case"local-link":{if(r.test(t)&&e.hasAttribute("href")){const{href:d,origin:m,pathname:w}=new URL(this.#t.URL),_=new URL(e.getAttribute("href"),d);_.origin===m&&_.pathname===w&&s.add(e)}break}case"visited":break;case"target":{const{hash:d}=new URL(this.#t.URL);e.id&&d===`#${e.id}`&&this.#t.contains(e)&&s.add(e);break}case"target-within":{const{hash:d}=new URL(this.#t.URL);if(d){const m=d.replace(/^#/,"");let w=this.#t.getElementById(m);for(;w;){if(w===e){s.add(e);break}w=w.parentNode}}break}case"scope":{this.#e.nodeType===f.ELEMENT_NODE?e===this.#e&&s.add(e):e===this.#t.documentElement&&s.add(e);break}case"focus":{if(e===this.#t.activeElement){let d=!0,m=e;for(;m;){if(m.hasAttribute("hidden")){d=!1;break}else if(m.hasAttribute("style")){const{display:w,visibility:_}=m.style;if(d=!(w==="none"||_==="hidden"),!d)break}if(m.parentNode&&m.parentNode.nodeType===f.ELEMENT_NODE)m=m.parentNode;else break}d&&s.add(e)}break}case"focus-within":{let d,m=this.#t.activeElement;for(;m;){if(m===e){d=!0;break}m=m.parentNode}if(d){let w=!0,_=e;for(;_;){if(_.hasAttribute("hidden")){w=!1;break}else if(_.hasAttribute("style")){const{display:y,visibility:E}=_.style;if(w=!(y==="none"||E==="hidden"),!w)break}if(_.parentNode&&_.parentNode.nodeType===f.ELEMENT_NODE)_=_.parentNode;else break}w&&s.add(e)}break}case"open":{k.test(t)&&e.hasAttribute("open")&&s.add(e);break}case"closed":{k.test(t)&&!e.hasAttribute("open")&&s.add(e);break}case"disabled":{if(u.test(t)||(0,z.default)(t))if(e.disabled||e.hasAttribute("disabled"))s.add(e);else{let d=n;for(;d&&d.localName!=="fieldset";)d=d.parentNode;d&&n.localName!=="legend"&&d.hasAttribute("disabled")&&s.add(e)}break}case"enabled":{(u.test(t)||(0,z.default)(t))&&!(e.disabled&&e.hasAttribute("disabled"))&&s.add(e);break}case"read-only":{switch(t){case"textarea":{(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&s.add(e);break}case"input":{(!e.type||g.test(e.type)||S.test(e.type))&&(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&s.add(e);break}default:(0,x.isContentEditable)(e)||s.add(e)}break}case"read-write":{switch(t){case"textarea":{e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled")||s.add(e);break}case"input":{(!e.type||g.test(e.type)||S.test(e.type))&&!(e.readonly||e.hasAttribute("readonly")||e.disabled||e.hasAttribute("disabled"))&&s.add(e);break}default:(0,x.isContentEditable)(e)&&s.add(e)}break}case"placeholder-shown":{let d;t==="textarea"?d=e:t==="input"&&(e.hasAttribute("type")?S.test(e.getAttribute("type"))&&(d=e):d=e),d&&e.value===""&&e.hasAttribute("placeholder")&&e.getAttribute("placeholder").trim().length&&s.add(e);break}case"checked":{(e.checked&&t==="input"&&e.hasAttribute("type")&&p.test(e.getAttribute("type"))||e.selected&&t==="option")&&s.add(e);break}case"indeterminate":{if(e.indeterminate&&t==="input"&&e.type==="checkbox"||t==="progress"&&!e.hasAttribute("value"))s.add(e);else if(t==="input"&&e.type==="radio"&&!e.hasAttribute("checked")){const d=e.name;let m=e.parentNode;for(;m&&m.localName!=="form";)m=m.parentNode;m||(m=this.#t.documentElement);let w;const _=m.getElementsByTagName("input"),y=_.length;if(y)for(let E=0;E0;let l=new Set,s=!1;if(this.#h)s=!0;else switch(n){case f.SELECTOR_PSEUDO_ELEMENT:{(0,R.matchPseudoElementSelector)(o,c);break}case f.SELECTOR_ID:{if(this.#s.nodeType===f.ELEMENT_NODE)s=!0;else{const r=this.#s.getElementById(o);r&&r!==e&&e.contains(r)&&(h?this._matchLeaves(t,r,c)&&l.add(r):l.add(r))}break}case f.SELECTOR_CLASS:{const r=e.getElementsByClassName(o);l=this._matchHTMLCollection(r,{compound:h,filterLeaves:t});break}case f.SELECTOR_TYPE:{if(this.#t.contentType==="text/html"&&!/[*|]/.test(o)){const r=e.getElementsByTagName(o);l=this._matchHTMLCollection(r,{compound:h,filterLeaves:t})}else s=!0;break}default:s=!0}return{nodes:l,pending:s}}_matchCombinator(a,e,c={}){const{combo:i,leaves:t}=a,{name:n}=i,{dir:o}=c;let h=new Set;if(o===C)switch(n){case"+":{const l=e.nextElementSibling;l&&this._matchLeaves(t,l,c)&&h.add(l);break}case"~":{const{parentNode:l}=e;if(l){const s=this.#t.createTreeWalker(l,f.SHOW_ELEMENT);let r=this._traverse(e,s);for(r===e&&(r=s.nextSibling());r;)this._matchLeaves(t,r,c)&&h.add(r),r=s.nextSibling()}break}case">":{const l=this.#t.createTreeWalker(e,f.SHOW_ELEMENT);let s=l.firstChild();for(;s;)this._matchLeaves(t,s,c)&&h.add(s),s=l.nextSibling();break}case" ":default:{const{nodes:l,pending:s}=this._findDescendantNodes(t,e);if(l.size)h=l;else if(s){const r=this.#t.createTreeWalker(e,f.SHOW_ELEMENT);let u=r.nextNode();for(;u;)this._matchLeaves(t,u,c)&&h.add(u),u=r.nextNode()}}}else switch(n){case"+":{const l=e.previousElementSibling;l&&this._matchLeaves(t,l,c)&&h.add(l);break}case"~":{const l=this.#t.createTreeWalker(e.parentNode,f.SHOW_ELEMENT);let s=l.firstChild();for(;s&&s!==e;)this._matchLeaves(t,s,c)&&h.add(s),s=l.nextSibling();break}case">":{const l=e.parentNode;l&&this._matchLeaves(t,l,c)&&h.add(l);break}case" ":default:{const l=[];let s=e.parentNode;for(;s;)this._matchLeaves(t,s,c)&&l.push(s),s=s.parentNode;l.length&&(h=new Set(l.reverse()))}}return h}_findNode(a,e={}){const{node:c}=e;let i,t=this._traverse(c,this.#r);if(t)for(t.nodeType!==f.ELEMENT_NODE?t=this.#r.nextNode():t===c&&t!==this.#s&&(t=this.#r.nextNode());t;){let n;if(this.#e.nodeType===f.ELEMENT_NODE?t===this.#e?n=!0:n=this.#e.contains(t):n=!0,n&&this._matchLeaves(a,t,{warn:this.#i})){i=t;break}t=this.#r.nextNode()}return i??null}_matchSelf(a){const e=[];let c=!1;return this._matchLeaves(a,this.#e)&&(e.push(this.#e),c=!0),[e,c]}_findLineal(a,e={}){const{complex:c,compound:i,filterLeaves:t}=e,n=[];let o=!1,h=this._matchLeaves([a],this.#e);if(h&&!c&&(i?(h=this._matchLeaves(t,this.#e),h&&(n.push(this.#e),o=!0)):(n.push(this.#e),o=!0)),!h||c){h&&(n.push(this.#e),i||(o=!0));let l=this.#e.parentNode;for(;l&&(h=this._matchLeaves([a],l),h&&(n.push(l),i||(o=!0)),l.parentNode);)l=l.parentNode}return[n,o]}_findFirst(a){const e=[];let c=!1;const i=this._findNode(a,{node:this.#e});return i&&(e.push(i),c=!0),[e,c]}_findFromHTMLCollection(a,e={}){const{compound:c,filterLeaves:i}=e;let t=[],n=!1;const o=a.length;if(o)if(this.#e.nodeType===f.ELEMENT_NODE)for(let h=0;h0;let s=[],r=!1,u=!1;switch(o){case f.SELECTOR_PSEUDO_ELEMENT:{(0,R.matchPseudoElementSelector)(h,{warn:this.#i});break}case f.SELECTOR_ID:{if(e===P)[s,r]=this._matchSelf(i);else if(e===M)[s,r]=this._findLineal(t,{complex:c,compound:l,filterLeaves:n});else if(e===$&&this.#s.nodeType!==f.ELEMENT_NODE){const b=this.#s.getElementById(h);b&&(l?this._matchLeaves(n,b,{warn:this.#i})&&(s.push(b),r=!0):(s.push(b),r=!0))}else u=!0;break}case f.SELECTOR_CLASS:{if(e===P)[s,r]=this._matchSelf(i);else if(e===M)[s,r]=this._findLineal(t,{complex:c,compound:l,filterLeaves:n});else if(e===$)[s,r]=this._findFirst(i);else if(this.#s.nodeType===f.DOCUMENT_NODE){const b=this.#s.getElementsByClassName(h);[s,r]=this._findFromHTMLCollection(b,{compound:l,filterLeaves:n})}else u=!0;break}case f.SELECTOR_TYPE:{if(e===P)[s,r]=this._matchSelf(i);else if(e===M)[s,r]=this._findLineal(t,{complex:c,compound:l,filterLeaves:n});else if(this.#t.contentType==="text/html"&&this.#s.nodeType===f.DOCUMENT_NODE&&!/[*|]/.test(h)){const b=this.#s.getElementsByTagName(h);[s,r]=this._findFromHTMLCollection(b,{compound:l,filterLeaves:n})}else u=!0;break}default:if(e!==M&&f.REG_SHADOW_HOST.test(h)){if(this.#h&&this.#e.nodeType===f.DOCUMENT_FRAGMENT_NODE){const b=this._matchShadowHostPseudoClass(t,this.#e);b&&(s.push(b),r=!0)}}else e===P?[s,r]=this._matchSelf(i):e===M?[s,r]=this._findLineal(t,{complex:c,compound:l,filterLeaves:n}):e===$?[s,r]=this._findFirst(i):u=!0}return{compound:l,filtered:r,nodes:s,pending:u}}_getEntryTwig(a,e){const c=a.length,i=c>1,t=a[0];let n,o;if(i){const{combo:h,leaves:[{name:l,type:s}]}=t,r=a[c-1],{leaves:[{name:u,type:b}]}=r;if(b===f.SELECTOR_PSEUDO_ELEMENT||b===f.SELECTOR_ID)n=O,o=r;else if(s===f.SELECTOR_PSEUDO_ELEMENT||s===f.SELECTOR_ID)n=C,o=t;else if(e===L)if(l==="*"&&s===f.SELECTOR_TYPE)n=O,o=r;else if(u==="*"&&b===f.SELECTOR_TYPE)n=C,o=t;else if(c===2){const{name:k}=h;/^[+~]$/.test(k)?(n=O,o=r):(n=C,o=t)}else n=C,o=t;else if(u==="*"&&b===f.SELECTOR_TYPE)n=C,o=t;else if(l==="*"&&s===f.SELECTOR_TYPE)n=O,o=r;else{let k,p;for(const{combo:g,leaves:[N]}of a){const{type:S}=N,d=(0,v.unescapeSelector)(N.name);if(S===f.SELECTOR_PSEUDO_CLASS&&d==="dir"){k=!1;break}if(g&&!p){const{name:m}=g;/^[+~]$/.test(m)&&(k=!0,p=!0)}}k?(n=C,o=t):(n=O,o=r)}}else n=O,o=t;return{complex:i,dir:n,twig:o}}_collectNodes(a){const e=this.#a.values();if(a===L||a===$){const c=new Set;let i=0;for(const{branch:t}of e){const{complex:n,dir:o,twig:h}=this._getEntryTwig(t,a),{compound:l,filtered:s,nodes:r,pending:u}=this._findEntryNodes(h,a,n);r.length?(this.#a[i].find=!0,this.#n[i]=r):u&&c.add(new Map([["index",i],["twig",h]])),this.#a[i].dir=o,this.#a[i].filtered=s||!l,i++}if(c.size){let t,n;this.#e!==this.#s&&this.#e.nodeType===f.ELEMENT_NODE?(t=this.#e,n=this.#r):(t=this.#s,n=this.#d);let o=this._traverse(t,n);for(;o;){let h=!1;if(this.#e.nodeType===f.ELEMENT_NODE?o===this.#e?h=!0:h=this.#e.contains(o):h=!0,h)for(const l of c){const{leaves:s}=l.get("twig");if(this._matchLeaves(s,o,{warn:this.#i})){const u=l.get("index");this.#a[u].filtered=!0,this.#a[u].find=!0,this.#n[u].push(o)}}o=n.nextNode()}}}else{let c=0;for(const{branch:i}of e){const t=i[i.length-1],n=i.length>1,{compound:o,filtered:h,nodes:l}=this._findEntryNodes(t,a,n);l.length&&(this.#a[c].find=!0,this.#n[c]=l),this.#a[c].dir=O,this.#a[c].filtered=h||!o,c++}}return[this.#a,this.#n]}_matchNodes(a){const[...e]=this.#a,c=e.length;let i=new Set;for(let t=0;t=0;d--){const m=n[d],w=[];for(const _ of S){const y=this._matchCombinator(m,_,{dir:o,warn:this.#i});y.size&&w.push(...y)}if(w.length)d===0?(i.add(N),p=!0,a===L&&s>1&&i.size>1&&(this.#o=!0)):(S=new Set(w),p=!1);else{p=!1;break}}if(p&&a!==L)break}if(!p&&a===$){const[g]=[...r];let N=this._findNode(k,{node:g});for(;N;){let S=new Set([N]);for(let d=b-1;d>=0;d--){const m=n[d],w=[];for(const _ of S){const y=this._matchCombinator(m,_,{dir:o,warn:this.#i});y.size&&w.push(...y)}if(w.length)d===0?(i.add(N),p=!0):(S=new Set(w),p=!1);else{p=!1;break}}if(p)break;N=this._findNode(k,{node:N}),S=new Set([N])}}}}}return i}_find(a){return this._collectNodes(a),this._matchNodes(a)}matches(a,e,c){let i;try{if(this.#e=this._setup(a,e,c),e.nodeType!==f.ELEMENT_NODE){const n=`Unexpected node ${e.nodeName}`;throw new TypeError(n)}i=this._find(P).size}catch(t){this._onError(t)}return!!i}closest(a,e,c){let i;try{if(this.#e=this._setup(a,e,c),e.nodeType!==f.ELEMENT_NODE){const n=`Unexpected node ${e.nodeName}`;throw new TypeError(n)}const t=this._find(M);if(t.size){let n=this.#e;for(;n;){if(t.has(n)){i=n;break}n=n.parentNode}}}catch(t){this._onError(t)}return i??null}querySelector(a,e,c){let i;try{this.#e=this._setup(a,e,c),this._prepareTreeWalkers(e);const t=this._find($);t.delete(this.#e),t.size&&([i]=(0,x.sortNodes)(t))}catch(t){this._onError(t)}return i??null}querySelectorAll(a,e,c){let i;try{this.#e=this._setup(a,e,c),this._prepareTreeWalkers(e);const t=this._find(L);t.delete(this.#e),t.size&&(this.#o?i=(0,x.sortNodes)(t):i=[...t])}catch(t){this._onError(t)}return i??[]}}0&&(module.exports={Finder}); //# sourceMappingURL=finder.js.map diff --git a/dist/cjs/js/finder.js.map b/dist/cjs/js/finder.js.map index ec6831f5..bdd14d7f 100644 --- a/dist/cjs/js/finder.js.map +++ b/dist/cjs/js/finder.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../../../src/js/finder.js"], - "sourcesContent": ["/**\n * finder.js\n */\n\n/* import */\nimport isCustomElementName from 'is-potential-custom-element-name';\nimport {\n getDirectionality, isContentEditable, isInclusive, isInShadowTree,\n prepareDOMObjects, sortNodes\n} from './dom-util.js';\nimport { matchPseudoElementSelector, matchSelector } from './matcher.js';\nimport {\n generateCSS, parseSelector, sortAST, unescapeSelector, walkAST\n} from './parser.js';\n\n/* constants */\nimport {\n ALPHA_NUM, COMBINATOR, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, ELEMENT_NODE,\n NOT_SUPPORTED_ERR, REG_LOGICAL_PSEUDO, REG_SHADOW_HOST, SELECTOR_CLASS,\n SELECTOR_ID, SELECTOR_PSEUDO_CLASS, SELECTOR_PSEUDO_ELEMENT, SELECTOR_TYPE,\n SHOW_ALL, SHOW_DOCUMENT, SHOW_DOCUMENT_FRAGMENT, SHOW_ELEMENT, SYNTAX_ERR,\n TEXT_NODE\n} from './constant.js';\nconst DIR_NEXT = 'next';\nconst DIR_PREV = 'prev';\nconst TARGET_ALL = 'all';\nconst TARGET_FIRST = 'first';\nconst TARGET_LINEAL = 'lineal';\nconst TARGET_SELF = 'self';\nconst WALKER_FILTER = SHOW_DOCUMENT | SHOW_DOCUMENT_FRAGMENT | SHOW_ELEMENT;\n\n/**\n * Finder\n * NOTE: #ast[i] corresponds to #nodes[i]\n * #ast: [\n * {\n * branch: branch[],\n * dir: string|null,\n * filtered: boolean,\n * find: boolean\n * },\n * {\n * branch: branch[],\n * dir: string|null,\n * filtered: boolean,\n * find: boolean\n * }\n * ]\n * #nodes: [\n * [node{}, node{}],\n * [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{}: CSSTree AST object\n * node{}: Element node\n */\nexport class Finder {\n /* private fields */\n #ast;\n #cache;\n #document;\n #finder;\n #node;\n #nodes;\n #noexcept;\n #results;\n #root;\n #shadow;\n #sort;\n #tree;\n #warn;\n #window;\n\n /**\n * construct\n */\n constructor() {\n this.#cache = new WeakMap();\n }\n\n /**\n * handle error\n * @private\n * @param {Error} e - Error\n * @throws Error\n * @returns {void}\n */\n _onError(e) {\n if (!this.#noexcept) {\n if (e instanceof DOMException ||\n (this.#window && e instanceof this.#window.DOMException)) {\n if (e.name === NOT_SUPPORTED_ERR) {\n if (this.#warn) {\n console.warn(e.message);\n }\n } else if (this.#window) {\n throw new this.#window.DOMException(e.message, e.name);\n } else {\n throw e;\n }\n } else {\n throw e;\n }\n }\n }\n\n /**\n * setup finder\n * @private\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} opt - options\n * @param {boolean} [opt.noexcept] - no exception\n * @param {boolean} [opt.warn] - console warn\n * @returns {object} - node\n */\n _setup(selector, node, opt = {}) {\n const { noexcept, warn } = opt;\n this.#noexcept = !!noexcept;\n this.#warn = !!warn;\n this.#node = node;\n [this.#window, this.#document, this.#root] = prepareDOMObjects(node);\n this.#shadow = isInShadowTree(node);\n [this.#ast, this.#nodes] = this._correspond(selector);\n this.#results = new WeakMap();\n return node;\n }\n\n /**\n * correspond #ast and #nodes\n * @private\n * @param {string} selector - CSS selector\n * @returns {Array.>} - array of #ast and #nodes\n */\n _correspond(selector) {\n const nodes = [];\n let ast;\n let cachedItem = this.#document && this.#cache.get(this.#document);\n if (cachedItem && cachedItem.has(`${selector}`)) {\n ast = cachedItem.get(selector);\n }\n if (ast) {\n const l = ast.length;\n for (let i = 0; i < l; i++) {\n ast[i].dir = null;\n ast[i].filtered = false;\n ast[i].find = false;\n nodes[i] = [];\n }\n } else {\n let cssAst;\n try {\n cssAst = parseSelector(selector);\n } catch (e) {\n this._onError(e);\n }\n const branches = walkAST(cssAst);\n ast = [];\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 selector ${selector}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n branch.push({\n combo: item,\n leaves: sortAST(leaves)\n });\n leaves.clear();\n } else if (item) {\n let { name: itemName } = item;\n if (itemName) {\n if (Object.prototype.hasOwnProperty.call(itemName, 'name')) {\n itemName = unescapeSelector(itemName.name);\n if (/[|:]/.test(itemName)) {\n item.namespace = true;\n }\n } else if (typeof itemName === 'string') {\n itemName = unescapeSelector(itemName);\n if (/[|:]/.test(itemName)) {\n item.namespace = true;\n }\n }\n }\n leaves.add(item);\n }\n if (items.length) {\n item = items.shift();\n } else {\n branch.push({\n combo: null,\n leaves: sortAST(leaves)\n });\n leaves.clear();\n break;\n }\n }\n }\n ast.push({\n branch,\n dir: null,\n filtered: false,\n find: false\n });\n nodes[i] = [];\n i++;\n }\n if (this.#document) {\n if (!cachedItem) {\n cachedItem = new Map();\n }\n cachedItem.set(`${selector}`, ast);\n this.#cache.set(this.#document, cachedItem);\n }\n }\n return [\n ast,\n nodes\n ];\n }\n\n /**\n * prepare tree walkers\n * @private\n * @param {object} node - Document, DocumentFragment, Element node\n * @returns {Array} - [#tree, #finder]\n */\n _prepareTreeWalkers(node) {\n this.#tree = this.#document.createTreeWalker(this.#root, WALKER_FILTER);\n this.#finder = this.#document.createTreeWalker(node, WALKER_FILTER);\n this.#sort = false;\n return [\n this.#tree,\n this.#finder\n ];\n }\n\n /**\n * traverse tree walker\n * @private\n * @param {object} [node] - Element node\n * @param {object} [walker] - tree walker\n * @returns {?object} - current node\n */\n _traverse(node = {}, walker = this.#tree) {\n let current;\n let refNode = walker.currentNode;\n if (node.nodeType === ELEMENT_NODE && refNode === node) {\n current = refNode;\n } else {\n if (refNode !== walker.root) {\n while (refNode) {\n if (refNode === walker.root ||\n (node.nodeType === ELEMENT_NODE && refNode === node)) {\n break;\n }\n refNode = walker.parentNode();\n }\n }\n if (node.nodeType === ELEMENT_NODE) {\n while (refNode) {\n if (refNode === node) {\n current = refNode;\n break;\n }\n refNode = walker.nextNode();\n }\n } else {\n current = refNode;\n }\n }\n return current ?? null;\n }\n\n /**\n * collect nth child\n * @private\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 * @param {object} opt - options\n * @returns {Set.} - collection of matched nodes\n */\n _collectNthChild(anb, node, opt) {\n const { a, b, reverse, selector } = anb;\n const { parentNode } = node;\n let 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 walker = this.#document.createTreeWalker(parentNode, WALKER_FILTER);\n let l = 0;\n let refNode = walker.firstChild();\n while (refNode) {\n l++;\n refNode = walker.nextSibling();\n }\n refNode = this._traverse(parentNode, walker);\n const selectorNodes = new Set();\n if (selectorBranches) {\n refNode = this._traverse(parentNode, walker);\n refNode = walker.firstChild();\n while (refNode) {\n let bool;\n for (const leaves of selectorBranches) {\n bool = this._matchLeaves(leaves, refNode, opt);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n selectorNodes.add(refNode);\n }\n refNode = walker.nextSibling();\n }\n }\n // :first-child, :last-child, :nth-child(b of S), :nth-last-child(b of S)\n if (a === 0) {\n if (b > 0 && b <= l) {\n if (selectorNodes.size) {\n let i = 0;\n refNode = this._traverse(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n while (refNode) {\n if (selectorNodes.has(refNode)) {\n if (i === b - 1) {\n matched.add(refNode);\n break;\n }\n i++;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n }\n } else if (!selector) {\n let i = 0;\n refNode = this._traverse(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n while (refNode) {\n if (i === b - 1) {\n matched.add(refNode);\n break;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n i++;\n }\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 i = 0;\n let j = a > 0 ? 0 : b - 1;\n refNode = this._traverse(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n while (refNode) {\n if (refNode && nth >= 0 && nth < l) {\n if (selectorNodes.size) {\n if (selectorNodes.has(refNode)) {\n if (j === nth) {\n matched.add(refNode);\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(refNode);\n }\n nth += a;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n i++;\n } else {\n break;\n }\n }\n }\n }\n if (reverse && matched.size > 1) {\n const m = [...matched];\n matched = new Set(m.reverse());\n }\n } else if (node === this.#root && (a + b) === 1) {\n if (selectorBranches) {\n let bool;\n for (const leaves of selectorBranches) {\n bool = this._matchLeaves(leaves, node, opt);\n if (bool) {\n break;\n }\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n }\n return matched;\n }\n\n /**\n * collect nth of type\n * @private\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.} - collection of matched nodes\n */\n _collectNthOfType(anb, node) {\n const { a, b, reverse } = anb;\n const { localName, parentNode, prefix } = node;\n let matched = new Set();\n if (parentNode) {\n const walker = this.#document.createTreeWalker(parentNode, WALKER_FILTER);\n let l = 0;\n let refNode = walker.firstChild();\n while (refNode) {\n l++;\n refNode = walker.nextSibling();\n }\n // :first-of-type, :last-of-type\n if (a === 0) {\n if (b > 0 && b <= l) {\n let j = 0;\n refNode = this._traverse(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n while (refNode) {\n const { localName: itemLocalName, prefix: itemPrefix } = refNode;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === b - 1) {\n matched.add(refNode);\n break;\n }\n j++;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\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 refNode = this._traverse(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n while (refNode) {\n const { localName: itemLocalName, prefix: itemPrefix } = refNode;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === nth) {\n matched.add(refNode);\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 if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n }\n }\n }\n if (reverse && matched.size > 1) {\n const m = [...matched];\n matched = new Set(m.reverse());\n }\n } else if (node === this.#root && (a + b) === 1) {\n matched.add(node);\n }\n return matched;\n }\n\n /**\n * match An+B\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {string} nthName - nth pseudo-class name\n * @param {object} opt - options\n * @returns {Set.} - collection of matched nodes\n */\n _matchAnPlusB(ast, node, nthName, opt) {\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, opt);\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 directionality pseudo-class - :dir()\n * @private\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 * @private\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 (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 if (astName) {\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 return res ?? null;\n }\n\n /**\n * match :has() pseudo-class function\n * @private\n * @param {Array.} leaves - AST leaves\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {boolean} - result\n */\n _matchHasPseudoFunc(leaves, node, opt = {}) {\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 opt.dir = DIR_NEXT;\n const nodes = this._matchCombinator(twig, node, opt);\n if (nodes.size) {\n if (leaves.length) {\n for (const nextNode of nodes) {\n bool = this._matchHasPseudoFunc(Object.assign([], leaves),\n nextNode, opt);\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 * @private\n * @param {object} astData - AST data\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\n _matchLogicalPseudoFunc(astData, node, opt = {}) {\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 let bool;\n for (const leaves of branches) {\n bool = this._matchHasPseudoFunc(Object.assign([], leaves), node, opt);\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 opt.forgive = forgive;\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, opt);\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 opt.dir = DIR_PREV;\n for (const nextNode of nextNodes) {\n const m = this._matchCombinator(twig, nextNode, opt);\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n if (j === 0) {\n bool = true;\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 * @private\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] - forgive unknown pseudo-class\n * @param {boolean} [opt.warn] - warn unsupported pseudo-class\n * @returns {Set.} - collection of matched nodes\n */\n _matchPseudoClassSelector(ast, node, opt = {}) {\n const { children: astChildren } = ast;\n const { localName, parentNode } = node;\n const {\n forgive,\n warn = this.#warn\n } = 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, opt);\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, opt);\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 (warn) {\n const msg = `Unsupported pseudo-class :${astName}()`;\n throw new DOMException(msg, 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 const msg = `Unknown pseudo-class :${astName}()`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n }\n }\n }\n } else {\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 { href, origin, pathname } = new URL(this.#document.URL);\n const attrURL = new URL(node.getAttribute('href'), href);\n if (attrURL.origin === origin && attrURL.pathname === pathname) {\n matched.add(node);\n }\n }\n break;\n }\n case 'visited': {\n // prevent fingerprinting\n break;\n }\n case 'target': {\n const { hash } = new URL(this.#document.URL);\n if (node.id && hash === `#${node.id}` &&\n this.#document.contains(node)) {\n matched.add(node);\n }\n break;\n }\n case 'target-within': {\n const { hash } = new URL(this.#document.URL);\n if (hash) {\n const id = hash.replace(/^#/, '');\n let current = this.#document.getElementById(id);\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 === this.#document.documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'focus': {\n if (node === this.#document.activeElement) {\n let focus = true;\n let refNode = node;\n while (refNode) {\n if (refNode.hasAttribute('hidden')) {\n focus = false;\n break;\n } else if (refNode.hasAttribute('style')) {\n const { display, visibility } = refNode.style;\n focus = !(display === 'none' || visibility === 'hidden');\n if (!focus) {\n break;\n }\n }\n if (refNode.parentNode &&\n refNode.parentNode.nodeType === ELEMENT_NODE) {\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n if (focus) {\n matched.add(node);\n }\n }\n break;\n }\n case 'focus-within': {\n let active;\n let current = this.#document.activeElement;\n while (current) {\n if (current === node) {\n active = true;\n break;\n }\n current = current.parentNode;\n }\n if (active) {\n let focus = true;\n let refNode = node;\n while (refNode) {\n if (refNode.hasAttribute('hidden')) {\n focus = false;\n break;\n } else if (refNode.hasAttribute('style')) {\n const { display, visibility } = refNode.style;\n focus = !(display === 'none' || visibility === 'hidden');\n if (!focus) {\n break;\n }\n }\n if (refNode.parentNode &&\n refNode.parentNode.nodeType === ELEMENT_NODE) {\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n if (focus) {\n matched.add(node);\n }\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 = this.#document.documentElement;\n }\n let checked;\n const items = parent.getElementsByTagName('input');\n const l = items.length;\n if (l) {\n for (let i = 0; i < l; i++) {\n const item = items[i];\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 }\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 walker =\n this.#document.createTreeWalker(form, SHOW_ELEMENT);\n let nextNode = walker.firstChild();\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 = walker.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 defaultOpt = new Set();\n const walker =\n this.#document.createTreeWalker(parentNode, SHOW_ELEMENT);\n let refNode = walker.firstChild();\n while (refNode) {\n if (refNode.selected || refNode.hasAttribute('selected')) {\n defaultOpt.add(refNode);\n break;\n }\n refNode = walker.nextSibling();\n }\n if (defaultOpt.size) {\n if (defaultOpt.has(node)) {\n matched.add(node);\n }\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 let bool;\n const walker = this.#document.createTreeWalker(node, SHOW_ELEMENT);\n let refNode = walker.firstChild();\n while (refNode) {\n if (regFormValidity.test(refNode.localName)) {\n bool = refNode.checkValidity();\n if (!bool) {\n break;\n }\n }\n refNode = walker.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 let bool;\n const walker = this.#document.createTreeWalker(node, SHOW_ELEMENT);\n let refNode = walker.firstChild();\n while (refNode) {\n if (regFormValidity.test(refNode.localName)) {\n bool = refNode.checkValidity();\n if (!bool) {\n break;\n }\n }\n refNode = walker.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 === this.#document.documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'empty': {\n if (node.hasChildNodes()) {\n let bool;\n const walker = this.#document.createTreeWalker(node, SHOW_ALL);\n let refNode = walker.firstChild();\n while (refNode) {\n bool = refNode.nodeType !== ELEMENT_NODE &&\n refNode.nodeType !== TEXT_NODE;\n if (!bool) {\n break;\n }\n refNode = walker.nextSibling();\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 === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'last-child': {\n if ((parentNode && node === parentNode.lastElementChild) ||\n node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'only-child': {\n if ((parentNode && node === parentNode.firstElementChild &&\n node === parentNode.lastElementChild) || node === this.#root) {\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 === this.#root) {\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 === this.#root) {\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 === this.#root) {\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 (warn) {\n const msg = `Unsupported pseudo-element ::${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n case 'active':\n case 'autofill':\n case 'blank':\n case 'buffering':\n case 'current':\n case 'defined':\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 (warn) {\n const msg = `Unsupported pseudo-class :${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (warn) {\n const msg = `Unsupported pseudo-class :${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n const msg = `Unknown pseudo-class :${astName}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * match shadow host pseudo class\n * @private\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 const msg = `Invalid selector ${css}`;\n throw new DOMException(msg, 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 bool;\n let parent = host;\n while (parent) {\n for (const leaf of leaves) {\n const { type: leafType } = leaf;\n if (leafType === COMBINATOR) {\n const css = generateCSS(ast);\n const msg = `Invalid selector ${css}`;\n throw new DOMException(msg, 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 const msg = `Invalid selector :${astName}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n return res ?? null;\n }\n\n /**\n * match selector\n * @private\n * @param {object} ast - AST\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} [opt] - options\n * @returns {Set.} - collection of matched nodes\n */\n _matchSelector(ast, node, opt) {\n const { type: astType } = ast;\n const astName = unescapeSelector(ast.name);\n let matched = new Set();\n if (node.nodeType === ELEMENT_NODE) {\n switch (astType) {\n case SELECTOR_CLASS: {\n if (node.classList.contains(astName)) {\n matched.add(node);\n }\n break;\n }\n case SELECTOR_ID: {\n if (astName === node.id) {\n matched.add(node);\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 matchPseudoElementSelector(astName, opt);\n break;\n }\n default: {\n const res = matchSelector(ast, node, opt);\n if (res) {\n matched.add(res);\n }\n }\n }\n } else if (this.#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, opt);\n if (res) {\n matched.add(res);\n }\n }\n }\n return matched;\n }\n\n /**\n * match leaves\n * @private\n * @param {Array.} 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 if (this.#results.has(leaves)) {\n const result = this.#results.get(leaves);\n if (result.has(node)) {\n bool = result.get(node);\n } else {\n for (const leaf of leaves) {\n bool = this._matchSelector(leaf, node, opt).has(node);\n if (!bool) {\n break;\n }\n }\n result.set(node, bool);\n this.#results.set(leaves, result);\n }\n } else {\n for (const leaf of leaves) {\n bool = this._matchSelector(leaf, node, opt).has(node);\n if (!bool) {\n break;\n }\n }\n const result = new WeakMap();\n result.set(node, bool);\n this.#results.set(leaves, result);\n }\n return !!bool;\n }\n\n /**\n * match HTML collection\n * @private\n * @param {object} items - HTML collection\n * @param {object} opt - options\n * @returns {Set.} - matched nodes\n */\n _matchHTMLCollection(items, opt = {}) {\n const { compound, filterLeaves } = opt;\n let nodes = new Set();\n const l = items.length;\n if (l) {\n if (compound) {\n for (let i = 0; i < l; i++) {\n const item = items[i];\n const bool = this._matchLeaves(filterLeaves, item, opt);\n if (bool) {\n nodes.add(item);\n }\n }\n } else {\n const arr = [].slice.call(items);\n nodes = new Set(arr);\n }\n }\n return nodes;\n }\n\n /**\n * find descendant nodes\n * @private\n * @param {Array.} leaves - AST leaves\n * @param {object} baseNode - base Element node\n * @param {object} opt - options\n * @returns {object} - collection of nodes and pending state\n */\n _findDescendantNodes(leaves, baseNode, opt) {\n const [leaf, ...filterLeaves] = leaves;\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n const compound = filterLeaves.length > 0;\n let nodes = new Set();\n let pending = false;\n if (this.#shadow) {\n pending = true;\n } else {\n switch (leafType) {\n case SELECTOR_PSEUDO_ELEMENT: {\n matchPseudoElementSelector(leafName, opt);\n break;\n }\n case SELECTOR_ID: {\n if (this.#root.nodeType === ELEMENT_NODE) {\n pending = true;\n } else {\n const node = this.#root.getElementById(leafName);\n if (node && node !== baseNode && baseNode.contains(node)) {\n if (compound) {\n const bool = this._matchLeaves(filterLeaves, node, opt);\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 items = baseNode.getElementsByClassName(leafName);\n nodes = this._matchHTMLCollection(items, {\n compound,\n filterLeaves\n });\n break;\n }\n case SELECTOR_TYPE: {\n if (this.#document.contentType === 'text/html' &&\n !/[*|]/.test(leafName)) {\n const items = baseNode.getElementsByTagName(leafName);\n nodes = this._matchHTMLCollection(items, {\n compound,\n filterLeaves\n });\n } else {\n pending = true;\n }\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 * @private\n * @param {object} twig - twig\n * @param {object} node - Element node\n * @param {object} opt - option\n * @returns {Set.} - collection of matched nodes\n */\n _matchCombinator(twig, node, opt = {}) {\n const { combo, leaves } = twig;\n const { name: comboName } = combo;\n const { dir } = opt;\n let matched = new Set();\n if (dir === DIR_NEXT) {\n switch (comboName) {\n case '+': {\n const refNode = node.nextElementSibling;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n const { parentNode } = node;\n if (parentNode) {\n const walker =\n this.#document.createTreeWalker(parentNode, SHOW_ELEMENT);\n let refNode = this._traverse(node, walker);\n if (refNode === node) {\n refNode = walker.nextSibling();\n }\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n refNode = walker.nextSibling();\n }\n }\n break;\n }\n case '>': {\n const walker = this.#document.createTreeWalker(node, SHOW_ELEMENT);\n let refNode = walker.firstChild();\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n refNode = walker.nextSibling();\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 walker = this.#document.createTreeWalker(node, SHOW_ELEMENT);\n let refNode = walker.nextNode();\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n refNode = walker.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, opt);\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n const walker =\n this.#document.createTreeWalker(node.parentNode, SHOW_ELEMENT);\n let refNode = walker.firstChild();\n while (refNode) {\n if (refNode === node) {\n break;\n } else {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n }\n refNode = walker.nextSibling();\n }\n break;\n }\n case '>': {\n const refNode = node.parentNode;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\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, opt);\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 matched node from finder\n * @private\n * @param {Array.} leaves - AST leaves\n * @param {object} [opt] - options\n * @param {object} [opt.node] - node to start from\n * @returns {?object} - matched node\n */\n _findNode(leaves, opt = {}) {\n const { node } = opt;\n let matchedNode;\n let refNode = this._traverse(node, this.#finder);\n if (refNode) {\n if (refNode.nodeType !== ELEMENT_NODE) {\n refNode = this.#finder.nextNode();\n } else if (refNode === node) {\n if (refNode !== this.#root) {\n refNode = this.#finder.nextNode();\n }\n }\n while (refNode) {\n let bool;\n if (this.#node.nodeType === ELEMENT_NODE) {\n if (refNode === this.#node) {\n bool = true;\n } else {\n bool = this.#node.contains(refNode);\n }\n } else {\n bool = true;\n }\n if (bool) {\n const matched = this._matchLeaves(leaves, refNode, {\n warn: this.#warn\n });\n if (matched) {\n matchedNode = refNode;\n break;\n }\n }\n refNode = this.#finder.nextNode();\n }\n }\n return matchedNode ?? null;\n }\n\n /**\n * match self\n * @private\n * @param {Array} leaves - AST leaves\n * @returns {Array} - [nodes, filtered]\n */\n _matchSelf(leaves) {\n const nodes = [];\n let filtered = false;\n const bool = this._matchLeaves(leaves, this.#node);\n if (bool) {\n nodes.push(this.#node);\n filtered = true;\n }\n return [nodes, filtered];\n }\n\n /**\n * find lineal\n * @private\n * @param {Array} leaf - AST leaf\n * @param {object} opt - options\n * @returns {Array} - [nodes, filtered]\n */\n _findLineal(leaf, opt = {}) {\n const { complex, compound, filterLeaves } = opt;\n const nodes = [];\n let filtered = false;\n let bool = this._matchLeaves([leaf], this.#node);\n if (bool && !complex) {\n if (compound) {\n bool = this._matchLeaves(filterLeaves, this.#node);\n if (bool) {\n nodes.push(this.#node);\n filtered = true;\n }\n } else {\n nodes.push(this.#node);\n filtered = true;\n }\n }\n if (!bool || complex) {\n if (bool) {\n nodes.push(this.#node);\n if (!compound) {\n filtered = true;\n }\n }\n let refNode = this.#node.parentNode;\n while (refNode) {\n bool = this._matchLeaves([leaf], refNode);\n if (bool) {\n nodes.push(refNode);\n if (!compound) {\n filtered = true;\n }\n }\n if (refNode.parentNode) {\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n }\n return [nodes, filtered];\n }\n\n /**\n * find first\n * @private\n * @param {Array} leaves - AST leaves\n * @returns {Array} - [nodes, filtered]\n */\n _findFirst(leaves) {\n const nodes = [];\n let filtered = false;\n const node = this._findNode(leaves, {\n node: this.#node\n });\n if (node) {\n nodes.push(node);\n filtered = true;\n }\n return [nodes, filtered];\n }\n\n /**\n * find from HTML collection\n * @private\n * @param {object} items - HTML collection\n * @param {object} opt - options\n * @param {boolean} [opt.compound] - compound selector\n * @param {Array} [opt.filterLeaves] - filter leaves\n * @returns {Array} - [nodes, filtered]\n */\n _findFromHTMLCollection(items, opt = {}) {\n const { compound, filterLeaves } = opt;\n let nodes = [];\n let filtered = false;\n const l = items.length;\n if (l) {\n if (this.#node.nodeType === ELEMENT_NODE) {\n for (let i = 0; i < l; i++) {\n const node = items[i];\n if (node === this.#node || isInclusive(node, this.#node)) {\n if (compound) {\n const bool = this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(node);\n filtered = true;\n }\n } else {\n nodes.push(node);\n filtered = true;\n }\n }\n }\n } else if (compound) {\n for (let i = 0; i < l; i++) {\n const node = items[i];\n const bool = this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(node);\n filtered = true;\n }\n }\n } else {\n nodes = [].slice.call(items);\n filtered = true;\n }\n }\n return [nodes, filtered];\n }\n\n /**\n * find entry nodes\n * @private\n * @param {object} twig - twig\n * @param {string} targetType - target type\n * @param {boolean} complex - complex selector\n * @returns {object} - collection of nodes etc.\n */\n _findEntryNodes(twig, targetType, complex) {\n const { leaves } = twig;\n const [leaf, ...filterLeaves] = leaves;\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n const compound = filterLeaves.length > 0;\n let nodes = [];\n let filtered = false;\n let pending = false;\n switch (leafType) {\n case SELECTOR_PSEUDO_ELEMENT: {\n matchPseudoElementSelector(leafName, {\n warn: this.#warn\n });\n break;\n }\n case SELECTOR_ID: {\n if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaf, {\n complex,\n compound,\n filterLeaves\n });\n } else if (targetType === TARGET_FIRST &&\n this.#root.nodeType !== ELEMENT_NODE) {\n const node = this.#root.getElementById(leafName);\n if (node) {\n if (compound) {\n const bool = this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(node);\n filtered = true;\n }\n } else {\n nodes.push(node);\n filtered = true;\n }\n }\n } else {\n pending = true;\n }\n break;\n }\n case SELECTOR_CLASS: {\n if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaf, {\n complex,\n compound,\n filterLeaves\n });\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else if (this.#root.nodeType === DOCUMENT_NODE) {\n const items = this.#root.getElementsByClassName(leafName);\n [nodes, filtered] = this._findFromHTMLCollection(items, {\n compound,\n filterLeaves\n });\n } else {\n pending = true;\n }\n break;\n }\n case SELECTOR_TYPE: {\n if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaf, {\n complex,\n compound,\n filterLeaves\n });\n } else if (this.#document.contentType === 'text/html' &&\n this.#root.nodeType === DOCUMENT_NODE &&\n !/[*|]/.test(leafName)) {\n const items = this.#root.getElementsByTagName(leafName);\n [nodes, filtered] = this._findFromHTMLCollection(items, {\n compound,\n filterLeaves\n });\n } else {\n pending = true;\n }\n break;\n }\n default: {\n if (targetType !== TARGET_LINEAL && REG_SHADOW_HOST.test(leafName)) {\n if (this.#shadow &&\n this.#node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const node = this._matchShadowHostPseudoClass(leaf, this.#node);\n if (node) {\n nodes.push(node);\n filtered = true;\n }\n }\n } else if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaf, {\n complex,\n compound,\n filterLeaves\n });\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n }\n }\n return {\n compound,\n filtered,\n nodes,\n pending\n };\n }\n\n /**\n * get entry twig\n * @private\n * @param {Array.} branch - AST branch\n * @param {string} targetType - target type\n * @returns {object} - direction and twig\n */\n _getEntryTwig(branch, targetType) {\n const branchLen = branch.length;\n const complex = branchLen > 1;\n const firstTwig = branch[0];\n let dir;\n let twig;\n if (complex) {\n const {\n combo: firstCombo,\n leaves: [{\n name: firstName,\n type: firstType\n }]\n } = firstTwig;\n const lastTwig = branch[branchLen - 1];\n const {\n leaves: [{\n name: lastName,\n type: lastType\n }]\n } = lastTwig;\n if (lastType === SELECTOR_PSEUDO_ELEMENT || lastType === SELECTOR_ID) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else if (firstType === SELECTOR_PSEUDO_ELEMENT ||\n firstType === SELECTOR_ID) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else if (targetType === TARGET_ALL) {\n if (firstName === '*' && firstType === SELECTOR_TYPE) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else if (lastName === '*' && lastType === SELECTOR_TYPE) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else if (branchLen === 2) {\n const { name: comboName } = firstCombo;\n if (/^[+~]$/.test(comboName)) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else {\n dir = DIR_NEXT;\n twig = firstTwig;\n }\n } else {\n dir = DIR_NEXT;\n twig = firstTwig;\n }\n } else if (lastName === '*' && lastType === SELECTOR_TYPE) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else if (firstName === '*' && firstType === SELECTOR_TYPE) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else {\n let bool;\n let sibling;\n for (const { combo, leaves: [leaf] } of branch) {\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n if (leafType === SELECTOR_PSEUDO_CLASS && leafName === 'dir') {\n bool = false;\n break;\n }\n if (combo && !sibling) {\n const { name: comboName } = combo;\n if (/^[+~]$/.test(comboName)) {\n bool = true;\n sibling = true;\n }\n }\n }\n if (bool) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else {\n dir = DIR_PREV;\n twig = lastTwig;\n }\n }\n } else {\n dir = DIR_PREV;\n twig = firstTwig;\n }\n return {\n complex,\n dir,\n twig\n };\n }\n\n /**\n * collect nodes\n * @private\n * @param {string} targetType - target type\n * @returns {Array.>} - #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 { complex, dir, twig } = this._getEntryTwig(branch, targetType);\n const {\n compound, filtered, nodes, pending\n } = this._findEntryNodes(twig, targetType, complex);\n if (nodes.length) {\n this.#ast[i].find = true;\n this.#nodes[i] = nodes;\n } else if (pending) {\n pendingItems.add(new Map([\n ['index', i],\n ['twig', twig]\n ]));\n }\n this.#ast[i].dir = dir;\n this.#ast[i].filtered = filtered || !compound;\n i++;\n }\n if (pendingItems.size) {\n let node;\n let walker;\n if (this.#node !== this.#root && this.#node.nodeType === ELEMENT_NODE) {\n node = this.#node;\n walker = this.#finder;\n } else {\n node = this.#root;\n walker = this.#tree;\n }\n let nextNode = this._traverse(node, walker);\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 warn: this.#warn\n });\n if (matched) {\n const index = pendingItem.get('index');\n this.#ast[index].filtered = true;\n this.#ast[index].find = true;\n this.#nodes[index].push(nextNode);\n }\n }\n }\n nextNode = walker.nextNode();\n }\n }\n } else {\n let i = 0;\n for (const { branch } of ast) {\n const twig = branch[branch.length - 1];\n const complex = branch.length > 1;\n const {\n compound, filtered, nodes\n } = this._findEntryNodes(twig, targetType, complex);\n if (nodes.length) {\n this.#ast[i].find = true;\n this.#nodes[i] = nodes;\n }\n this.#ast[i].dir = DIR_PREV;\n this.#ast[i].filtered = filtered || !compound;\n i++;\n }\n }\n return [\n this.#ast,\n this.#nodes\n ];\n }\n\n /**\n * match nodes\n * @private\n * @param {string} targetType - target type\n * @returns {Set.} - 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, dir, filtered, find } = branches[i];\n const branchLen = branch.length;\n if (branchLen && find) {\n const entryNodes = this.#nodes[i];\n const entryNodesLen = entryNodes.length;\n const lastIndex = branchLen - 1;\n if (lastIndex === 0) {\n const { leaves: [, ...filterLeaves] } = branch[0];\n if ((targetType === TARGET_ALL || targetType === TARGET_FIRST) &&\n this.#node.nodeType === ELEMENT_NODE) {\n for (let j = 0; j < entryNodesLen; j++) {\n const node = entryNodes[j];\n if (node !== this.#node && this.#node.contains(node)) {\n nodes.add(node);\n if (targetType !== TARGET_ALL) {\n break;\n }\n }\n }\n } else if (filterLeaves.length) {\n for (let j = 0; j < entryNodesLen; j++) {\n const node = entryNodes[j];\n const bool = filtered || this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.add(node);\n if (targetType !== TARGET_ALL) {\n break;\n }\n }\n }\n } else if (targetType === TARGET_ALL) {\n if (nodes.size) {\n const n = [...nodes];\n nodes = new Set([...n, ...entryNodes]);\n this.#sort = true;\n } else {\n nodes = new Set([...entryNodes]);\n }\n } else {\n const [node] = [...entryNodes];\n nodes.add(node);\n }\n } else if (dir === DIR_NEXT) {\n let { combo, leaves: entryLeaves } = branch[0];\n let matched;\n for (let j = 0; j < entryNodesLen; j++) {\n const node = entryNodes[j];\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, {\n dir,\n warn: this.#warn\n });\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n if (j === lastIndex) {\n if (targetType === TARGET_ALL) {\n if (nodes.size) {\n const n = [...nodes];\n nodes = new Set([...n, ...arr]);\n } else {\n nodes = new Set([...arr]);\n }\n this.#sort = true;\n } else {\n const [node] = sortNodes(arr);\n nodes.add(node);\n }\n matched = true;\n } else {\n combo = nextCombo;\n nextNodes = new Set(arr);\n matched = false;\n }\n } else {\n matched = false;\n break;\n }\n }\n if (matched && targetType !== TARGET_ALL) {\n break;\n }\n }\n if (!matched && targetType === TARGET_FIRST) {\n const [entryNode] = [...entryNodes];\n let refNode = this._findNode(entryLeaves, {\n node: entryNode\n });\n while (refNode) {\n let nextNodes = new Set([refNode]);\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, {\n dir,\n warn: this.#warn\n });\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n if (j === lastIndex) {\n const [node] = sortNodes(arr);\n nodes.add(node);\n matched = true;\n } else {\n combo = nextCombo;\n nextNodes = new Set(arr);\n matched = false;\n }\n } else {\n matched = false;\n break;\n }\n }\n if (matched) {\n break;\n }\n refNode = this._findNode(entryLeaves, {\n node: refNode\n });\n nextNodes = new Set([refNode]);\n }\n }\n } else {\n const { leaves: entryLeaves } = branch[lastIndex];\n let matched;\n for (let j = 0; j < entryNodesLen; j++) {\n const node = entryNodes[j];\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 dir,\n warn: this.#warn\n });\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n if (j === 0) {\n nodes.add(node);\n matched = true;\n if (targetType === TARGET_ALL &&\n branchLen > 1 && nodes.size > 1) {\n this.#sort = true;\n }\n } else {\n nextNodes = new Set(arr);\n matched = false;\n }\n } else {\n matched = false;\n break;\n }\n }\n if (matched && targetType !== TARGET_ALL) {\n break;\n }\n }\n if (!matched && targetType === TARGET_FIRST) {\n const [entryNode] = [...entryNodes];\n let refNode = this._findNode(entryLeaves, {\n node: entryNode\n });\n while (refNode) {\n let nextNodes = new Set([refNode]);\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 dir,\n warn: this.#warn\n });\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n if (j === 0) {\n nodes.add(refNode);\n matched = true;\n } else {\n nextNodes = new Set(arr);\n matched = false;\n }\n } else {\n matched = false;\n break;\n }\n }\n if (matched) {\n break;\n }\n refNode = this._findNode(entryLeaves, {\n node: refNode\n });\n nextNodes = new Set([refNode]);\n }\n }\n }\n }\n }\n return nodes;\n }\n\n /**\n * find matched nodes\n * @private\n * @param {string} targetType - target type\n * @returns {Set.} - 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 * @param {string} selector - CSS selector\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {boolean} - `true` if matched `false` otherwise\n */\n matches(selector, node, opt) {\n let res;\n try {\n this.#node = this._setup(selector, node, opt);\n if (node.nodeType !== ELEMENT_NODE) {\n const msg = `Unexpected node ${node.nodeName}`;\n throw new TypeError(msg);\n }\n const nodes = this._find(TARGET_SELF);\n res = nodes.size;\n } catch (e) {\n this._onError(e);\n }\n return !!res;\n }\n\n /**\n * closest\n * @param {string} selector - CSS selector\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\n closest(selector, node, opt) {\n let res;\n try {\n this.#node = this._setup(selector, node, opt);\n if (node.nodeType !== ELEMENT_NODE) {\n const msg = `Unexpected node ${node.nodeName}`;\n throw new TypeError(msg);\n }\n const nodes = this._find(TARGET_LINEAL);\n if (nodes.size) {\n let refNode = this.#node;\n while (refNode) {\n if (nodes.has(refNode)) {\n res = refNode;\n break;\n }\n refNode = refNode.parentNode;\n }\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? null;\n }\n\n /**\n * query selector\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\n querySelector(selector, node, opt) {\n let res;\n try {\n this.#node = this._setup(selector, node, opt);\n this._prepareTreeWalkers(node);\n const nodes = this._find(TARGET_FIRST);\n nodes.delete(this.#node);\n if (nodes.size) {\n [res] = 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 * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} opt - options\n * @returns {Array.} - collection of matched nodes\n */\n querySelectorAll(selector, node, opt) {\n let res;\n try {\n this.#node = this._setup(selector, node, opt);\n this._prepareTreeWalkers(node);\n const nodes = this._find(TARGET_ALL);\n nodes.delete(this.#node);\n if (nodes.size) {\n if (this.#sort) {\n res = sortNodes(nodes);\n } else {\n res = [...nodes];\n }\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? [];\n }\n};\n"], - "mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,YAAAE,IAAA,eAAAC,EAAAH,GAKA,IAAAI,EAAgC,iDAChCC,EAGO,yBACPC,EAA0D,wBAC1DC,EAEO,uBAGPC,EAMO,yBACP,MAAMC,EAAW,OACXC,EAAW,OACXC,EAAa,MACbC,EAAe,QACfC,EAAgB,SAChBC,EAAc,OACdC,EAAgB,gBAAgB,yBAAyB,eAgCxD,MAAMb,CAAO,CAElBc,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GAKA,aAAc,CACZ,KAAKZ,GAAS,IAAI,OACpB,CASA,SAASa,EAAG,CACV,GAAI,CAAC,KAAKR,GACR,GAAIQ,aAAa,cACZ,KAAKD,IAAWC,aAAa,KAAKD,GAAQ,aAC7C,GAAIC,EAAE,OAAS,oBACT,KAAKF,IACP,QAAQ,KAAKE,EAAE,OAAO,MAEnB,OAAI,KAAKD,GACR,IAAI,KAAKA,GAAQ,aAAaC,EAAE,QAASA,EAAE,IAAI,EAE/CA,MAGR,OAAMA,CAGZ,CAYA,OAAOC,EAAUC,EAAMC,EAAM,CAAC,EAAG,CAC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AAOW,EAAUC,EAAMC,CAAG,EAC5C,KAAK,oBAAoBD,CAAI,EAC7B,MAAMI,EAAQ,KAAK,MAAMxB,CAAY,EACrCwB,EAAM,OAAO,KAAKhB,EAAK,EACnBgB,EAAM,OACR,CAACuC,CAAG,KAAI,aAAUvC,CAAK,EAE3B,OAASN,EAAG,CACV,KAAK,SAASA,CAAC,CACjB,CACA,OAAO6C,GAAO,IAChB,CAUA,iBAAiB5C,EAAUC,EAAMC,EAAK,CACpC,IAAI0C,EACJ,GAAI,CACF,KAAKvD,GAAQ,KAAK,OAAOW,EAAUC,EAAMC,CAAG,EAC5C,KAAK,oBAAoBD,CAAI,EAC7B,MAAMI,EAAQ,KAAK,MAAMzB,CAAU,EACnCyB,EAAM,OAAO,KAAKhB,EAAK,EACnBgB,EAAM,OACJ,KAAKV,GACPiD,KAAM,aAAUvC,CAAK,EAErBuC,EAAM,CAAC,GAAGvC,CAAK,EAGrB,OAASN,EAAG,CACV,KAAK,SAASA,CAAC,CACjB,CACA,OAAO6C,GAAO,CAAC,CACjB,CACF", + "sourcesContent": ["/**\n * finder.js\n */\n\n/* import */\nimport isCustomElementName from 'is-potential-custom-element-name';\nimport {\n getDirectionality, isContentEditable, isInclusive, isInShadowTree,\n prepareDOMObjects, sortNodes\n} from './dom-util.js';\nimport { matchPseudoElementSelector, matchSelector } from './matcher.js';\nimport {\n generateCSS, parseSelector, sortAST, unescapeSelector, walkAST\n} from './parser.js';\n\n/* constants */\nimport {\n ALPHA_NUM, COMBINATOR, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, ELEMENT_NODE,\n NOT_SUPPORTED_ERR, REG_LOGICAL_PSEUDO, REG_SHADOW_HOST, SELECTOR_CLASS,\n SELECTOR_ID, SELECTOR_PSEUDO_CLASS, SELECTOR_PSEUDO_ELEMENT, SELECTOR_TYPE,\n SHOW_ALL, SHOW_DOCUMENT, SHOW_DOCUMENT_FRAGMENT, SHOW_ELEMENT, SYNTAX_ERR,\n TEXT_NODE\n} from './constant.js';\nconst DIR_NEXT = 'next';\nconst DIR_PREV = 'prev';\nconst TARGET_ALL = 'all';\nconst TARGET_FIRST = 'first';\nconst TARGET_LINEAL = 'lineal';\nconst TARGET_SELF = 'self';\nconst WALKER_FILTER = SHOW_DOCUMENT | SHOW_DOCUMENT_FRAGMENT | SHOW_ELEMENT;\n\n/**\n * Finder\n * NOTE: #ast[i] corresponds to #nodes[i]\n * #ast: [\n * {\n * branch: branch[],\n * dir: string|null,\n * filtered: boolean,\n * find: boolean\n * },\n * {\n * branch: branch[],\n * dir: string|null,\n * filtered: boolean,\n * find: boolean\n * }\n * ]\n * #nodes: [\n * [node{}, node{}],\n * [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{}: CSSTree AST object\n * node{}: Element node\n */\nexport class Finder {\n /* private fields */\n #ast;\n #cache;\n #document;\n #finder;\n #node;\n #nodes;\n #noexcept;\n #results;\n #root;\n #shadow;\n #sort;\n #tree;\n #warn;\n #window;\n\n /**\n * construct\n */\n constructor() {\n this.#cache = new WeakMap();\n }\n\n /**\n * handle error\n * @private\n * @param {Error} e - Error\n * @throws Error\n * @returns {void}\n */\n _onError(e) {\n if (!this.#noexcept) {\n if (e instanceof DOMException ||\n (this.#window && e instanceof this.#window.DOMException)) {\n if (e.name === NOT_SUPPORTED_ERR) {\n if (this.#warn) {\n console.warn(e.message);\n }\n } else if (this.#window) {\n throw new this.#window.DOMException(e.message, e.name);\n } else {\n throw e;\n }\n } else {\n throw e;\n }\n }\n }\n\n /**\n * setup finder\n * @private\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} opt - options\n * @param {boolean} [opt.noexcept] - no exception\n * @param {boolean} [opt.warn] - console warn\n * @returns {object} - node\n */\n _setup(selector, node, opt = {}) {\n const { noexcept, warn } = opt;\n this.#noexcept = !!noexcept;\n this.#warn = !!warn;\n this.#node = node;\n [this.#window, this.#document, this.#root] = prepareDOMObjects(node);\n this.#shadow = isInShadowTree(node);\n [this.#ast, this.#nodes] = this._correspond(selector);\n this.#results = new WeakMap();\n return node;\n }\n\n /**\n * correspond #ast and #nodes\n * @private\n * @param {string} selector - CSS selector\n * @returns {Array.>} - array of #ast and #nodes\n */\n _correspond(selector) {\n const nodes = [];\n let ast;\n let cachedItem = this.#document && this.#cache.get(this.#document);\n if (cachedItem && cachedItem.has(`${selector}`)) {\n ast = cachedItem.get(selector);\n }\n if (ast) {\n const l = ast.length;\n for (let i = 0; i < l; i++) {\n ast[i].dir = null;\n ast[i].filtered = false;\n ast[i].find = false;\n nodes[i] = [];\n }\n } else {\n let cssAst;\n try {\n cssAst = parseSelector(selector);\n } catch (e) {\n this._onError(e);\n }\n const branches = walkAST(cssAst);\n ast = [];\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 selector ${selector}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n branch.push({\n combo: item,\n leaves: sortAST(leaves)\n });\n leaves.clear();\n } else if (item) {\n let { name: itemName } = item;\n if (itemName) {\n if (Object.prototype.hasOwnProperty.call(itemName, 'name')) {\n itemName = unescapeSelector(itemName.name);\n if (/[|:]/.test(itemName)) {\n item.namespace = true;\n }\n } else if (typeof itemName === 'string') {\n itemName = unescapeSelector(itemName);\n if (/[|:]/.test(itemName)) {\n item.namespace = true;\n }\n }\n }\n leaves.add(item);\n }\n if (items.length) {\n item = items.shift();\n } else {\n branch.push({\n combo: null,\n leaves: sortAST(leaves)\n });\n leaves.clear();\n break;\n }\n }\n }\n ast.push({\n branch,\n dir: null,\n filtered: false,\n find: false\n });\n nodes[i] = [];\n i++;\n }\n if (this.#document) {\n if (!cachedItem) {\n cachedItem = new Map();\n }\n cachedItem.set(`${selector}`, ast);\n this.#cache.set(this.#document, cachedItem);\n }\n }\n return [\n ast,\n nodes\n ];\n }\n\n /**\n * prepare tree walkers\n * @private\n * @param {object} node - Document, DocumentFragment, Element node\n * @returns {Array} - [#tree, #finder]\n */\n _prepareTreeWalkers(node) {\n this.#tree = this.#document.createTreeWalker(this.#root, WALKER_FILTER);\n this.#finder = this.#document.createTreeWalker(node, WALKER_FILTER);\n this.#sort = false;\n return [\n this.#tree,\n this.#finder\n ];\n }\n\n /**\n * traverse tree walker\n * @private\n * @param {object} [node] - Element node\n * @param {object} [walker] - tree walker\n * @returns {?object} - current node\n */\n _traverse(node = {}, walker = this.#tree) {\n let current;\n let refNode = walker.currentNode;\n if (node.nodeType === ELEMENT_NODE && refNode === node) {\n current = refNode;\n } else {\n if (refNode !== walker.root) {\n while (refNode) {\n if (refNode === walker.root ||\n (node.nodeType === ELEMENT_NODE && refNode === node)) {\n break;\n }\n refNode = walker.parentNode();\n }\n }\n if (node.nodeType === ELEMENT_NODE) {\n while (refNode) {\n if (refNode === node) {\n current = refNode;\n break;\n }\n refNode = walker.nextNode();\n }\n } else {\n current = refNode;\n }\n }\n return current ?? null;\n }\n\n /**\n * collect nth child\n * @private\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 * @param {object} opt - options\n * @returns {Set.} - collection of matched nodes\n */\n _collectNthChild(anb, node, opt) {\n const { a, b, reverse, selector } = anb;\n const { parentNode } = node;\n let 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 walker = this.#document.createTreeWalker(parentNode, WALKER_FILTER);\n let l = 0;\n let refNode = walker.firstChild();\n while (refNode) {\n l++;\n refNode = walker.nextSibling();\n }\n refNode = this._traverse(parentNode, walker);\n const selectorNodes = new Set();\n if (selectorBranches) {\n refNode = this._traverse(parentNode, walker);\n refNode = walker.firstChild();\n while (refNode) {\n let bool;\n for (const leaves of selectorBranches) {\n bool = this._matchLeaves(leaves, refNode, opt);\n if (!bool) {\n break;\n }\n }\n if (bool) {\n selectorNodes.add(refNode);\n }\n refNode = walker.nextSibling();\n }\n }\n // :first-child, :last-child, :nth-child(b of S), :nth-last-child(b of S)\n if (a === 0) {\n if (b > 0 && b <= l) {\n if (selectorNodes.size) {\n let i = 0;\n refNode = this._traverse(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n while (refNode) {\n if (selectorNodes.has(refNode)) {\n if (i === b - 1) {\n matched.add(refNode);\n break;\n }\n i++;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n }\n } else if (!selector) {\n let i = 0;\n refNode = this._traverse(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n while (refNode) {\n if (i === b - 1) {\n matched.add(refNode);\n break;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n i++;\n }\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 i = 0;\n let j = a > 0 ? 0 : b - 1;\n refNode = this._traverse(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n while (refNode) {\n if (refNode && nth >= 0 && nth < l) {\n if (selectorNodes.size) {\n if (selectorNodes.has(refNode)) {\n if (j === nth) {\n matched.add(refNode);\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(refNode);\n }\n nth += a;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n i++;\n } else {\n break;\n }\n }\n }\n }\n if (reverse && matched.size > 1) {\n const m = [...matched];\n matched = new Set(m.reverse());\n }\n } else if (node === this.#root && (a + b) === 1) {\n if (selectorBranches) {\n let bool;\n for (const leaves of selectorBranches) {\n bool = this._matchLeaves(leaves, node, opt);\n if (bool) {\n break;\n }\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n }\n return matched;\n }\n\n /**\n * collect nth of type\n * @private\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.} - collection of matched nodes\n */\n _collectNthOfType(anb, node) {\n const { a, b, reverse } = anb;\n const { localName, parentNode, prefix } = node;\n let matched = new Set();\n if (parentNode) {\n const walker = this.#document.createTreeWalker(parentNode, WALKER_FILTER);\n let l = 0;\n let refNode = walker.firstChild();\n while (refNode) {\n l++;\n refNode = walker.nextSibling();\n }\n // :first-of-type, :last-of-type\n if (a === 0) {\n if (b > 0 && b <= l) {\n let j = 0;\n refNode = this._traverse(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n while (refNode) {\n const { localName: itemLocalName, prefix: itemPrefix } = refNode;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === b - 1) {\n matched.add(refNode);\n break;\n }\n j++;\n }\n if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\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 refNode = this._traverse(parentNode, walker);\n if (reverse) {\n refNode = walker.lastChild();\n } else {\n refNode = walker.firstChild();\n }\n while (refNode) {\n const { localName: itemLocalName, prefix: itemPrefix } = refNode;\n if (itemLocalName === localName && itemPrefix === prefix) {\n if (j === nth) {\n matched.add(refNode);\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 if (reverse) {\n refNode = walker.previousSibling();\n } else {\n refNode = walker.nextSibling();\n }\n }\n }\n }\n if (reverse && matched.size > 1) {\n const m = [...matched];\n matched = new Set(m.reverse());\n }\n } else if (node === this.#root && (a + b) === 1) {\n matched.add(node);\n }\n return matched;\n }\n\n /**\n * match An+B\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {string} nthName - nth pseudo-class name\n * @param {object} opt - options\n * @returns {Set.} - collection of matched nodes\n */\n _matchAnPlusB(ast, node, nthName, opt) {\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, opt);\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 directionality pseudo-class - :dir()\n * @private\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 * @private\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 (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 if (astName) {\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 return res ?? null;\n }\n\n /**\n * match :has() pseudo-class function\n * @private\n * @param {Array.} leaves - AST leaves\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {boolean} - result\n */\n _matchHasPseudoFunc(leaves, node, opt = {}) {\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 opt.dir = DIR_NEXT;\n const nodes = this._matchCombinator(twig, node, opt);\n if (nodes.size) {\n if (leaves.length) {\n for (const nextNode of nodes) {\n bool = this._matchHasPseudoFunc(Object.assign([], leaves),\n nextNode, opt);\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 * @private\n * @param {object} astData - AST data\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\n _matchLogicalPseudoFunc(astData, node, opt = {}) {\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 let bool;\n for (const leaves of branches) {\n bool = this._matchHasPseudoFunc(Object.assign([], leaves), node, opt);\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 opt.forgive = forgive;\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, opt);\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 opt.dir = DIR_PREV;\n for (const nextNode of nextNodes) {\n const m = this._matchCombinator(twig, nextNode, opt);\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n if (j === 0) {\n bool = true;\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 * @private\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] - forgive unknown pseudo-class\n * @param {boolean} [opt.warn] - warn unsupported pseudo-class\n * @returns {Set.} - collection of matched nodes\n */\n _matchPseudoClassSelector(ast, node, opt = {}) {\n const { children: astChildren } = ast;\n const { localName, parentNode } = node;\n const {\n forgive,\n warn = this.#warn\n } = 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, opt);\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, opt);\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 (warn) {\n const msg = `Unsupported pseudo-class :${astName}()`;\n throw new DOMException(msg, 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 const msg = `Unknown pseudo-class :${astName}()`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n }\n }\n }\n } else {\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 { href, origin, pathname } = new URL(this.#document.URL);\n const attrURL = new URL(node.getAttribute('href'), href);\n if (attrURL.origin === origin && attrURL.pathname === pathname) {\n matched.add(node);\n }\n }\n break;\n }\n case 'visited': {\n // prevent fingerprinting\n break;\n }\n case 'target': {\n const { hash } = new URL(this.#document.URL);\n if (node.id && hash === `#${node.id}` &&\n this.#document.contains(node)) {\n matched.add(node);\n }\n break;\n }\n case 'target-within': {\n const { hash } = new URL(this.#document.URL);\n if (hash) {\n const id = hash.replace(/^#/, '');\n let current = this.#document.getElementById(id);\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 === this.#document.documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'focus': {\n if (node === this.#document.activeElement) {\n let focus = true;\n let refNode = node;\n while (refNode) {\n if (refNode.hasAttribute('hidden')) {\n focus = false;\n break;\n } else if (refNode.hasAttribute('style')) {\n const { display, visibility } = refNode.style;\n focus = !(display === 'none' || visibility === 'hidden');\n if (!focus) {\n break;\n }\n }\n if (refNode.parentNode &&\n refNode.parentNode.nodeType === ELEMENT_NODE) {\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n if (focus) {\n matched.add(node);\n }\n }\n break;\n }\n case 'focus-within': {\n let active;\n let current = this.#document.activeElement;\n while (current) {\n if (current === node) {\n active = true;\n break;\n }\n current = current.parentNode;\n }\n if (active) {\n let focus = true;\n let refNode = node;\n while (refNode) {\n if (refNode.hasAttribute('hidden')) {\n focus = false;\n break;\n } else if (refNode.hasAttribute('style')) {\n const { display, visibility } = refNode.style;\n focus = !(display === 'none' || visibility === 'hidden');\n if (!focus) {\n break;\n }\n }\n if (refNode.parentNode &&\n refNode.parentNode.nodeType === ELEMENT_NODE) {\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n if (focus) {\n matched.add(node);\n }\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 = this.#document.documentElement;\n }\n let checked;\n const items = parent.getElementsByTagName('input');\n const l = items.length;\n if (l) {\n for (let i = 0; i < l; i++) {\n const item = items[i];\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 }\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 walker =\n this.#document.createTreeWalker(form, SHOW_ELEMENT);\n let nextNode = walker.firstChild();\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 = walker.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 defaultOpt = new Set();\n const walker =\n this.#document.createTreeWalker(parentNode, SHOW_ELEMENT);\n let refNode = walker.firstChild();\n while (refNode) {\n if (refNode.selected || refNode.hasAttribute('selected')) {\n defaultOpt.add(refNode);\n break;\n }\n refNode = walker.nextSibling();\n }\n if (defaultOpt.size) {\n if (defaultOpt.has(node)) {\n matched.add(node);\n }\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 let bool;\n const walker = this.#document.createTreeWalker(node, SHOW_ELEMENT);\n let refNode = walker.firstChild();\n while (refNode) {\n if (regFormValidity.test(refNode.localName)) {\n bool = refNode.checkValidity();\n if (!bool) {\n break;\n }\n }\n refNode = walker.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 let bool;\n const walker = this.#document.createTreeWalker(node, SHOW_ELEMENT);\n let refNode = walker.firstChild();\n while (refNode) {\n if (regFormValidity.test(refNode.localName)) {\n bool = refNode.checkValidity();\n if (!bool) {\n break;\n }\n }\n refNode = walker.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 === this.#document.documentElement) {\n matched.add(node);\n }\n break;\n }\n case 'empty': {\n if (node.hasChildNodes()) {\n let bool;\n const walker = this.#document.createTreeWalker(node, SHOW_ALL);\n let refNode = walker.firstChild();\n while (refNode) {\n bool = refNode.nodeType !== ELEMENT_NODE &&\n refNode.nodeType !== TEXT_NODE;\n if (!bool) {\n break;\n }\n refNode = walker.nextSibling();\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 === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'last-child': {\n if ((parentNode && node === parentNode.lastElementChild) ||\n node === this.#root) {\n matched.add(node);\n }\n break;\n }\n case 'only-child': {\n if ((parentNode && node === parentNode.firstElementChild &&\n node === parentNode.lastElementChild) || node === this.#root) {\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 === this.#root) {\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 === this.#root) {\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 === this.#root) {\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 (warn) {\n const msg = `Unsupported pseudo-element ::${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n case 'active':\n case 'autofill':\n case 'blank':\n case 'buffering':\n case 'current':\n case 'defined':\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 (warn) {\n const msg = `Unsupported pseudo-class :${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (warn) {\n const msg = `Unsupported pseudo-class :${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n const msg = `Unknown pseudo-class :${astName}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * match shadow host pseudo class\n * @private\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 const msg = `Invalid selector ${css}`;\n throw new DOMException(msg, 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 bool;\n let parent = host;\n while (parent) {\n for (const leaf of leaves) {\n const { type: leafType } = leaf;\n if (leafType === COMBINATOR) {\n const css = generateCSS(ast);\n const msg = `Invalid selector ${css}`;\n throw new DOMException(msg, 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 const msg = `Invalid selector :${astName}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n return res ?? null;\n }\n\n /**\n * match selector\n * @private\n * @param {object} ast - AST\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} [opt] - options\n * @returns {Set.} - collection of matched nodes\n */\n _matchSelector(ast, node, opt) {\n const { type: astType } = ast;\n const astName = unescapeSelector(ast.name);\n let matched = new Set();\n if (node.nodeType === ELEMENT_NODE) {\n switch (astType) {\n case SELECTOR_PSEUDO_ELEMENT: {\n matchPseudoElementSelector(astName, opt);\n break;\n }\n case SELECTOR_ID: {\n if (node.id === astName) {\n matched.add(node);\n }\n break;\n }\n case SELECTOR_CLASS: {\n if (node.classList.contains(astName)) {\n matched.add(node);\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 default: {\n const res = matchSelector(ast, node, opt);\n if (res) {\n matched.add(res);\n }\n }\n }\n } else if (this.#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, opt);\n if (res) {\n matched.add(res);\n }\n }\n }\n return matched;\n }\n\n /**\n * match leaves\n * @private\n * @param {Array.} 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 if (this.#results.has(leaves)) {\n const result = this.#results.get(leaves);\n if (result.has(node)) {\n bool = result.get(node);\n } else {\n for (const leaf of leaves) {\n bool = this._matchSelector(leaf, node, opt).has(node);\n if (!bool) {\n break;\n }\n }\n result.set(node, bool);\n this.#results.set(leaves, result);\n }\n } else {\n for (const leaf of leaves) {\n bool = this._matchSelector(leaf, node, opt).has(node);\n if (!bool) {\n break;\n }\n }\n const result = new WeakMap();\n result.set(node, bool);\n this.#results.set(leaves, result);\n }\n return !!bool;\n }\n\n /**\n * match HTML collection\n * @private\n * @param {object} items - HTML collection\n * @param {object} opt - options\n * @returns {Set.} - matched nodes\n */\n _matchHTMLCollection(items, opt = {}) {\n const { compound, filterLeaves } = opt;\n let nodes = new Set();\n const l = items.length;\n if (l) {\n if (compound) {\n for (let i = 0; i < l; i++) {\n const item = items[i];\n const bool = this._matchLeaves(filterLeaves, item, opt);\n if (bool) {\n nodes.add(item);\n }\n }\n } else {\n const arr = [].slice.call(items);\n nodes = new Set(arr);\n }\n }\n return nodes;\n }\n\n /**\n * find descendant nodes\n * @private\n * @param {Array.} leaves - AST leaves\n * @param {object} baseNode - base Element node\n * @param {object} opt - options\n * @returns {object} - collection of nodes and pending state\n */\n _findDescendantNodes(leaves, baseNode, opt) {\n const [leaf, ...filterLeaves] = leaves;\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n const compound = filterLeaves.length > 0;\n let nodes = new Set();\n let pending = false;\n if (this.#shadow) {\n pending = true;\n } else {\n switch (leafType) {\n case SELECTOR_PSEUDO_ELEMENT: {\n matchPseudoElementSelector(leafName, opt);\n break;\n }\n case SELECTOR_ID: {\n if (this.#root.nodeType === ELEMENT_NODE) {\n pending = true;\n } else {\n const node = this.#root.getElementById(leafName);\n if (node && node !== baseNode && baseNode.contains(node)) {\n if (compound) {\n const bool = this._matchLeaves(filterLeaves, node, opt);\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 items = baseNode.getElementsByClassName(leafName);\n nodes = this._matchHTMLCollection(items, {\n compound,\n filterLeaves\n });\n break;\n }\n case SELECTOR_TYPE: {\n if (this.#document.contentType === 'text/html' &&\n !/[*|]/.test(leafName)) {\n const items = baseNode.getElementsByTagName(leafName);\n nodes = this._matchHTMLCollection(items, {\n compound,\n filterLeaves\n });\n } else {\n pending = true;\n }\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 * @private\n * @param {object} twig - twig\n * @param {object} node - Element node\n * @param {object} opt - option\n * @returns {Set.} - collection of matched nodes\n */\n _matchCombinator(twig, node, opt = {}) {\n const { combo, leaves } = twig;\n const { name: comboName } = combo;\n const { dir } = opt;\n let matched = new Set();\n if (dir === DIR_NEXT) {\n switch (comboName) {\n case '+': {\n const refNode = node.nextElementSibling;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n const { parentNode } = node;\n if (parentNode) {\n const walker =\n this.#document.createTreeWalker(parentNode, SHOW_ELEMENT);\n let refNode = this._traverse(node, walker);\n if (refNode === node) {\n refNode = walker.nextSibling();\n }\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n refNode = walker.nextSibling();\n }\n }\n break;\n }\n case '>': {\n const walker = this.#document.createTreeWalker(node, SHOW_ELEMENT);\n let refNode = walker.firstChild();\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n refNode = walker.nextSibling();\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 walker = this.#document.createTreeWalker(node, SHOW_ELEMENT);\n let refNode = walker.nextNode();\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n refNode = walker.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, opt);\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case '~': {\n const walker =\n this.#document.createTreeWalker(node.parentNode, SHOW_ELEMENT);\n let refNode = walker.firstChild();\n while (refNode) {\n if (refNode === node) {\n break;\n } else {\n const bool = this._matchLeaves(leaves, refNode, opt);\n if (bool) {\n matched.add(refNode);\n }\n }\n refNode = walker.nextSibling();\n }\n break;\n }\n case '>': {\n const refNode = node.parentNode;\n if (refNode) {\n const bool = this._matchLeaves(leaves, refNode, opt);\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, opt);\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 matched node from finder\n * @private\n * @param {Array.} leaves - AST leaves\n * @param {object} [opt] - options\n * @param {object} [opt.node] - node to start from\n * @returns {?object} - matched node\n */\n _findNode(leaves, opt = {}) {\n const { node } = opt;\n let matchedNode;\n let refNode = this._traverse(node, this.#finder);\n if (refNode) {\n if (refNode.nodeType !== ELEMENT_NODE) {\n refNode = this.#finder.nextNode();\n } else if (refNode === node) {\n if (refNode !== this.#root) {\n refNode = this.#finder.nextNode();\n }\n }\n while (refNode) {\n let bool;\n if (this.#node.nodeType === ELEMENT_NODE) {\n if (refNode === this.#node) {\n bool = true;\n } else {\n bool = this.#node.contains(refNode);\n }\n } else {\n bool = true;\n }\n if (bool) {\n const matched = this._matchLeaves(leaves, refNode, {\n warn: this.#warn\n });\n if (matched) {\n matchedNode = refNode;\n break;\n }\n }\n refNode = this.#finder.nextNode();\n }\n }\n return matchedNode ?? null;\n }\n\n /**\n * match self\n * @private\n * @param {Array} leaves - AST leaves\n * @returns {Array} - [nodes, filtered]\n */\n _matchSelf(leaves) {\n const nodes = [];\n let filtered = false;\n const bool = this._matchLeaves(leaves, this.#node);\n if (bool) {\n nodes.push(this.#node);\n filtered = true;\n }\n return [nodes, filtered];\n }\n\n /**\n * find lineal\n * @private\n * @param {Array} leaf - AST leaf\n * @param {object} opt - options\n * @returns {Array} - [nodes, filtered]\n */\n _findLineal(leaf, opt = {}) {\n const { complex, compound, filterLeaves } = opt;\n const nodes = [];\n let filtered = false;\n let bool = this._matchLeaves([leaf], this.#node);\n if (bool && !complex) {\n if (compound) {\n bool = this._matchLeaves(filterLeaves, this.#node);\n if (bool) {\n nodes.push(this.#node);\n filtered = true;\n }\n } else {\n nodes.push(this.#node);\n filtered = true;\n }\n }\n if (!bool || complex) {\n if (bool) {\n nodes.push(this.#node);\n if (!compound) {\n filtered = true;\n }\n }\n let refNode = this.#node.parentNode;\n while (refNode) {\n bool = this._matchLeaves([leaf], refNode);\n if (bool) {\n nodes.push(refNode);\n if (!compound) {\n filtered = true;\n }\n }\n if (refNode.parentNode) {\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n }\n return [nodes, filtered];\n }\n\n /**\n * find first\n * @private\n * @param {Array} leaves - AST leaves\n * @returns {Array} - [nodes, filtered]\n */\n _findFirst(leaves) {\n const nodes = [];\n let filtered = false;\n const node = this._findNode(leaves, {\n node: this.#node\n });\n if (node) {\n nodes.push(node);\n filtered = true;\n }\n return [nodes, filtered];\n }\n\n /**\n * find from HTML collection\n * @private\n * @param {object} items - HTML collection\n * @param {object} opt - options\n * @param {boolean} [opt.compound] - compound selector\n * @param {Array} [opt.filterLeaves] - filter leaves\n * @returns {Array} - [nodes, filtered]\n */\n _findFromHTMLCollection(items, opt = {}) {\n const { compound, filterLeaves } = opt;\n let nodes = [];\n let filtered = false;\n const l = items.length;\n if (l) {\n if (this.#node.nodeType === ELEMENT_NODE) {\n for (let i = 0; i < l; i++) {\n const node = items[i];\n if (node === this.#node || isInclusive(node, this.#node)) {\n if (compound) {\n const bool = this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(node);\n filtered = true;\n }\n } else {\n nodes.push(node);\n filtered = true;\n }\n }\n }\n } else if (compound) {\n for (let i = 0; i < l; i++) {\n const node = items[i];\n const bool = this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(node);\n filtered = true;\n }\n }\n } else {\n nodes = [].slice.call(items);\n filtered = true;\n }\n }\n return [nodes, filtered];\n }\n\n /**\n * find entry nodes\n * @private\n * @param {object} twig - twig\n * @param {string} targetType - target type\n * @param {boolean} complex - complex selector\n * @returns {object} - collection of nodes etc.\n */\n _findEntryNodes(twig, targetType, complex) {\n const { leaves } = twig;\n const [leaf, ...filterLeaves] = leaves;\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n const compound = filterLeaves.length > 0;\n let nodes = [];\n let filtered = false;\n let pending = false;\n switch (leafType) {\n case SELECTOR_PSEUDO_ELEMENT: {\n matchPseudoElementSelector(leafName, {\n warn: this.#warn\n });\n break;\n }\n case SELECTOR_ID: {\n if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaf, {\n complex,\n compound,\n filterLeaves\n });\n } else if (targetType === TARGET_FIRST &&\n this.#root.nodeType !== ELEMENT_NODE) {\n const node = this.#root.getElementById(leafName);\n if (node) {\n if (compound) {\n const bool = this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.push(node);\n filtered = true;\n }\n } else {\n nodes.push(node);\n filtered = true;\n }\n }\n } else {\n pending = true;\n }\n break;\n }\n case SELECTOR_CLASS: {\n if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaf, {\n complex,\n compound,\n filterLeaves\n });\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else if (this.#root.nodeType === DOCUMENT_NODE) {\n const items = this.#root.getElementsByClassName(leafName);\n [nodes, filtered] = this._findFromHTMLCollection(items, {\n compound,\n filterLeaves\n });\n } else {\n pending = true;\n }\n break;\n }\n case SELECTOR_TYPE: {\n if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaf, {\n complex,\n compound,\n filterLeaves\n });\n } else if (this.#document.contentType === 'text/html' &&\n this.#root.nodeType === DOCUMENT_NODE &&\n !/[*|]/.test(leafName)) {\n const items = this.#root.getElementsByTagName(leafName);\n [nodes, filtered] = this._findFromHTMLCollection(items, {\n compound,\n filterLeaves\n });\n } else {\n pending = true;\n }\n break;\n }\n default: {\n if (targetType !== TARGET_LINEAL && REG_SHADOW_HOST.test(leafName)) {\n if (this.#shadow &&\n this.#node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const node = this._matchShadowHostPseudoClass(leaf, this.#node);\n if (node) {\n nodes.push(node);\n filtered = true;\n }\n }\n } else if (targetType === TARGET_SELF) {\n [nodes, filtered] = this._matchSelf(leaves);\n } else if (targetType === TARGET_LINEAL) {\n [nodes, filtered] = this._findLineal(leaf, {\n complex,\n compound,\n filterLeaves\n });\n } else if (targetType === TARGET_FIRST) {\n [nodes, filtered] = this._findFirst(leaves);\n } else {\n pending = true;\n }\n }\n }\n return {\n compound,\n filtered,\n nodes,\n pending\n };\n }\n\n /**\n * get entry twig\n * @private\n * @param {Array.} branch - AST branch\n * @param {string} targetType - target type\n * @returns {object} - direction and twig\n */\n _getEntryTwig(branch, targetType) {\n const branchLen = branch.length;\n const complex = branchLen > 1;\n const firstTwig = branch[0];\n let dir;\n let twig;\n if (complex) {\n const {\n combo: firstCombo,\n leaves: [{\n name: firstName,\n type: firstType\n }]\n } = firstTwig;\n const lastTwig = branch[branchLen - 1];\n const {\n leaves: [{\n name: lastName,\n type: lastType\n }]\n } = lastTwig;\n if (lastType === SELECTOR_PSEUDO_ELEMENT || lastType === SELECTOR_ID) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else if (firstType === SELECTOR_PSEUDO_ELEMENT ||\n firstType === SELECTOR_ID) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else if (targetType === TARGET_ALL) {\n if (firstName === '*' && firstType === SELECTOR_TYPE) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else if (lastName === '*' && lastType === SELECTOR_TYPE) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else if (branchLen === 2) {\n const { name: comboName } = firstCombo;\n if (/^[+~]$/.test(comboName)) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else {\n dir = DIR_NEXT;\n twig = firstTwig;\n }\n } else {\n dir = DIR_NEXT;\n twig = firstTwig;\n }\n } else if (lastName === '*' && lastType === SELECTOR_TYPE) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else if (firstName === '*' && firstType === SELECTOR_TYPE) {\n dir = DIR_PREV;\n twig = lastTwig;\n } else {\n let bool;\n let sibling;\n for (const { combo, leaves: [leaf] } of branch) {\n const { type: leafType } = leaf;\n const leafName = unescapeSelector(leaf.name);\n if (leafType === SELECTOR_PSEUDO_CLASS && leafName === 'dir') {\n bool = false;\n break;\n }\n if (combo && !sibling) {\n const { name: comboName } = combo;\n if (/^[+~]$/.test(comboName)) {\n bool = true;\n sibling = true;\n }\n }\n }\n if (bool) {\n dir = DIR_NEXT;\n twig = firstTwig;\n } else {\n dir = DIR_PREV;\n twig = lastTwig;\n }\n }\n } else {\n dir = DIR_PREV;\n twig = firstTwig;\n }\n return {\n complex,\n dir,\n twig\n };\n }\n\n /**\n * collect nodes\n * @private\n * @param {string} targetType - target type\n * @returns {Array.>} - #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 { complex, dir, twig } = this._getEntryTwig(branch, targetType);\n const {\n compound, filtered, nodes, pending\n } = this._findEntryNodes(twig, targetType, complex);\n if (nodes.length) {\n this.#ast[i].find = true;\n this.#nodes[i] = nodes;\n } else if (pending) {\n pendingItems.add(new Map([\n ['index', i],\n ['twig', twig]\n ]));\n }\n this.#ast[i].dir = dir;\n this.#ast[i].filtered = filtered || !compound;\n i++;\n }\n if (pendingItems.size) {\n let node;\n let walker;\n if (this.#node !== this.#root && this.#node.nodeType === ELEMENT_NODE) {\n node = this.#node;\n walker = this.#finder;\n } else {\n node = this.#root;\n walker = this.#tree;\n }\n let nextNode = this._traverse(node, walker);\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 warn: this.#warn\n });\n if (matched) {\n const index = pendingItem.get('index');\n this.#ast[index].filtered = true;\n this.#ast[index].find = true;\n this.#nodes[index].push(nextNode);\n }\n }\n }\n nextNode = walker.nextNode();\n }\n }\n } else {\n let i = 0;\n for (const { branch } of ast) {\n const twig = branch[branch.length - 1];\n const complex = branch.length > 1;\n const {\n compound, filtered, nodes\n } = this._findEntryNodes(twig, targetType, complex);\n if (nodes.length) {\n this.#ast[i].find = true;\n this.#nodes[i] = nodes;\n }\n this.#ast[i].dir = DIR_PREV;\n this.#ast[i].filtered = filtered || !compound;\n i++;\n }\n }\n return [\n this.#ast,\n this.#nodes\n ];\n }\n\n /**\n * match nodes\n * @private\n * @param {string} targetType - target type\n * @returns {Set.} - 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, dir, filtered, find } = branches[i];\n const branchLen = branch.length;\n if (branchLen && find) {\n const entryNodes = this.#nodes[i];\n const entryNodesLen = entryNodes.length;\n const lastIndex = branchLen - 1;\n if (lastIndex === 0) {\n const { leaves: [, ...filterLeaves] } = branch[0];\n if ((targetType === TARGET_ALL || targetType === TARGET_FIRST) &&\n this.#node.nodeType === ELEMENT_NODE) {\n for (let j = 0; j < entryNodesLen; j++) {\n const node = entryNodes[j];\n if (node !== this.#node && this.#node.contains(node)) {\n nodes.add(node);\n if (targetType !== TARGET_ALL) {\n break;\n }\n }\n }\n } else if (filterLeaves.length) {\n for (let j = 0; j < entryNodesLen; j++) {\n const node = entryNodes[j];\n const bool = filtered || this._matchLeaves(filterLeaves, node, {\n warn: this.#warn\n });\n if (bool) {\n nodes.add(node);\n if (targetType !== TARGET_ALL) {\n break;\n }\n }\n }\n } else if (targetType === TARGET_ALL) {\n if (nodes.size) {\n const n = [...nodes];\n nodes = new Set([...n, ...entryNodes]);\n this.#sort = true;\n } else {\n nodes = new Set([...entryNodes]);\n }\n } else {\n const [node] = [...entryNodes];\n nodes.add(node);\n }\n } else if (dir === DIR_NEXT) {\n let { combo, leaves: entryLeaves } = branch[0];\n let matched;\n for (let j = 0; j < entryNodesLen; j++) {\n const node = entryNodes[j];\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, {\n dir,\n warn: this.#warn\n });\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n if (j === lastIndex) {\n if (targetType === TARGET_ALL) {\n if (nodes.size) {\n const n = [...nodes];\n nodes = new Set([...n, ...arr]);\n } else {\n nodes = new Set([...arr]);\n }\n this.#sort = true;\n } else {\n const [node] = sortNodes(arr);\n nodes.add(node);\n }\n matched = true;\n } else {\n combo = nextCombo;\n nextNodes = new Set(arr);\n matched = false;\n }\n } else {\n matched = false;\n break;\n }\n }\n if (matched && targetType !== TARGET_ALL) {\n break;\n }\n }\n if (!matched && targetType === TARGET_FIRST) {\n const [entryNode] = [...entryNodes];\n let refNode = this._findNode(entryLeaves, {\n node: entryNode\n });\n while (refNode) {\n let nextNodes = new Set([refNode]);\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, {\n dir,\n warn: this.#warn\n });\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n if (j === lastIndex) {\n const [node] = sortNodes(arr);\n nodes.add(node);\n matched = true;\n } else {\n combo = nextCombo;\n nextNodes = new Set(arr);\n matched = false;\n }\n } else {\n matched = false;\n break;\n }\n }\n if (matched) {\n break;\n }\n refNode = this._findNode(entryLeaves, {\n node: refNode\n });\n nextNodes = new Set([refNode]);\n }\n }\n } else {\n const { leaves: entryLeaves } = branch[lastIndex];\n let matched;\n for (let j = 0; j < entryNodesLen; j++) {\n const node = entryNodes[j];\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 dir,\n warn: this.#warn\n });\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n if (j === 0) {\n nodes.add(node);\n matched = true;\n if (targetType === TARGET_ALL &&\n branchLen > 1 && nodes.size > 1) {\n this.#sort = true;\n }\n } else {\n nextNodes = new Set(arr);\n matched = false;\n }\n } else {\n matched = false;\n break;\n }\n }\n if (matched && targetType !== TARGET_ALL) {\n break;\n }\n }\n if (!matched && targetType === TARGET_FIRST) {\n const [entryNode] = [...entryNodes];\n let refNode = this._findNode(entryLeaves, {\n node: entryNode\n });\n while (refNode) {\n let nextNodes = new Set([refNode]);\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 dir,\n warn: this.#warn\n });\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n if (j === 0) {\n nodes.add(refNode);\n matched = true;\n } else {\n nextNodes = new Set(arr);\n matched = false;\n }\n } else {\n matched = false;\n break;\n }\n }\n if (matched) {\n break;\n }\n refNode = this._findNode(entryLeaves, {\n node: refNode\n });\n nextNodes = new Set([refNode]);\n }\n }\n }\n }\n }\n return nodes;\n }\n\n /**\n * find matched nodes\n * @private\n * @param {string} targetType - target type\n * @returns {Set.} - 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 * @param {string} selector - CSS selector\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {boolean} - `true` if matched `false` otherwise\n */\n matches(selector, node, opt) {\n let res;\n try {\n this.#node = this._setup(selector, node, opt);\n if (node.nodeType !== ELEMENT_NODE) {\n const msg = `Unexpected node ${node.nodeName}`;\n throw new TypeError(msg);\n }\n const nodes = this._find(TARGET_SELF);\n res = nodes.size;\n } catch (e) {\n this._onError(e);\n }\n return !!res;\n }\n\n /**\n * closest\n * @param {string} selector - CSS selector\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\n closest(selector, node, opt) {\n let res;\n try {\n this.#node = this._setup(selector, node, opt);\n if (node.nodeType !== ELEMENT_NODE) {\n const msg = `Unexpected node ${node.nodeName}`;\n throw new TypeError(msg);\n }\n const nodes = this._find(TARGET_LINEAL);\n if (nodes.size) {\n let refNode = this.#node;\n while (refNode) {\n if (nodes.has(refNode)) {\n res = refNode;\n break;\n }\n refNode = refNode.parentNode;\n }\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? null;\n }\n\n /**\n * query selector\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\n querySelector(selector, node, opt) {\n let res;\n try {\n this.#node = this._setup(selector, node, opt);\n this._prepareTreeWalkers(node);\n const nodes = this._find(TARGET_FIRST);\n nodes.delete(this.#node);\n if (nodes.size) {\n [res] = 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 * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} opt - options\n * @returns {Array.} - collection of matched nodes\n */\n querySelectorAll(selector, node, opt) {\n let res;\n try {\n this.#node = this._setup(selector, node, opt);\n this._prepareTreeWalkers(node);\n const nodes = this._find(TARGET_ALL);\n nodes.delete(this.#node);\n if (nodes.size) {\n if (this.#sort) {\n res = sortNodes(nodes);\n } else {\n res = [...nodes];\n }\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? [];\n }\n};\n"], + "mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,YAAAE,IAAA,eAAAC,EAAAH,GAKA,IAAAI,EAAgC,iDAChCC,EAGO,yBACPC,EAA0D,wBAC1DC,EAEO,uBAGPC,EAMO,yBACP,MAAMC,EAAW,OACXC,EAAW,OACXC,EAAa,MACbC,EAAe,QACfC,EAAgB,SAChBC,EAAc,OACdC,EAAgB,gBAAgB,yBAAyB,eAgCxD,MAAMb,CAAO,CAElBc,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GAKA,aAAc,CACZ,KAAKZ,GAAS,IAAI,OACpB,CASA,SAASa,EAAG,CACV,GAAI,CAAC,KAAKR,GACR,GAAIQ,aAAa,cACZ,KAAKD,IAAWC,aAAa,KAAKD,GAAQ,aAC7C,GAAIC,EAAE,OAAS,oBACT,KAAKF,IACP,QAAQ,KAAKE,EAAE,OAAO,MAEnB,OAAI,KAAKD,GACR,IAAI,KAAKA,GAAQ,aAAaC,EAAE,QAASA,EAAE,IAAI,EAE/CA,MAGR,OAAMA,CAGZ,CAYA,OAAOC,EAAUC,EAAMC,EAAM,CAAC,EAAG,CAC/B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AAUC,EAAMC,CAAG,EAC5C,KAAK,oBAAoBD,CAAI,EAC7B,MAAMI,EAAQ,KAAK,MAAMxB,CAAY,EACrCwB,EAAM,OAAO,KAAKhB,EAAK,EACnBgB,EAAM,OACR,CAACuC,CAAG,KAAI,aAAUvC,CAAK,EAE3B,OAASN,EAAG,CACV,KAAK,SAASA,CAAC,CACjB,CACA,OAAO6C,GAAO,IAChB,CAUA,iBAAiB5C,EAAUC,EAAMC,EAAK,CACpC,IAAI0C,EACJ,GAAI,CACF,KAAKvD,GAAQ,KAAK,OAAOW,EAAUC,EAAMC,CAAG,EAC5C,KAAK,oBAAoBD,CAAI,EAC7B,MAAMI,EAAQ,KAAK,MAAMzB,CAAU,EACnCyB,EAAM,OAAO,KAAKhB,EAAK,EACnBgB,EAAM,OACJ,KAAKV,GACPiD,KAAM,aAAUvC,CAAK,EAErBuC,EAAM,CAAC,GAAGvC,CAAK,EAGrB,OAASN,EAAG,CACV,KAAK,SAASA,CAAC,CACjB,CACA,OAAO6C,GAAO,CAAC,CACjB,CACF", "names": ["finder_exports", "__export", "Finder", "__toCommonJS", "import_is_potential_custom_element_name", "import_dom_util", "import_matcher", "import_parser", "import_constant", "DIR_NEXT", "DIR_PREV", "TARGET_ALL", "TARGET_FIRST", "TARGET_LINEAL", "TARGET_SELF", "WALKER_FILTER", "#ast", "#cache", "#document", "#finder", "#node", "#nodes", "#noexcept", "#results", "#root", "#shadow", "#sort", "#tree", "#warn", "#window", "e", "selector", "node", "opt", "noexcept", "warn", "nodes", "ast", "cachedItem", "l", "i", "cssAst", "branches", "items", "branch", "item", "leaves", "nextItem", "msg", "itemName", "walker", "current", "refNode", "anb", "a", "b", "reverse", "parentNode", "matched", "selectorBranches", "selectorNodes", "bool", "nth", "j", "m", "localName", "prefix", "itemLocalName", "itemPrefix", "nthName", "nthIdentName", "identName", "anbMap", "astName", "dir", "res", "parent", "langPart", "regExtendedLang", "langMain", "langSub", "langRest", "extendedMain", "extendedSub", "len", "extendedRest", "value", "leaf", "leafType", "combo", "twigLeaves", "itemType", "twig", "nextNode", "astData", "twigBranches", "forgive", "lastIndex", "nextNodes", "arr", "astChildren", "selectors", "css", "leavesSet", "regAnchor", "regFormCtrl", "regFormValidity", "regInteract", "regTypeCheck", "regTypeDate", "regTypeRange", "regTypeText", "href", "origin", "pathname", "attrURL", "hash", "id", "focus", "display", "visibility", "active", "isCustomElementName", "targetNode", "nodeName", "checked", "regTypeReset", "regTypeSubmit", "form", "isMultiple", "defaultOpt", "inputType", "node1", "node2", "host", "astType", "result", "compound", "filterLeaves", "baseNode", "leafName", "pending", "comboName", "matchedNode", "filtered", "complex", "targetType", "branchLen", "firstTwig", "firstCombo", "firstName", "firstType", "lastTwig", "lastName", "lastType", "sibling", "pendingItems", "pendingItem", "index", "find", "entryNodes", "entryNodesLen", "n", "entryLeaves", "nextCombo", "entryNode"] } diff --git a/dist/cjs/js/matcher.js b/dist/cjs/js/matcher.js index 3c82935f..ca95ff85 100644 --- a/dist/cjs/js/matcher.js +++ b/dist/cjs/js/matcher.js @@ -1,2 +1,2 @@ -var y=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var D=(t,e)=>{for(var f in e)y(t,f,{get:e[f],enumerable:!0})},v=(t,e,f,m)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of L(e))!S.call(t,o)&&o!==f&&y(t,o,{get:()=>e[o],enumerable:!(m=$(e,o))||m.enumerable});return t};var C=t=>v(y({},"__esModule",{value:!0}),t);var U={};D(U,{_matchAttributeSelector:()=>k,_matchTypeSelector:()=>O,matchPseudoElementSelector:()=>P,matchSelector:()=>N});module.exports=C(U);var T=require("./dom-util.js"),h=require("./parser.js"),i=require("./constant.js");const k=(t,e)=>{const{flags:f,matcher:m,name:o,value:w}=t;if(typeof f=="string"&&!/^[is]$/i.test(f)){const r=`Invalid selector ${(0,h.generateCSS)(t)}`;throw new DOMException(r,i.SYNTAX_ERR)}const{attributes:x}=e;let d;if(x&&x.length){const g=e.ownerDocument.contentType;let r;g==="text/html"?typeof f=="string"&&/^s$/i.test(f)?r=!1:r=!0:typeof f=="string"&&/^i$/i.test(f)?r=!0:r=!1;let u=(0,h.unescapeSelector)(o.name);r&&(u=u.toLowerCase());const n=new Set;if(u.indexOf("|")>-1){const{prefix:l,localName:p}=(0,h.parseAstName)(u);for(const s of x){let{name:a,value:c}=s;switch(r&&(a=a.toLowerCase(),c=c.toLowerCase()),l){case"":{p===a&&n.add(c);break}case"*":{a.indexOf(":")>-1?a.endsWith(`:${p}`)&&n.add(c):p===a&&n.add(c);break}default:if(a.indexOf(":")>-1){const[b,E]=a.split(":");if(b==="xml"&&E==="lang")continue;l===b&&p===E&&(0,T.isNamespaceDeclared)(l,e)&&n.add(c)}}}}else for(let{name:l,value:p}of x)if(r&&(l=l.toLowerCase(),p=p.toLowerCase()),l.indexOf(":")>-1){const[s,a]=l.split(":");if(s==="xml"&&a==="lang")continue;u===a&&n.add(p)}else u===l&&n.add(p);if(n.size){const{name:l,value:p}=w??{};let s;switch(l?r?s=l.toLowerCase():s=l:p?r?s=p.toLowerCase():s=p:p===""&&(s=p),m){case"=":{typeof s=="string"&&n.has(s)&&(d=e);break}case"~=":{if(s&&typeof s=="string"){for(const a of n)if(new Set(a.split(/\s+/)).has(s)){d=e;break}}break}case"|=":{if(s&&typeof s=="string"){let a;for(const c of n)if(c===s||c.startsWith(`${s}-`)){a=c;break}a&&(d=e)}break}case"^=":{if(s&&typeof s=="string"){let a;for(const c of n)if(c.startsWith(`${s}`)){a=c;break}a&&(d=e)}break}case"$=":{if(s&&typeof s=="string"){let a;for(const c of n)if(c.endsWith(`${s}`)){a=c;break}a&&(d=e)}break}case"*=":{if(s&&typeof s=="string"){let a;for(const c of n)if(c.includes(`${s}`)){a=c;break}a&&(d=e)}break}case null:default:d=e}}}return d??null},O=(t,e,f={})=>{const m=(0,h.unescapeSelector)(t.name),{localName:o,namespaceURI:w,prefix:x}=e,{forgive:d}=f;let{prefix:g,localName:r}=(0,h.parseAstName)(m,e);e.ownerDocument.contentType==="text/html"&&(g=g.toLowerCase(),r=r.toLowerCase());let u,n;o.indexOf(":")>-1?[u,n]=o.split(":"):(u=x||"",n=o);let l;switch(g){case"":{u===""&&w===null&&(r==="*"||r===n)&&(l=e);break}case"*":{(r==="*"||r===n)&&(l=e);break}default:if((0,T.isNamespaceDeclared)(g,e))g===u&&(r==="*"||r===n)&&(l=e);else if(!d){const s=`Undeclared namespace ${g}`;throw new DOMException(s,i.SYNTAX_ERR)}}return l??null},N=(t,e,f)=>{if(!t||!t.type){const w=`Unexpected node ${Object.prototype.toString.call(t).slice(i.TYPE_FROM,i.TYPE_TO)}`;throw new TypeError(w)}else if(!e||!e.nodeType){const w=`Unexpected node ${Object.prototype.toString.call(e).slice(i.TYPE_FROM,i.TYPE_TO)}`;throw new TypeError(w)}else if(e.nodeType!==i.ELEMENT_NODE){const o=`Unexpected node ${e.nodeName}`;throw new TypeError(o)}let m;switch(t.type){case i.SELECTOR_ATTR:{m=k(t,e);break}case i.SELECTOR_TYPE:default:m=O(t,e,f)}return m},P=(t,e={})=>{if(!t||typeof t!="string"){const w=`Unexpected type ${Object.prototype.toString.call(t).slice(i.TYPE_FROM,i.TYPE_TO)}`;throw new TypeError(w)}const{forgive:f,warn:m}=e;switch(t){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(m){const o=`Unsupported pseudo-element ::${t}`;throw new DOMException(o,i.NOT_SUPPORTED_ERR)}break}case"part":case"slotted":{if(m){const o=`Unsupported pseudo-element ::${t}()`;throw new DOMException(o,i.NOT_SUPPORTED_ERR)}break}default:if(t.startsWith("-webkit-")){if(m){const o=`Unsupported pseudo-element ::${t}`;throw new DOMException(o,i.NOT_SUPPORTED_ERR)}}else if(!f){const o=`Unknown pseudo-element ::${t}`;throw new DOMException(o,i.SYNTAX_ERR)}}};0&&(module.exports={_matchAttributeSelector,_matchTypeSelector,matchPseudoElementSelector,matchSelector}); +var y=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var D=(t,e)=>{for(var f in e)y(t,f,{get:e[f],enumerable:!0})},v=(t,e,f,m)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of L(e))!S.call(t,o)&&o!==f&&y(t,o,{get:()=>e[o],enumerable:!(m=$(e,o))||m.enumerable});return t};var C=t=>v(y({},"__esModule",{value:!0}),t);var U={};D(U,{_matchAttributeSelector:()=>k,_matchTypeSelector:()=>O,matchPseudoElementSelector:()=>P,matchSelector:()=>N});module.exports=C(U);var T=require("./dom-util.js"),h=require("./parser.js"),i=require("./constant.js");const k=(t,e)=>{const{flags:f,matcher:m,name:o,value:w}=t;if(typeof f=="string"&&!/^[is]$/i.test(f)){const r=`Invalid selector ${(0,h.generateCSS)(t)}`;throw new DOMException(r,i.SYNTAX_ERR)}const{attributes:x}=e;let d;if(x&&x.length){const g=e.ownerDocument.contentType;let r;g==="text/html"?typeof f=="string"&&/^s$/i.test(f)?r=!1:r=!0:typeof f=="string"&&/^i$/i.test(f)?r=!0:r=!1;let u=(0,h.unescapeSelector)(o.name);r&&(u=u.toLowerCase());const n=new Set;if(u.indexOf("|")>-1){const{prefix:l,localName:p}=(0,h.parseAstName)(u);for(const s of x){let{name:a,value:c}=s;switch(r&&(a=a.toLowerCase(),c=c.toLowerCase()),l){case"":{p===a&&n.add(c);break}case"*":{a.indexOf(":")>-1?a.endsWith(`:${p}`)&&n.add(c):p===a&&n.add(c);break}default:if(a.indexOf(":")>-1){const[b,E]=a.split(":");if(b==="xml"&&E==="lang")continue;l===b&&p===E&&(0,T.isNamespaceDeclared)(l,e)&&n.add(c)}}}}else for(let{name:l,value:p}of x)if(r&&(l=l.toLowerCase(),p=p.toLowerCase()),l.indexOf(":")>-1){const[s,a]=l.split(":");if(s==="xml"&&a==="lang")continue;u===a&&n.add(p)}else u===l&&n.add(p);if(n.size){const{name:l,value:p}=w??{};let s;switch(l?r?s=l.toLowerCase():s=l:p?r?s=p.toLowerCase():s=p:p===""&&(s=p),m){case"=":{typeof s=="string"&&n.has(s)&&(d=e);break}case"~=":{if(s&&typeof s=="string"){for(const a of n)if(new Set(a.split(/\s+/)).has(s)){d=e;break}}break}case"|=":{if(s&&typeof s=="string"){let a;for(const c of n)if(c===s||c.startsWith(`${s}-`)){a=c;break}a&&(d=e)}break}case"^=":{if(s&&typeof s=="string"){let a;for(const c of n)if(c.startsWith(`${s}`)){a=c;break}a&&(d=e)}break}case"$=":{if(s&&typeof s=="string"){let a;for(const c of n)if(c.endsWith(`${s}`)){a=c;break}a&&(d=e)}break}case"*=":{if(s&&typeof s=="string"){let a;for(const c of n)if(c.includes(`${s}`)){a=c;break}a&&(d=e)}break}case null:default:d=e}}}return d??null},O=(t,e,f={})=>{const m=(0,h.unescapeSelector)(t.name),{localName:o,namespaceURI:w,prefix:x}=e,{forgive:d}=f;let{prefix:g,localName:r}=(0,h.parseAstName)(m,e);e.ownerDocument.contentType==="text/html"&&(g=g.toLowerCase(),r=r.toLowerCase());let u,n;o.indexOf(":")>-1?[u,n]=o.split(":"):(u=x||"",n=o);let l;switch(g){case"":{!u&&!w&&(r==="*"||r===n)&&(l=e);break}case"*":{(r==="*"||r===n)&&(l=e);break}default:if(g===u){if((0,T.isNamespaceDeclared)(g,e))(r==="*"||r===n)&&(l=e);else if(!d){const s=`Undeclared namespace ${g}`;throw new DOMException(s,i.SYNTAX_ERR)}}}return l??null},N=(t,e,f)=>{if(!t||!t.type){const w=`Unexpected node ${Object.prototype.toString.call(t).slice(i.TYPE_FROM,i.TYPE_TO)}`;throw new TypeError(w)}else if(!e||!e.nodeType){const w=`Unexpected node ${Object.prototype.toString.call(e).slice(i.TYPE_FROM,i.TYPE_TO)}`;throw new TypeError(w)}else if(e.nodeType!==i.ELEMENT_NODE){const o=`Unexpected node ${e.nodeName}`;throw new TypeError(o)}let m;switch(t.type){case i.SELECTOR_ATTR:{m=k(t,e);break}case i.SELECTOR_TYPE:default:m=O(t,e,f)}return m},P=(t,e={})=>{if(!t||typeof t!="string"){const w=`Unexpected type ${Object.prototype.toString.call(t).slice(i.TYPE_FROM,i.TYPE_TO)}`;throw new TypeError(w)}const{forgive:f,warn:m}=e;switch(t){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(m){const o=`Unsupported pseudo-element ::${t}`;throw new DOMException(o,i.NOT_SUPPORTED_ERR)}break}case"part":case"slotted":{if(m){const o=`Unsupported pseudo-element ::${t}()`;throw new DOMException(o,i.NOT_SUPPORTED_ERR)}break}default:if(t.startsWith("-webkit-")){if(m){const o=`Unsupported pseudo-element ::${t}`;throw new DOMException(o,i.NOT_SUPPORTED_ERR)}}else if(!f){const o=`Unknown pseudo-element ::${t}`;throw new DOMException(o,i.SYNTAX_ERR)}}};0&&(module.exports={_matchAttributeSelector,_matchTypeSelector,matchPseudoElementSelector,matchSelector}); //# sourceMappingURL=matcher.js.map diff --git a/dist/cjs/js/matcher.js.map b/dist/cjs/js/matcher.js.map index 0334df47..afbbb274 100644 --- a/dist/cjs/js/matcher.js.map +++ b/dist/cjs/js/matcher.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../../../src/js/matcher.js"], - "sourcesContent": ["/**\n * matcher.js\n * NOTE: Pseudo-class selector matching is done within `./finder.js`.\n * Functions that begin with `_` are not intended for general use,\n * and are exported for testing purposes only.\n */\n\n/* import */\nimport { isNamespaceDeclared } from './dom-util.js';\nimport { generateCSS, parseAstName, unescapeSelector } from './parser.js';\n\n/* constants */\nimport {\n ELEMENT_NODE, NOT_SUPPORTED_ERR, SELECTOR_ATTR, SELECTOR_TYPE, SYNTAX_ERR,\n TYPE_FROM, TYPE_TO\n} from './constant.js';\n\n/**\n * match attribute selector\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node or structured clone\n * @returns {?object} - matched node\n */\nexport const _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 const msg = `Invalid selector ${css}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n const { attributes } = node;\n let res;\n if (attributes && attributes.length) {\n const contentType = node.ownerDocument.contentType;\n let caseInsensitive;\n if (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: astPrefix, localName: astLocalName\n } = parseAstName(astAttrName);\n for (const item of attributes) {\n let { name: itemName, value: itemValue } = item;\n if (caseInsensitive) {\n itemName = itemName.toLowerCase();\n itemValue = itemValue.toLowerCase();\n }\n switch (astPrefix) {\n case '': {\n if (astLocalName === itemName) {\n attrValues.add(itemValue);\n }\n break;\n }\n case '*': {\n if (itemName.indexOf(':') > -1) {\n if (itemName.endsWith(`:${astLocalName}`)) {\n attrValues.add(itemValue);\n }\n } else if (astLocalName === itemName) {\n attrValues.add(itemValue);\n }\n break;\n }\n default: {\n if (itemName.indexOf(':') > -1) {\n const [itemPrefix, itemLocalName] = itemName.split(':');\n // ignore xml:lang\n if (itemPrefix === 'xml' && itemLocalName === 'lang') {\n continue;\n } else if (astPrefix === itemPrefix &&\n astLocalName === itemLocalName) {\n const namespaceDeclared = isNamespaceDeclared(astPrefix, node);\n if (namespaceDeclared) {\n attrValues.add(itemValue);\n }\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 [itemPrefix, itemLocalName] = itemName.split(':');\n // ignore xml:lang\n if (itemPrefix === 'xml' && itemLocalName === 'lang') {\n continue;\n } else if (astAttrName === itemLocalName) {\n attrValues.add(itemValue);\n }\n } else if (astAttrName === itemName) {\n attrValues.add(itemValue);\n }\n }\n }\n if (attrValues.size) {\n const { name: astIdentValue, value: astStringValue } = astValue ?? {};\n let attrValue;\n if (astIdentValue) {\n if (caseInsensitive) {\n attrValue = astIdentValue.toLowerCase();\n } else {\n attrValue = astIdentValue;\n }\n } else if (astStringValue) {\n if (caseInsensitive) {\n attrValue = astStringValue.toLowerCase();\n } else {\n attrValue = astStringValue;\n }\n } else if (astStringValue === '') {\n attrValue = astStringValue;\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 type selector\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node or structured clone\n * @param {object} opt - options\n * @param {boolean} [opt.forgive] - forgive undeclared namespace\n * @returns {?object} - matched node\n */\nexport const _matchTypeSelector = (ast, node, opt = {}) => {\n const astName = unescapeSelector(ast.name);\n const { localName, namespaceURI, prefix } = node;\n const { forgive } = opt;\n let {\n prefix: astPrefix, localName: astLocalName\n } = parseAstName(astName, node);\n if (node.ownerDocument.contentType === 'text/html') {\n astPrefix = astPrefix.toLowerCase();\n astLocalName = astLocalName.toLowerCase();\n }\n let nodePrefix;\n let nodeLocalName;\n // just in case that the namespaced content is parsed as text/html\n if (localName.indexOf(':') > -1) {\n [nodePrefix, nodeLocalName] = localName.split(':');\n } else {\n nodePrefix = prefix || '';\n nodeLocalName = localName;\n }\n let res;\n switch (astPrefix) {\n case '': {\n if (nodePrefix === '' && namespaceURI === null &&\n (astLocalName === '*' || astLocalName === nodeLocalName)) {\n res = node;\n }\n break;\n }\n case '*': {\n if (astLocalName === '*' || astLocalName === nodeLocalName) {\n res = node;\n }\n break;\n }\n default: {\n const namespaceDeclared = isNamespaceDeclared(astPrefix, node);\n if (namespaceDeclared) {\n if (astPrefix === nodePrefix &&\n (astLocalName === '*' || astLocalName === nodeLocalName)) {\n res = node;\n }\n } else if (!forgive) {\n const msg = `Undeclared namespace ${astPrefix}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n }\n }\n return res ?? null;\n};\n\n/**\n * match selector\n * @param {object} ast - AST\n * @param {object} node - Element node or structured clone\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\nexport const matchSelector = (ast, node, opt) => {\n if (!ast || !ast.type) {\n const nodeType =\n Object.prototype.toString.call(ast).slice(TYPE_FROM, TYPE_TO);\n const msg = `Unexpected node ${nodeType}`;\n throw new TypeError(msg);\n } else if (!node || !node.nodeType) {\n const nodeType =\n Object.prototype.toString.call(node).slice(TYPE_FROM, TYPE_TO);\n const msg = `Unexpected node ${nodeType}`;\n throw new TypeError(msg);\n } else if (node.nodeType !== ELEMENT_NODE) {\n const msg = `Unexpected node ${node.nodeName}`;\n throw new TypeError(msg);\n }\n let matched;\n switch (ast.type) {\n case SELECTOR_ATTR: {\n matched = _matchAttributeSelector(ast, node);\n break;\n }\n case SELECTOR_TYPE:\n default: {\n matched = _matchTypeSelector(ast, node, opt);\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] - forgive unknown pseudo-element\n * @param {boolean} [opt.warn] - warn unsupported pseudo-element\n * @throws {DOMException}\n * @returns {void}\n */\nexport const matchPseudoElementSelector = (astName, opt = {}) => {\n if (!astName || typeof astName !== 'string') {\n const nodeType =\n Object.prototype.toString.call(astName).slice(TYPE_FROM, TYPE_TO);\n const msg = `Unexpected type ${nodeType}`;\n throw new TypeError(msg);\n }\n const { forgive, warn } = 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 (warn) {\n const msg = `Unsupported pseudo-element ::${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n case 'part':\n case 'slotted': {\n if (warn) {\n const msg = `Unsupported pseudo-element ::${astName}()`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (warn) {\n const msg = `Unsupported pseudo-element ::${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n const msg = `Unknown pseudo-element ::${astName}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n }\n }\n};\n"], - "mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAA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,CAE/C,CACA,OAAOO,CACT,EAWarC,EAA6B,CAACU,EAASoB,EAAM,CAAC,IAAM,CAC/D,GAAI,CAACpB,GAAW,OAAOA,GAAY,SAAU,CAG3C,MAAME,EAAM,mBADV,OAAO,UAAU,SAAS,KAAKF,CAAO,EAAE,MAAM,YAAW,SAAO,CAC3B,GACvC,MAAM,IAAI,UAAUE,CAAG,CACzB,CACA,KAAM,CAAE,QAAAsB,EAAS,KAAAI,CAAK,EAAIR,EAC1B,OAAQpB,EAAS,CACf,IAAK,QACL,IAAK,WACL,IAAK,SACL,IAAK,MACL,IAAK,aACL,IAAK,eACL,IAAK,aACL,IAAK,uBACL,IAAK,SACL,IAAK,cACL,IAAK,YACL,IAAK,cAAe,CAClB,GAAI4B,EAAM,CACR,MAAM1B,EAAM,gCAAgCF,CAAO,GACnD,MAAM,IAAI,aAAaE,EAAK,mBAAiB,CAC/C,CACA,KACF,CACA,IAAK,OACL,IAAK,UAAW,CACd,GAAI0B,EAAM,CACR,MAAM1B,EAAM,gCAAgCF,CAAO,KACnD,MAAM,IAAI,aAAaE,EAAK,mBAAiB,CAC/C,CACA,KACF,CACA,QACE,GAAIF,EAAQ,WAAW,UAAU,GAC/B,GAAI4B,EAAM,CACR,MAAM1B,EAAM,gCAAgCF,CAAO,GACnD,MAAM,IAAI,aAAaE,EAAK,mBAAiB,CAC/C,UACS,CAACsB,EAAS,CACnB,MAAMtB,EAAM,4BAA4BF,CAAO,GAC/C,MAAM,IAAI,aAAaE,EAAK,YAAU,CACxC,CAEJ,CACF", + "sourcesContent": ["/**\n * matcher.js\n * NOTE: Pseudo-class selector matching is done within `./finder.js`.\n * Functions that begin with `_` are not intended for general use,\n * and are exported for testing purposes only.\n */\n\n/* import */\nimport { isNamespaceDeclared } from './dom-util.js';\nimport { generateCSS, parseAstName, unescapeSelector } from './parser.js';\n\n/* constants */\nimport {\n ELEMENT_NODE, NOT_SUPPORTED_ERR, SELECTOR_ATTR, SELECTOR_TYPE, SYNTAX_ERR,\n TYPE_FROM, TYPE_TO\n} from './constant.js';\n\n/**\n * match attribute selector\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node or structured clone\n * @returns {?object} - matched node\n */\nexport const _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 const msg = `Invalid selector ${css}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n const { attributes } = node;\n let res;\n if (attributes && attributes.length) {\n const contentType = node.ownerDocument.contentType;\n let caseInsensitive;\n if (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: astPrefix, localName: astLocalName\n } = parseAstName(astAttrName);\n for (const item of attributes) {\n let { name: itemName, value: itemValue } = item;\n if (caseInsensitive) {\n itemName = itemName.toLowerCase();\n itemValue = itemValue.toLowerCase();\n }\n switch (astPrefix) {\n case '': {\n if (astLocalName === itemName) {\n attrValues.add(itemValue);\n }\n break;\n }\n case '*': {\n if (itemName.indexOf(':') > -1) {\n if (itemName.endsWith(`:${astLocalName}`)) {\n attrValues.add(itemValue);\n }\n } else if (astLocalName === itemName) {\n attrValues.add(itemValue);\n }\n break;\n }\n default: {\n if (itemName.indexOf(':') > -1) {\n const [itemPrefix, itemLocalName] = itemName.split(':');\n // ignore xml:lang\n if (itemPrefix === 'xml' && itemLocalName === 'lang') {\n continue;\n } else if (astPrefix === itemPrefix &&\n astLocalName === itemLocalName) {\n const namespaceDeclared = isNamespaceDeclared(astPrefix, node);\n if (namespaceDeclared) {\n attrValues.add(itemValue);\n }\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 [itemPrefix, itemLocalName] = itemName.split(':');\n // ignore xml:lang\n if (itemPrefix === 'xml' && itemLocalName === 'lang') {\n continue;\n } else if (astAttrName === itemLocalName) {\n attrValues.add(itemValue);\n }\n } else if (astAttrName === itemName) {\n attrValues.add(itemValue);\n }\n }\n }\n if (attrValues.size) {\n const { name: astIdentValue, value: astStringValue } = astValue ?? {};\n let attrValue;\n if (astIdentValue) {\n if (caseInsensitive) {\n attrValue = astIdentValue.toLowerCase();\n } else {\n attrValue = astIdentValue;\n }\n } else if (astStringValue) {\n if (caseInsensitive) {\n attrValue = astStringValue.toLowerCase();\n } else {\n attrValue = astStringValue;\n }\n } else if (astStringValue === '') {\n attrValue = astStringValue;\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 type selector\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node or structured clone\n * @param {object} opt - options\n * @param {boolean} [opt.forgive] - forgive undeclared namespace\n * @returns {?object} - matched node\n */\nexport const _matchTypeSelector = (ast, node, opt = {}) => {\n const astName = unescapeSelector(ast.name);\n const { localName, namespaceURI, prefix } = node;\n const { forgive } = opt;\n let {\n prefix: astPrefix, localName: astLocalName\n } = parseAstName(astName, node);\n if (node.ownerDocument.contentType === 'text/html') {\n astPrefix = astPrefix.toLowerCase();\n astLocalName = astLocalName.toLowerCase();\n }\n let nodePrefix;\n let nodeLocalName;\n // just in case that the namespaced content is parsed as text/html\n if (localName.indexOf(':') > -1) {\n [nodePrefix, nodeLocalName] = localName.split(':');\n } else {\n nodePrefix = prefix || '';\n nodeLocalName = localName;\n }\n let res;\n switch (astPrefix) {\n case '': {\n if (!nodePrefix && !namespaceURI &&\n (astLocalName === '*' || astLocalName === nodeLocalName)) {\n res = node;\n }\n break;\n }\n case '*': {\n if (astLocalName === '*' || astLocalName === nodeLocalName) {\n res = node;\n }\n break;\n }\n default: {\n if (astPrefix === nodePrefix) {\n const namespaceDeclared = isNamespaceDeclared(astPrefix, node);\n if (namespaceDeclared) {\n if (astLocalName === '*' || astLocalName === nodeLocalName) {\n res = node;\n }\n } else if (!forgive) {\n const msg = `Undeclared namespace ${astPrefix}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n }\n }\n }\n return res ?? null;\n};\n\n/**\n * match selector\n * @param {object} ast - AST\n * @param {object} node - Element node or structured clone\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\nexport const matchSelector = (ast, node, opt) => {\n if (!ast || !ast.type) {\n const nodeType =\n Object.prototype.toString.call(ast).slice(TYPE_FROM, TYPE_TO);\n const msg = `Unexpected node ${nodeType}`;\n throw new TypeError(msg);\n } else if (!node || !node.nodeType) {\n const nodeType =\n Object.prototype.toString.call(node).slice(TYPE_FROM, TYPE_TO);\n const msg = `Unexpected node ${nodeType}`;\n throw new TypeError(msg);\n } else if (node.nodeType !== ELEMENT_NODE) {\n const msg = `Unexpected node ${node.nodeName}`;\n throw new TypeError(msg);\n }\n let matched;\n switch (ast.type) {\n case SELECTOR_ATTR: {\n matched = _matchAttributeSelector(ast, node);\n break;\n }\n case SELECTOR_TYPE:\n default: {\n matched = _matchTypeSelector(ast, node, opt);\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] - forgive unknown pseudo-element\n * @param {boolean} [opt.warn] - warn unsupported pseudo-element\n * @throws {DOMException}\n * @returns {void}\n */\nexport const matchPseudoElementSelector = (astName, opt = {}) => {\n if (!astName || typeof astName !== 'string') {\n const nodeType =\n Object.prototype.toString.call(astName).slice(TYPE_FROM, TYPE_TO);\n const msg = `Unexpected type ${nodeType}`;\n throw new TypeError(msg);\n }\n const { forgive, warn } = 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 (warn) {\n const msg = `Unsupported pseudo-element ::${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n case 'part':\n case 'slotted': {\n if (warn) {\n const msg = `Unsupported pseudo-element ::${astName}()`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (warn) {\n const msg = `Unsupported pseudo-element ::${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n const msg = `Unknown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B+B,EAAUvC,EAAwBQ,EAAKC,CAAI,EAC3C,KACF,CACA,KAAK,gBACL,QACE8B,EAAUtC,EAAmBO,EAAKC,EAAMuB,CAAG,CAE/C,CACA,OAAOO,CACT,EAWarC,EAA6B,CAACU,EAASoB,EAAM,CAAC,IAAM,CAC/D,GAAI,CAACpB,GAAW,OAAOA,GAAY,SAAU,CAG3C,MAAME,EAAM,mBADV,OAAO,UAAU,SAAS,KAAKF,CAAO,EAAE,MAAM,YAAW,SAAO,CAC3B,GACvC,MAAM,IAAI,UAAUE,CAAG,CACzB,CACA,KAAM,CAAE,QAAAsB,EAAS,KAAAI,CAAK,EAAIR,EAC1B,OAAQpB,EAAS,CACf,IAAK,QACL,IAAK,WACL,IAAK,SACL,IAAK,MACL,IAAK,aACL,IAAK,eACL,IAAK,aACL,IAAK,uBACL,IAAK,SACL,IAAK,cACL,IAAK,YACL,IAAK,cAAe,CAClB,GAAI4B,EAAM,CACR,MAAM1B,EAAM,gCAAgCF,CAAO,GACnD,MAAM,IAAI,aAAaE,EAAK,mBAAiB,CAC/C,CACA,KACF,CACA,IAAK,OACL,IAAK,UAAW,CACd,GAAI0B,EAAM,CACR,MAAM1B,EAAM,gCAAgCF,CAAO,KACnD,MAAM,IAAI,aAAaE,EAAK,mBAAiB,CAC/C,CACA,KACF,CACA,QACE,GAAIF,EAAQ,WAAW,UAAU,GAC/B,GAAI4B,EAAM,CACR,MAAM1B,EAAM,gCAAgCF,CAAO,GACnD,MAAM,IAAI,aAAaE,EAAK,mBAAiB,CAC/C,UACS,CAACsB,EAAS,CACnB,MAAMtB,EAAM,4BAA4BF,CAAO,GAC/C,MAAM,IAAI,aAAaE,EAAK,YAAU,CACxC,CAEJ,CACF", "names": ["matcher_exports", "__export", "_matchAttributeSelector", "_matchTypeSelector", "matchPseudoElementSelector", "matchSelector", "__toCommonJS", "import_dom_util", "import_parser", "import_constant", "ast", "node", "astFlags", "astMatcher", "astName", "astValue", "msg", "attributes", "res", "contentType", "caseInsensitive", "astAttrName", "attrValues", "astPrefix", "astLocalName", "item", "itemName", "itemValue", "itemPrefix", "itemLocalName", "astIdentValue", "astStringValue", "attrValue", "value", "opt", "localName", "namespaceURI", "prefix", "forgive", "nodePrefix", "nodeLocalName", "matched", "warn"] } diff --git a/package.json b/package.json index 29fc4bdb..cab17f0f 100644 --- a/package.json +++ b/package.json @@ -59,5 +59,5 @@ "tsc": "npx tsc", "update-wpt": "git submodule update --init --recursive --remote" }, - "version": "3.0.4" + "version": "3.0.5" }