@asamuzakjp/dom-selector 2.0.3-a.1 → 2.0.3-a.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/index.js.map +3 -3
- package/dist/cjs/js/constant.js +1 -1
- package/dist/cjs/js/constant.js.map +3 -3
- package/dist/cjs/js/dom-util.js +1 -1
- package/dist/cjs/js/dom-util.js.map +3 -3
- package/dist/cjs/js/finder.js +2 -0
- package/dist/cjs/js/finder.js.map +7 -0
- package/dist/cjs/js/matcher.js +1 -1
- package/dist/cjs/js/matcher.js.map +3 -3
- package/dist/cjs/js/parser.js +2 -2
- package/dist/cjs/js/parser.js.map +3 -3
- package/package.json +1 -1
- package/src/index.js +19 -19
- package/src/js/constant.js +1 -1
- package/src/js/dom-util.js +71 -21
- package/src/js/finder.js +2722 -0
- package/src/js/matcher.js +339 -3055
- package/src/js/parser.js +65 -4
- package/types/index.d.ts +3 -3
- package/types/js/constant.d.ts +1 -1
- package/types/js/dom-util.d.ts +2 -1
- package/types/js/finder.d.ts +30 -0
- package/types/js/matcher.d.ts +11 -57
- package/types/js/parser.d.ts +2 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/js/matcher.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * matcher.js\n */\n\n/* import */\nimport isCustomElementName from 'is-potential-custom-element-name';\nimport {\n getDirectionality, isContentEditable, isInclusive, isInShadowTree,\n isNamespaceDeclared, isPreceding, selectorToNodeProps\n} from './dom-util.js';\nimport {\n generateCSS, parseSelector, unescapeSelector, walkAST\n} from './parser.js';\n\n/* constants */\nimport {\n ALPHA_NUM, BIT_01, BIT_02, BIT_04, BIT_08, BIT_16, BIT_32, COMBINATOR,\n DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, ELEMENT_NODE, NOT_SUPPORTED_ERR,\n REG_LOGICAL_PSEUDO, REG_SHADOW_HOST, SELECTOR_ATTR, SELECTOR_CLASS,\n SELECTOR_ID, SELECTOR_PSEUDO_CLASS, SELECTOR_PSEUDO_ELEMENT, SELECTOR_TYPE,\n SHOW_ALL, SHOW_DOCUMENT, SHOW_DOCUMENT_FRAGMENT, SHOW_ELEMENT, SYNTAX_ERR,\n TEXT_NODE, TYPE_FROM, TYPE_TO\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 * Matcher\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 * Set([node{}, node{}]),\n * Set([node{}, node{}, node{}])\n * ]\n * branch[]: [twig{}, twig{}]\n * twig{}: {\n * combo: leaf{}|null,\n * leaves: leaves[]\n * }\n * leaves[]: [leaf{}, leaf{}, leaf{}]\n * leaf{}: CSSTree AST object\n * node{}: Element node\n */\nexport class Matcher {\n /* private fields */\n #ast;\n #bit;\n #cache;\n #document;\n #finder;\n #node;\n #nodes;\n #root;\n #selector;\n #shadow;\n #sort;\n #tree;\n #warn;\n #window;\n\n /**\n * construct\n */\n constructor() {\n this.#bit = new Map([\n [SELECTOR_PSEUDO_ELEMENT, BIT_01],\n [SELECTOR_ID, BIT_02],\n [SELECTOR_CLASS, BIT_04],\n [SELECTOR_TYPE, BIT_08],\n [SELECTOR_ATTR, BIT_16],\n [SELECTOR_PSEUDO_CLASS, BIT_32]\n ]);\n this.#cache = new WeakMap();\n }\n\n /**\n * handle error\n * @param {Error} e - Error\n * @throws Error\n * @returns {void}\n */\n _onError(e) {\n if (e instanceof DOMException ||\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 * set up #window, #document, #root\n * @param {object} node - Document, DocumentFragment, Element node\n * @returns {Array.<object>} - array of #window, #document, #root\n */\n _setup(node) {\n let document;\n let root;\n switch (node?.nodeType) {\n case DOCUMENT_NODE: {\n document = node;\n root = node;\n break;\n }\n case DOCUMENT_FRAGMENT_NODE: {\n document = node.ownerDocument;\n root = node;\n break;\n }\n case ELEMENT_NODE: {\n if (node.ownerDocument.contains(node)) {\n document = node.ownerDocument;\n root = node.ownerDocument;\n } else {\n let parent = node;\n while (parent) {\n if (parent.parentNode) {\n parent = parent.parentNode;\n } else {\n break;\n }\n }\n if (parent.nodeType === DOCUMENT_NODE) {\n document = parent;\n } else {\n document = parent.ownerDocument;\n }\n root = parent;\n }\n break;\n }\n default: {\n let msg;\n if (node?.nodeName) {\n msg = `Unexpected node ${node.nodeName}`;\n } else {\n const nodeType =\n Object.prototype.toString.call(node).slice(TYPE_FROM, TYPE_TO);\n msg = `Unexpected node ${nodeType}`;\n }\n throw new TypeError(msg);\n }\n }\n const window = document.defaultView;\n return [\n window,\n document,\n root\n ];\n }\n\n /**\n * sort AST leaves\n * @param {Array.<object>} leaves - collection of AST leaves\n * @returns {Array.<object>} - sorted leaves\n */\n _sortLeaves(leaves) {\n const arr = [...leaves];\n if (arr.length > 1) {\n arr.sort((a, b) => {\n const { type: typeA } = a;\n const { type: typeB } = b;\n const bitA = this.#bit.get(typeA);\n const bitB = this.#bit.get(typeB);\n let res;\n if (bitA === bitB) {\n res = 0;\n } else if (bitA > bitB) {\n res = 1;\n } else {\n res = -1;\n }\n return res;\n });\n }\n return arr;\n }\n\n /**\n * correspond #ast and #nodes\n * @param {string} selector - CSS selector\n * @returns {Array.<Array.<object|undefined>>} - 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 if (typeof ast === 'string') {\n throw new DOMException(ast, SYNTAX_ERR);\n }\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] = new Set();\n }\n } else {\n let cssAst;\n try {\n cssAst = parseSelector(selector);\n } catch (e) {\n if (this.#document) {\n if (!cachedItem) {\n cachedItem = new Map();\n }\n cachedItem.set(`${selector}`, e.message);\n this.#cache.set(this.#document, cachedItem);\n }\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 if (this.#document) {\n if (!cachedItem) {\n cachedItem = new Map();\n }\n cachedItem.set(`${selector}`, msg);\n this.#cache.set(this.#document, cachedItem);\n }\n throw new DOMException(msg, SYNTAX_ERR);\n }\n branch.push({\n combo: item,\n leaves: this._sortLeaves(leaves)\n });\n leaves.clear();\n } else if (item) {\n leaves.add(item);\n }\n if (items.length) {\n item = items.shift();\n } else {\n branch.push({\n combo: null,\n leaves: this._sortLeaves(leaves)\n });\n leaves.clear();\n break;\n }\n }\n }\n ast.push({\n branch,\n dir: null,\n filtered: false,\n find: false\n });\n nodes[i] = new Set();\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 * traverse tree walker\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 * @param {object} anb - An+B options\n * @param {number} anb.a - a\n * @param {number} anb.b - b\n * @param {boolean} [anb.reverse] - reverse order\n * @param {object} [anb.selector] - AST\n * @param {object} node - Element node\n * @returns {Set.<object>} - collection of matched nodes\n */\n _collectNthChild(anb, node) {\n const { a, b, reverse, selector } = anb;\n const { parentNode } = node;\n 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);\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 && this.#root.nodeType === ELEMENT_NODE &&\n (a + b) === 1) {\n if (selectorBranches) {\n let bool;\n for (const leaves of selectorBranches) {\n bool = this._matchLeaves(leaves, node);\n if (bool) {\n break;\n }\n }\n if (bool) {\n matched.add(node);\n }\n } else {\n matched.add(node);\n }\n }\n return matched;\n }\n\n /**\n * collect nth of type\n * @param {object} anb - An+B options\n * @param {number} anb.a - a\n * @param {number} anb.b - b\n * @param {boolean} [anb.reverse] - reverse order\n * @param {object} node - Element node\n * @returns {Set.<object>} - collection of matched nodes\n */\n _collectNthOfType(anb, node) {\n const { a, b, reverse } = anb;\n const { localName, parentNode, prefix } = node;\n 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 && this.#root.nodeType === ELEMENT_NODE &&\n (a + b) === 1) {\n matched.add(node);\n }\n return matched;\n }\n\n /**\n * match An+B\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {string} nthName - nth pseudo-class name\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchAnPlusB(ast, node, nthName) {\n const {\n nth: {\n a,\n b,\n name: nthIdentName\n },\n selector\n } = ast;\n const identName = unescapeSelector(nthIdentName);\n const anbMap = new Map();\n if (identName) {\n if (identName === 'even') {\n anbMap.set('a', 2);\n anbMap.set('b', 0);\n } else if (identName === 'odd') {\n anbMap.set('a', 2);\n anbMap.set('b', 1);\n }\n if (nthName.indexOf('last') > -1) {\n anbMap.set('reverse', true);\n }\n } else {\n if (typeof a === 'string' && /-?\\d+/.test(a)) {\n anbMap.set('a', a * 1);\n } else {\n anbMap.set('a', 0);\n }\n if (typeof b === 'string' && /-?\\d+/.test(b)) {\n anbMap.set('b', b * 1);\n } else {\n anbMap.set('b', 0);\n }\n if (nthName.indexOf('last') > -1) {\n anbMap.set('reverse', true);\n }\n }\n let matched = new Set();\n if (anbMap.has('a') && anbMap.has('b')) {\n if (/^nth-(?:last-)?child$/.test(nthName)) {\n if (selector) {\n anbMap.set('selector', selector);\n }\n const anb = Object.fromEntries(anbMap);\n const nodes = this._collectNthChild(anb, node);\n if (nodes.size) {\n matched = nodes;\n }\n } else if (/^nth-(?:last-)?of-type$/.test(nthName)) {\n const anb = Object.fromEntries(anbMap);\n const nodes = this._collectNthOfType(anb, node);\n if (nodes.size) {\n matched = nodes;\n }\n }\n }\n return matched;\n }\n\n /**\n * match pseudo element selector\n * @param {string} astName - AST name\n * @param {object} [opt] - options\n * @param {boolean} [opt.forgive] - is forgiving selector list\n * @throws {DOMException}\n * @returns {void}\n */\n _matchPseudoElementSelector(astName, opt = {}) {\n const { forgive } = opt;\n switch (astName) {\n case 'after':\n case 'backdrop':\n case 'before':\n case 'cue':\n case 'cue-region':\n case 'first-letter':\n case 'first-line':\n case 'file-selector-button':\n case 'marker':\n case 'placeholder':\n case 'selection':\n case 'target-text': {\n if (this.#warn) {\n 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 (this.#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 (this.#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\n /**\n * match directionality pseudo-class - :dir()\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchDirectionPseudoClass(ast, node) {\n const astName = unescapeSelector(ast.name);\n const dir = getDirectionality(node);\n let res;\n if (astName === dir) {\n res = node;\n }\n return res ?? null;\n }\n\n /**\n * match language pseudo-class - :lang()\n * @see https://datatracker.ietf.org/doc/html/rfc4647#section-3.3.1\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchLanguagePseudoClass(ast, node) {\n const astName = unescapeSelector(ast.name);\n let res;\n if (astName === '*') {\n if (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 * @param {Array.<object>} leaves - AST leaves\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\n _matchHasPseudoFunc(leaves, node) {\n let bool;\n if (Array.isArray(leaves) && leaves.length) {\n const [leaf] = leaves;\n const { type: leafType } = leaf;\n let combo;\n if (leafType === COMBINATOR) {\n combo = leaves.shift();\n } else {\n combo = {\n name: ' ',\n type: COMBINATOR\n };\n }\n const twigLeaves = [];\n while (leaves.length) {\n const [item] = leaves;\n const { type: itemType } = item;\n if (itemType === COMBINATOR) {\n break;\n } else {\n twigLeaves.push(leaves.shift());\n }\n }\n const twig = {\n combo,\n leaves: twigLeaves\n };\n const nodes = this._matchCombinator(twig, node, {\n dir: DIR_NEXT\n });\n if (nodes.size) {\n if (leaves.length) {\n for (const nextNode of nodes) {\n bool =\n this._matchHasPseudoFunc(Object.assign([], leaves), nextNode);\n if (bool) {\n break;\n }\n }\n } else {\n bool = true;\n }\n }\n }\n return !!bool;\n }\n\n /**\n * match logical pseudo-class functions - :has(), :is(), :not(), :where()\n * @param {object} astData - AST data\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchLogicalPseudoFunc(astData, node) {\n const {\n astName = '', branches = [], selector = '', twigBranches = []\n } = astData;\n let res;\n if (astName === 'has') {\n if (selector.includes(':has(')) {\n res = null;\n } else {\n let bool;\n for (const leaves of branches) {\n bool = this._matchHasPseudoFunc(Object.assign([], leaves), node);\n if (bool) {\n break;\n }\n }\n if (bool) {\n res = node;\n }\n }\n } else {\n const forgive = /^(?:is|where)$/.test(astName);\n const l = twigBranches.length;\n let bool;\n for (let i = 0; i < l; i++) {\n const branch = twigBranches[i];\n const lastIndex = branch.length - 1;\n const { leaves } = branch[lastIndex];\n bool = this._matchLeaves(leaves, node, { forgive });\n if (bool && lastIndex > 0) {\n let nextNodes = new Set([node]);\n for (let j = lastIndex - 1; j >= 0; j--) {\n const twig = branch[j];\n const arr = [];\n for (const nextNode of nextNodes) {\n const m = this._matchCombinator(twig, nextNode, {\n forgive,\n dir: DIR_PREV\n });\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 * @see https://html.spec.whatwg.org/#pseudo-classes\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.forgive] - is forgiving selector list\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchPseudoClassSelector(ast, node, opt = {}) {\n const { children: astChildren } = ast;\n const { localName, parentNode } = node;\n const { forgive } = opt;\n const astName = unescapeSelector(ast.name);\n let matched = new Set();\n // :has(), :is(), :not(), :where()\n if (REG_LOGICAL_PSEUDO.test(astName)) {\n let astData;\n if (this.#cache.has(ast)) {\n astData = this.#cache.get(ast);\n } else {\n const branches = walkAST(ast);\n const selectors = [];\n const twigBranches = [];\n for (const [...leaves] of branches) {\n for (const leaf of leaves) {\n const css = generateCSS(leaf);\n selectors.push(css);\n }\n const branch = [];\n const leavesSet = new Set();\n let item = leaves.shift();\n while (item) {\n if (item.type === COMBINATOR) {\n branch.push({\n combo: item,\n leaves: [...leavesSet]\n });\n leavesSet.clear();\n } else if (item) {\n leavesSet.add(item);\n }\n if (leaves.length) {\n item = leaves.shift();\n } else {\n branch.push({\n combo: null,\n leaves: [...leavesSet]\n });\n leavesSet.clear();\n break;\n }\n }\n twigBranches.push(branch);\n }\n astData = {\n astName,\n branches,\n twigBranches,\n selector: selectors.join(',')\n };\n this.#cache.set(ast, astData);\n }\n const res = this._matchLogicalPseudoFunc(astData, node);\n if (res) {\n matched.add(res);\n }\n } else if (Array.isArray(astChildren)) {\n const [branch] = astChildren;\n // :nth-child(), :nth-last-child(), nth-of-type(), :nth-last-of-type()\n if (/^nth-(?:last-)?(?:child|of-type)$/.test(astName)) {\n const nodes = this._matchAnPlusB(branch, node, astName);\n if (nodes.size) {\n matched = nodes;\n }\n // :dir()\n } else if (astName === 'dir') {\n const res = this._matchDirectionPseudoClass(branch, node);\n if (res) {\n matched.add(res);\n }\n // :lang()\n } else if (astName === 'lang') {\n const res = this._matchLanguagePseudoClass(branch, node);\n if (res) {\n matched.add(res);\n }\n } else {\n switch (astName) {\n case 'current':\n case 'nth-col':\n case 'nth-last-col': {\n if (this.#warn) {\n 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 matched.add(node);\n }\n break;\n }\n case 'focus-within': {\n let current = this.#document.activeElement;\n while (current) {\n if (current === node) {\n matched.add(node);\n break;\n }\n current = current.parentNode;\n }\n break;\n }\n case 'open': {\n if (regInteract.test(localName) && node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'closed': {\n if (regInteract.test(localName) && !node.hasAttribute('open')) {\n matched.add(node);\n }\n break;\n }\n case 'disabled': {\n if (regFormCtrl.test(localName) || isCustomElementName(localName)) {\n if (node.disabled || node.hasAttribute('disabled')) {\n matched.add(node);\n } else {\n let parent = parentNode;\n while (parent) {\n if (parent.localName === 'fieldset') {\n break;\n }\n parent = parent.parentNode;\n }\n if (parent && parentNode.localName !== 'legend' &&\n parent.hasAttribute('disabled')) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'enabled': {\n if ((regFormCtrl.test(localName) || isCustomElementName(localName)) &&\n !(node.disabled && node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n case 'read-only': {\n switch (localName) {\n case 'textarea': {\n if (node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled')) {\n matched.add(node);\n }\n break;\n }\n case 'input': {\n if ((!node.type || regTypeDate.test(node.type) ||\n regTypeText.test(node.type)) &&\n (node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n default: {\n if (!isContentEditable(node)) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'read-write': {\n switch (localName) {\n case 'textarea': {\n if (!(node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n case 'input': {\n if ((!node.type || regTypeDate.test(node.type) ||\n regTypeText.test(node.type)) &&\n !(node.readonly || node.hasAttribute('readonly') ||\n node.disabled || node.hasAttribute('disabled'))) {\n matched.add(node);\n }\n break;\n }\n default: {\n if (isContentEditable(node)) {\n matched.add(node);\n }\n }\n }\n break;\n }\n case 'placeholder-shown': {\n let targetNode;\n if (localName === 'textarea') {\n targetNode = node;\n } else if (localName === 'input') {\n if (node.hasAttribute('type')) {\n if (regTypeText.test(node.getAttribute('type'))) {\n targetNode = node;\n }\n } else {\n targetNode = node;\n }\n }\n if (targetNode && node.value === '' &&\n node.hasAttribute('placeholder') &&\n node.getAttribute('placeholder').trim().length) {\n matched.add(node);\n }\n break;\n }\n case 'checked': {\n if ((node.checked && localName === 'input' &&\n node.hasAttribute('type') &&\n regTypeCheck.test(node.getAttribute('type'))) ||\n (node.selected && localName === 'option')) {\n matched.add(node);\n }\n break;\n }\n case 'indeterminate': {\n if ((node.indeterminate && localName === 'input' &&\n node.type === 'checkbox') ||\n (localName === 'progress' && !node.hasAttribute('value'))) {\n matched.add(node);\n } else if (localName === 'input' && node.type === 'radio' &&\n !node.hasAttribute('checked')) {\n const nodeName = node.name;\n let parent = node.parentNode;\n while (parent) {\n if (parent.localName === 'form') {\n break;\n }\n parent = parent.parentNode;\n }\n if (!parent) {\n parent = this.#document.documentElement;\n }\n let checked;\n const nodes = [].slice.call(parent.getElementsByTagName('input'));\n for (const item of nodes) {\n if (item.getAttribute('type') === 'radio') {\n if (nodeName) {\n if (item.getAttribute('name') === nodeName) {\n checked = !!item.checked;\n }\n } else if (!item.hasAttribute('name')) {\n checked = !!item.checked;\n }\n if (checked) {\n break;\n }\n }\n }\n if (!checked) {\n matched.add(node);\n }\n }\n break;\n }\n case 'default': {\n const regTypeReset = /^(?:button|reset)$/;\n const regTypeSubmit = /^(?:image|submit)$/;\n // button[type=\"submit\"], input[type=\"submit\"], input[type=\"image\"]\n if ((localName === 'button' &&\n !(node.hasAttribute('type') &&\n regTypeReset.test(node.getAttribute('type')))) ||\n (localName === 'input' && node.hasAttribute('type') &&\n regTypeSubmit.test(node.getAttribute('type')))) {\n let form = node.parentNode;\n while (form) {\n if (form.localName === 'form') {\n break;\n }\n form = form.parentNode;\n }\n if (form) {\n const 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 && this.#root.nodeType === ELEMENT_NODE)) {\n matched.add(node);\n }\n break;\n }\n case 'last-child': {\n if ((parentNode && node === parentNode.lastElementChild) ||\n (node === this.#root && this.#root.nodeType === ELEMENT_NODE)) {\n matched.add(node);\n }\n break;\n }\n case 'only-child': {\n if ((parentNode &&\n node === parentNode.firstElementChild &&\n node === parentNode.lastElementChild) ||\n (node === this.#root && this.#root.nodeType === ELEMENT_NODE)) {\n matched.add(node);\n }\n break;\n }\n case 'first-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1\n }, node);\n if (node1) {\n matched.add(node1);\n }\n } else if (node === this.#root &&\n this.#root.nodeType === ELEMENT_NODE) {\n matched.add(node);\n }\n break;\n }\n case 'last-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1,\n reverse: true\n }, node);\n if (node1) {\n matched.add(node1);\n }\n } else if (node === this.#root &&\n this.#root.nodeType === ELEMENT_NODE) {\n matched.add(node);\n }\n break;\n }\n case 'only-of-type': {\n if (parentNode) {\n const [node1] = this._collectNthOfType({\n a: 0,\n b: 1\n }, node);\n if (node1 === node) {\n const [node2] = this._collectNthOfType({\n a: 0,\n b: 1,\n reverse: true\n }, node);\n if (node2 === node) {\n matched.add(node);\n }\n }\n } else if (node === this.#root &&\n this.#root.nodeType === ELEMENT_NODE) {\n matched.add(node);\n }\n break;\n }\n case 'host':\n case 'host-context': {\n // ignore\n break;\n }\n // legacy pseudo-elements\n case 'after':\n case 'before':\n case 'first-letter':\n case 'first-line': {\n if (this.#warn) {\n 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 (this.#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 (this.#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 attribute selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchAttributeSelector(ast, node) {\n const {\n flags: astFlags, matcher: astMatcher, name: astName, value: astValue\n } = ast;\n if (typeof astFlags === 'string' && !/^[is]$/i.test(astFlags)) {\n const css = generateCSS(ast);\n 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 let caseInsensitive;\n if (this.#document.contentType === 'text/html') {\n if (typeof astFlags === 'string' && /^s$/i.test(astFlags)) {\n caseInsensitive = false;\n } else {\n caseInsensitive = true;\n }\n } else if (typeof astFlags === 'string' && /^i$/i.test(astFlags)) {\n caseInsensitive = true;\n } else {\n caseInsensitive = false;\n }\n let astAttrName = unescapeSelector(astName.name);\n if (caseInsensitive) {\n astAttrName = astAttrName.toLowerCase();\n }\n const attrValues = new Set();\n // namespaced\n if (astAttrName.indexOf('|') > -1) {\n const {\n prefix: astAttrPrefix, tagName: astAttrLocalName\n } = selectorToNodeProps(astAttrName);\n for (let { name: itemName, value: itemValue } of attributes) {\n if (caseInsensitive) {\n itemName = itemName.toLowerCase();\n itemValue = itemValue.toLowerCase();\n }\n switch (astAttrPrefix) {\n case '': {\n if (astAttrLocalName === itemName) {\n attrValues.add(itemValue);\n }\n break;\n }\n case '*': {\n if (itemName.indexOf(':') > -1) {\n if (itemName.endsWith(`:${astAttrLocalName}`)) {\n attrValues.add(itemValue);\n }\n } else if (astAttrLocalName === itemName) {\n attrValues.add(itemValue);\n }\n break;\n }\n default: {\n if (itemName.indexOf(':') > -1) {\n const [itemNamePrefix, itemNameLocalName] = itemName.split(':');\n if (astAttrPrefix === itemNamePrefix &&\n astAttrLocalName === itemNameLocalName &&\n isNamespaceDeclared(astAttrPrefix, node)) {\n attrValues.add(itemValue);\n }\n }\n }\n }\n }\n } else {\n for (let { name: itemName, value: itemValue } of attributes) {\n if (caseInsensitive) {\n itemName = itemName.toLowerCase();\n itemValue = itemValue.toLowerCase();\n }\n if (itemName.indexOf(':') > -1) {\n const [itemNamePrefix, itemNameLocalName] = itemName.split(':');\n // ignore xml:lang\n if (itemNamePrefix === 'xml' && itemNameLocalName === 'lang') {\n continue;\n } else if (astAttrName === itemNameLocalName) {\n attrValues.add(itemValue);\n }\n } else if (astAttrName === itemName) {\n attrValues.add(itemValue);\n }\n }\n }\n if (attrValues.size) {\n const {\n name: astAttrIdentValue, value: astAttrStringValue\n } = astValue || {};\n let attrValue;\n if (astAttrIdentValue) {\n if (caseInsensitive) {\n attrValue = astAttrIdentValue.toLowerCase();\n } else {\n attrValue = astAttrIdentValue;\n }\n } else if (astAttrStringValue) {\n if (caseInsensitive) {\n attrValue = astAttrStringValue.toLowerCase();\n } else {\n attrValue = astAttrStringValue;\n }\n } else if (astAttrStringValue === '') {\n attrValue = astAttrStringValue;\n }\n switch (astMatcher) {\n case '=': {\n if (typeof attrValue === 'string' && attrValues.has(attrValue)) {\n res = node;\n }\n break;\n }\n case '~=': {\n if (attrValue && typeof attrValue === 'string') {\n for (const value of attrValues) {\n const item = new Set(value.split(/\\s+/));\n if (item.has(attrValue)) {\n res = node;\n break;\n }\n }\n }\n break;\n }\n case '|=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value === attrValue || value.startsWith(`${attrValue}-`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '^=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.startsWith(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '$=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.endsWith(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '*=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.includes(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case null:\n default: {\n res = node;\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * match class selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchClassSelector(ast, node) {\n const astName = unescapeSelector(ast.name);\n let res;\n if (node.classList.contains(astName)) {\n res = node;\n }\n return res ?? null;\n }\n\n /**\n * match ID selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchIDSelector(ast, node) {\n const astName = unescapeSelector(ast.name);\n const { id } = node;\n let res;\n if (astName === id) {\n res = node;\n }\n return res ?? null;\n }\n\n /**\n * match type selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.forgive] - is forgiving selector list\n * @returns {?object} - matched node\n */\n _matchTypeSelector(ast, node, opt = {}) {\n const astName = unescapeSelector(ast.name);\n const { localName, prefix } = node;\n const { forgive } = opt;\n let {\n prefix: astPrefix, tagName: astNodeName\n } = selectorToNodeProps(astName, node);\n if (this.#document.contentType === 'text/html') {\n astPrefix = astPrefix.toLowerCase();\n astNodeName = astNodeName.toLowerCase();\n }\n let nodePrefix;\n let nodeName;\n // just in case that the namespaced content is parsed as text/html\n if (localName.indexOf(':') > -1) {\n [nodePrefix, nodeName] = localName.split(':');\n } else {\n nodePrefix = prefix || '';\n nodeName = localName;\n }\n let res;\n if (astPrefix === '' && nodePrefix === '') {\n if (node.namespaceURI === null &&\n (astNodeName === '*' || astNodeName === nodeName)) {\n res = node;\n }\n } else if (astPrefix === '*') {\n if (astNodeName === '*' || astNodeName === nodeName) {\n res = node;\n }\n } else if (astPrefix === nodePrefix) {\n if (isNamespaceDeclared(astPrefix, node)) {\n if (astNodeName === '*' || astNodeName === nodeName) {\n res = node;\n }\n } else if (!forgive) {\n const msg = `Undeclared namespace ${astPrefix}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n } else if (astPrefix && !forgive && !isNamespaceDeclared(astPrefix, node)) {\n const msg = `Undeclared namespace ${astPrefix}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n return res ?? null;\n };\n\n /**\n * match shadow host pseudo class\n * @param {object} ast - AST\n * @param {object} node - DocumentFragment node\n * @returns {?object} - matched node\n */\n _matchShadowHostPseudoClass(ast, node) {\n const { children: astChildren } = ast;\n const astName = unescapeSelector(ast.name);\n let res;\n if (Array.isArray(astChildren)) {\n const [branch] = walkAST(astChildren[0]);\n const [...leaves] = branch;\n const { host } = node;\n if (astName === 'host') {\n let bool;\n for (const leaf of leaves) {\n const { type: leafType } = leaf;\n if (leafType === COMBINATOR) {\n const css = generateCSS(ast);\n 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 * @param {object} ast - AST\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} [opt] - options\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchSelector(ast, node, opt) {\n const { type: astType } = ast;\n const astName = unescapeSelector(ast.name);\n let matched = new Set();\n if (node.nodeType === ELEMENT_NODE) {\n switch (astType) {\n case SELECTOR_ATTR: {\n const res = this._matchAttributeSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case SELECTOR_CLASS: {\n const res = this._matchClassSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case SELECTOR_ID: {\n const res = this._matchIDSelector(ast, node);\n if (res) {\n matched.add(res);\n }\n break;\n }\n case SELECTOR_PSEUDO_CLASS: {\n const nodes = this._matchPseudoClassSelector(ast, node, opt);\n if (nodes.size) {\n matched = nodes;\n }\n break;\n }\n case SELECTOR_PSEUDO_ELEMENT: {\n this._matchPseudoElementSelector(astName, opt);\n break;\n }\n case SELECTOR_TYPE:\n default: {\n const res = this._matchTypeSelector(ast, node, opt);\n if (res) {\n matched.add(res);\n }\n }\n }\n } else if (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);\n if (res) {\n matched.add(res);\n }\n }\n }\n return matched;\n }\n\n /**\n * match leaves\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} node - node\n * @param {object} [opt] - options\n * @returns {boolean} - result\n */\n _matchLeaves(leaves, node, opt) {\n let bool;\n for (const leaf of leaves) {\n bool = this._matchSelector(leaf, node, opt).has(node);\n if (!bool) {\n break;\n }\n }\n return !!bool;\n }\n\n /**\n * find descendant nodes\n * @param {Array.<object>} leaves - AST leaves\n * @param {object} baseNode - base Element node\n * @returns {object} - collection of nodes and pending state\n */\n _findDescendantNodes(leaves, baseNode) {\n const [leaf, ...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_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);\n if (bool) {\n nodes.add(node);\n }\n } else {\n nodes.add(node);\n }\n }\n }\n break;\n }\n case SELECTOR_CLASS: {\n const arr = [].slice.call(baseNode.getElementsByClassName(leafName));\n if (arr.length) {\n if (compound) {\n for (const node of arr) {\n const bool = this._matchLeaves(filterLeaves, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n break;\n }\n case SELECTOR_TYPE: {\n if (this.#document.contentType === 'text/html' &&\n !/[*|]/.test(leafName)) {\n const arr = [].slice.call(baseNode.getElementsByTagName(leafName));\n if (arr.length) {\n if (compound) {\n for (const node of arr) {\n const bool = this._matchLeaves(filterLeaves, node);\n if (bool) {\n nodes.add(node);\n }\n }\n } else {\n nodes = new Set(arr);\n }\n }\n } else {\n pending = true;\n }\n break;\n }\n case SELECTOR_PSEUDO_ELEMENT: {\n this._matchPseudoElementSelector(leafName);\n break;\n }\n default: {\n pending = true;\n }\n }\n }\n return {\n nodes,\n pending\n };\n }\n\n /**\n * match combinator\n * @param {object} twig - twig\n * @param {object} node - Element node\n * @param {object} [opt] - option\n * @param {string} [opt.dir] - direction to find\n * @param {boolean} [opt.forgive] - is forgiving selector list\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchCombinator(twig, node, opt = {}) {\n const { combo, leaves } = twig;\n const { name: comboName } = combo;\n const { dir, forgive } = 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, { forgive });\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, { forgive });\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, { forgive });\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, { forgive });\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, { forgive });\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, { forgive });\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, { forgive });\n if (bool) {\n matched.add(refNode);\n }\n }\n break;\n }\n case ' ':\n default: {\n const arr = [];\n let refNode = node.parentNode;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode, { forgive });\n if (bool) {\n arr.push(refNode);\n }\n refNode = refNode.parentNode;\n }\n if (arr.length) {\n matched = new Set(arr.reverse());\n }\n }\n }\n }\n return matched;\n }\n\n /**\n * find matched node from finder\n * @param {Array.<object>} 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 if (matched) {\n matchedNode = refNode;\n break;\n }\n }\n refNode = this.#finder.nextNode();\n }\n }\n return matchedNode ?? null;\n }\n\n /**\n * find entry nodes\n * @param {object} twig - twig\n * @param {string} targetType - target type\n * @returns {object} - collection of nodes etc.\n */\n _findEntryNodes(twig, targetType) {\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 = new Set();\n let filtered = false;\n let pending = false;\n switch (leafType) {\n case SELECTOR_ID: {\n if (targetType === TARGET_SELF) {\n const bool = this._matchLeaves(leaves, this.#node);\n if (bool) {\n nodes.add(this.#node);\n filtered = true;\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode);\n if (bool) {\n nodes.add(refNode);\n filtered = true;\n }\n refNode = refNode.parentNode;\n }\n } else if (targetType === TARGET_FIRST &&\n this.#root.nodeType !== ELEMENT_NODE) {\n const node = this.#root.getElementById(leafName);\n if (node) {\n nodes.add(node);\n }\n } else {\n pending = true;\n }\n break;\n }\n case SELECTOR_CLASS: {\n if (targetType === TARGET_SELF) {\n if (this.#node.nodeType === ELEMENT_NODE &&\n this.#node.classList.contains(leafName)) {\n nodes.add(this.#node);\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n if (refNode.nodeType === ELEMENT_NODE) {\n if (refNode.classList.contains(leafName)) {\n nodes.add(refNode);\n }\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n } else if (targetType === TARGET_FIRST) {\n const node = this._findNode(leaves, {\n node: this.#node\n });\n if (node) {\n nodes.add(node);\n filtered = true;\n }\n } else if (this.#root.nodeType === DOCUMENT_NODE) {\n const arr =\n [].slice.call(this.#root.getElementsByClassName(leafName));\n if (this.#node.nodeType === ELEMENT_NODE) {\n for (const node of arr) {\n if (node === this.#node || isInclusive(node, this.#node)) {\n nodes.add(node);\n }\n }\n } else if (arr.length) {\n nodes = new Set(arr);\n }\n } else {\n pending = true;\n }\n break;\n }\n case SELECTOR_TYPE: {\n if (targetType === TARGET_SELF) {\n if (this.#node.nodeType === ELEMENT_NODE) {\n const bool = this._matchLeaves(leaves, this.#node);\n if (bool) {\n nodes.add(this.#node);\n filtered = true;\n }\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n if (refNode.nodeType === ELEMENT_NODE) {\n const bool = this._matchLeaves(leaves, refNode);\n if (bool) {\n nodes.add(refNode);\n filtered = true;\n }\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n } else if (targetType === TARGET_FIRST) {\n const node = this._findNode(leaves, {\n node: this.#node\n });\n if (node) {\n nodes.add(node);\n filtered = true;\n }\n } else if (this.#document.contentType === 'text/html' &&\n this.#root.nodeType === DOCUMENT_NODE &&\n !/[*|]/.test(leafName)) {\n const arr = [].slice.call(this.#root.getElementsByTagName(leafName));\n if (this.#node.nodeType === ELEMENT_NODE) {\n for (const node of arr) {\n if (node === this.#node || isInclusive(node, this.#node)) {\n nodes.add(node);\n }\n }\n } else if (arr.length) {\n nodes = new Set(arr);\n }\n } else {\n pending = true;\n }\n break;\n }\n case SELECTOR_PSEUDO_ELEMENT: {\n // throws\n this._matchPseudoElementSelector(leafName);\n break;\n }\n default: {\n if (targetType !== TARGET_LINEAL && REG_SHADOW_HOST.test(leafName)) {\n if (this.#shadow && this.#node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const node = this._matchShadowHostPseudoClass(leaf, this.#node);\n if (node) {\n nodes.add(node);\n }\n }\n } else if (targetType === TARGET_SELF) {\n const bool = this._matchLeaves(leaves, this.#node);\n if (bool) {\n nodes.add(this.#node);\n filtered = true;\n }\n } else if (targetType === TARGET_LINEAL) {\n let refNode = this.#node;\n while (refNode) {\n const bool = this._matchLeaves(leaves, refNode);\n if (bool) {\n nodes.add(refNode);\n filtered = true;\n }\n refNode = refNode.parentNode;\n }\n } else if (targetType === TARGET_FIRST) {\n const node = this._findNode(leaves, {\n node: this.#node\n });\n if (node) {\n nodes.add(node);\n filtered = true;\n }\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 * @param {Array.<object>} 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 * @param {string} targetType - target type\n * @returns {Array.<Array.<object|undefined>>} - #ast and #nodes\n */\n _collectNodes(targetType) {\n const ast = this.#ast.values();\n if (targetType === TARGET_ALL || targetType === TARGET_FIRST) {\n const pendingItems = new Set();\n let i = 0;\n for (const { branch } of ast) {\n const { dir, twig } = this._getEntryTwig(branch, targetType);\n const {\n compound, filtered, nodes, pending\n } = this._findEntryNodes(twig, targetType);\n if (nodes.size) {\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 if (matched) {\n const index = pendingItem.get('index');\n this.#ast[index].filtered = true;\n this.#ast[index].find = true;\n this.#nodes[index].add(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 {\n compound, filtered, nodes\n } = this._findEntryNodes(twig, targetType);\n if (nodes.size) {\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 * sort nodes\n * @param {Array.<object>|Set.<object>} nodes - collection of nodes\n * @returns {Array.<object|undefined>} - collection of sorted nodes\n */\n _sortNodes(nodes) {\n const arr = [...nodes];\n if (arr.length > 1) {\n arr.sort((a, b) => {\n let res;\n if (isPreceding(b, a)) {\n res = 1;\n } else {\n res = -1;\n }\n return res;\n });\n }\n return arr;\n }\n\n /**\n * match nodes\n * @param {string} targetType - target type\n * @returns {Set.<object>} - collection of matched nodes\n */\n _matchNodes(targetType) {\n const [...branches] = this.#ast;\n const l = branches.length;\n let nodes = new Set();\n for (let i = 0; i < l; i++) {\n const { branch, dir, filtered, find } = branches[i];\n const branchLen = branch.length;\n if (branchLen && find) {\n const entryNodes = this.#nodes[i];\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 (const node of entryNodes) {\n const bool = filtered || this._matchLeaves(filterLeaves, node);\n if (bool && 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 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 {\n for (const node of entryNodes) {\n const bool = filtered || this._matchLeaves(filterLeaves, node);\n if (bool) {\n nodes.add(node);\n if (targetType !== TARGET_ALL) {\n break;\n }\n }\n }\n }\n } else if (dir === DIR_NEXT) {\n let { combo, leaves: entryLeaves } = branch[0];\n const [, ...filterLeaves] = entryLeaves;\n let matched;\n for (const node of entryNodes) {\n const bool = filtered || this._matchLeaves(filterLeaves, node);\n if (bool) {\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, { dir });\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] = this._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 } else {\n matched = false;\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, { dir });\n if (m.size) {\n arr.push(...m);\n }\n }\n if (arr.length) {\n if (j === lastIndex) {\n const [node] = this._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 const [, ...filterLeaves] = entryLeaves;\n let matched;\n for (const node of entryNodes) {\n const bool = filtered || this._matchLeaves(filterLeaves, node);\n if (bool) {\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, { dir });\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 }\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, { dir });\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 * @param {string} targetType - target type\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {string} selector - CSS selector\n * @param {object} [opt] - options\n * @returns {Set.<object>} - collection of matched nodes\n */\n _find(targetType, node, selector, opt = {}) {\n const { warn } = opt;\n this.#warn = !!warn;\n if (!node) {\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 !== 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 } else if ((targetType === TARGET_SELF || targetType === TARGET_LINEAL) &&\n node.nodeType !== ELEMENT_NODE) {\n const msg = `Unexpected node ${node.nodeName}`;\n throw new TypeError(msg);\n }\n this.#node = node;\n [this.#window, this.#document, this.#root] = this._setup(node);\n this.#shadow = isInShadowTree(node);\n this.#selector = selector;\n [this.#ast, this.#nodes] = this._correspond(selector);\n if (targetType === TARGET_ALL || targetType === TARGET_FIRST) {\n this.#tree = this.#document.createTreeWalker(this.#root, WALKER_FILTER);\n this.#finder = this.#document.createTreeWalker(this.#node, SHOW_ELEMENT);\n this.#sort = false;\n }\n this._collectNodes(targetType);\n const nodes = this._matchNodes(targetType);\n return nodes;\n }\n\n /**\n * matches\n * @param {object} node - Element node\n * @param {string} selector - CSS selector\n * @param {object} opt - options\n * @returns {boolean} - `true` if matched `false` otherwise\n */\n matches(node, selector, opt) {\n let res;\n try {\n const nodes = this._find(TARGET_SELF, node, selector, opt);\n if (nodes.size) {\n res = nodes.has(this.#node);\n }\n } catch (e) {\n this._onError(e);\n }\n return !!res;\n }\n\n /**\n * closest\n * @param {object} node - Element node\n * @param {string} selector - CSS selector\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\n closest(node, selector, opt) {\n let res;\n try {\n const nodes = this._find(TARGET_LINEAL, node, selector, opt);\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 } catch (e) {\n this._onError(e);\n }\n return res ?? null;\n }\n\n /**\n * query selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {string} selector - CSS selector\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\n querySelector(node, selector, opt) {\n let res;\n try {\n const nodes = this._find(TARGET_FIRST, node, selector, opt);\n nodes.delete(this.#node);\n if (nodes.size) {\n [res] = this._sortNodes(nodes);\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? null;\n }\n\n /**\n * query selector all\n * NOTE: returns Array, not NodeList\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {string} selector - CSS selector\n * @param {object} opt - options\n * @returns {Array.<object|undefined>} - collection of matched nodes\n */\n querySelectorAll(node, selector, opt) {\n let res;\n try {\n const nodes = this._find(TARGET_ALL, node, selector, opt);\n nodes.delete(this.#node);\n if (nodes.size) {\n if (this.#sort) {\n res = this._sortNodes(nodes);\n } else {\n res = [...nodes];\n }\n }\n } catch (e) {\n this._onError(e);\n }\n return res ?? [];\n }\n};\n"],
|
|
5
|
-
"mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,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CACtBf,EAAMe,EACN,KACF,CACAA,EAAUA,EAAQ,UACpB,CACF,OAAS7B,EAAG,CACV,KAAK,SAASA,CAAC,CACjB,CACA,OAAOc,GAAO,IAChB,CASA,cAAcb,EAAMc,EAAUkC,EAAK,CACjC,IAAInC,EACJ,GAAI,CACF,MAAME,EAAQ,KAAK,MAAMlC,EAAcmB,EAAMc,EAAUkC,CAAG,EAC1DjC,EAAM,OAAO,KAAKzB,EAAK,EACnByB,EAAM,OACR,CAACF,CAAG,EAAI,KAAK,WAAWE,CAAK,EAEjC,OAAShB,EAAG,CACV,KAAK,SAASA,CAAC,CACjB,CACA,OAAOc,GAAO,IAChB,CAUA,iBAAiBb,EAAMc,EAAUkC,EAAK,CACpC,IAAInC,EACJ,GAAI,CACF,MAAME,EAAQ,KAAK,MAAMnC,EAAYoB,EAAMc,EAAUkC,CAAG,EACxDjC,EAAM,OAAO,KAAKzB,EAAK,EACnByB,EAAM,OACJ,KAAKpB,GACPkB,EAAM,KAAK,WAAWE,CAAK,EAE3BF,EAAM,CAAC,GAAGE,CAAK,EAGrB,OAAShB,EAAG,CACV,KAAK,SAASA,CAAC,CACjB,CACA,OAAOc,GAAO,CAAC,CACjB,CACF",
|
|
6
|
-
"names": ["matcher_exports", "__export", "
|
|
4
|
+
"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_CLASS, SELECTOR_ID,\n SELECTOR_TYPE, SYNTAX_ERR, 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(itemPrefix, 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 class 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 _matchClassSelector = (ast, node) => {\n const astName = unescapeSelector(ast.name);\n const { classList } = node;\n let res;\n if (classList.contains(astName)) {\n res = node;\n }\n return res ?? null;\n};\n\n/**\n * match ID 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 _matchIDSelector = (ast, node) => {\n const astName = unescapeSelector(ast.name);\n const { id } = node;\n let res;\n if (astName === id) {\n res = node;\n }\n return res ?? null;\n};\n\n/**\n * match type selector\n * @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 const contentType = node.ownerDocument.contentType;\n if (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 if (astPrefix === '' && nodePrefix === '') {\n if (namespaceURI === null &&\n (astLocalName === '*' || astLocalName === nodeLocalName)) {\n res = node;\n }\n } else if (astPrefix === '*') {\n if (astLocalName === '*' || astLocalName === nodeLocalName) {\n res = node;\n }\n } else if (astPrefix && nodePrefix) {\n const namespaceDeclared = isNamespaceDeclared(nodePrefix, node);\n if (astPrefix === nodePrefix) {\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 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_CLASS: {\n matched = _matchClassSelector(ast, node);\n break;\n }\n case SELECTOR_ID: {\n matched = _matchIDSelector(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"],
|
|
5
|
+
"mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,6BAAAE,EAAA,wBAAAC,EAAA,qBAAAC,EAAA,uBAAAC,EAAA,+BAAAC,EAAA,kBAAAC,IAAA,eAAAC,EAAAR,GAQA,IAAAS,EAAoC,yBACpCC,EAA4D,uBAG5DC,EAGO,yBASA,MAAMT,EAA0B,CAACU,EAAKC,IAAS,CACpD,KAAM,CACJ,MAAOC,EAAU,QAASC,EAAY,KAAMC,EAAS,MAAOC,CAC9D,EAAIL,EACJ,GAAI,OAAOE,GAAa,UAAY,CAAC,UAAU,KAAKA,CAAQ,EAAG,CAE7D,MAAMI,EAAM,uBADA,eAAYN,CAAG,CACQ,GACnC,MAAM,IAAI,aAAaM,EAAK,YAAU,CACxC,CACA,KAAM,CAAE,WAAAC,CAAW,EAAIN,EACvB,IAAIO,EACJ,GAAID,GAAcA,EAAW,OAAQ,CACnC,MAAME,EAAcR,EAAK,cAAc,YACvC,IAAIS,EACAD,IAAgB,YACd,OAAOP,GAAa,UAAY,OAAO,KAAKA,CAAQ,EACtDQ,EAAkB,GAElBA,EAAkB,GAEX,OAAOR,GAAa,UAAY,OAAO,KAAKA,CAAQ,EAC7DQ,EAAkB,GAElBA,EAAkB,GAEpB,IAAIC,KAAc,oBAAiB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I,UAAUE,CAAG,CACzB,CACA,KAAM,CAAE,QAAAwB,EAAS,KAAAK,CAAK,EAAIT,EAC1B,OAAQtB,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,GAAI+B,EAAM,CACR,MAAM7B,EAAM,gCAAgCF,CAAO,GACnD,MAAM,IAAI,aAAaE,EAAK,mBAAiB,CAC/C,CACA,KACF,CACA,IAAK,OACL,IAAK,UAAW,CACd,GAAI6B,EAAM,CACR,MAAM7B,EAAM,gCAAgCF,CAAO,KACnD,MAAM,IAAI,aAAaE,EAAK,mBAAiB,CAC/C,CACA,KACF,CACA,QACE,GAAIF,EAAQ,WAAW,UAAU,GAC/B,GAAI+B,EAAM,CACR,MAAM7B,EAAM,gCAAgCF,CAAO,GACnD,MAAM,IAAI,aAAaE,EAAK,mBAAiB,CAC/C,UACS,CAACwB,EAAS,CACnB,MAAMxB,EAAM,4BAA4BF,CAAO,GAC/C,MAAM,IAAI,aAAaE,EAAK,YAAU,CACxC,CAEJ,CACF",
|
|
6
|
+
"names": ["matcher_exports", "__export", "_matchAttributeSelector", "_matchClassSelector", "_matchIDSelector", "_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", "classList", "id", "opt", "localName", "namespaceURI", "prefix", "forgive", "nodePrefix", "nodeLocalName", "namespaceDeclared", "matched", "warn"]
|
|
7
7
|
}
|
package/dist/cjs/js/parser.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var E=Object.defineProperty;var
|
|
2
|
-
`).replace(/[\0\uD800-\uDFFF]|\\$/g,
|
|
1
|
+
var E=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var m=(n,t)=>{for(var r in t)E(n,r,{get:t[r],enumerable:!0})},y=(n,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of x(t))!T.call(n,s)&&s!==r&&E(n,s,{get:()=>t[s],enumerable:!(i=u(t,s))||i.enumerable});return n};var _=n=>y(E({},"__esModule",{value:!0}),n);var A={};m(A,{generateCSS:()=>O.generate,parseAstName:()=>$,parseSelector:()=>d,preprocess:()=>S,sortAST:()=>L,unescapeSelector:()=>w,walkAST:()=>I});module.exports=_(A);var g=require("css-tree"),e=require("./constant.js"),O=require("css-tree");const w=(n="")=>{if(typeof n=="string"&&n.indexOf("\\",0)>=0){const t=n.split("\\"),r=t.length;for(let i=1;i<r;i++){let s=t[i];if(s===""&&i===r-1)s=e.U_FFFD;else{const p=/^([\da-f]{1,6}\s?)/i.exec(s);if(p){const[,c]=p;let a;try{const o=parseInt("D800",e.HEX),f=parseInt("DFFF",e.HEX),h=parseInt(c,e.HEX);h===0||h>=o&&h<=f?a=e.U_FFFD:a=String.fromCodePoint(h)}catch{a=e.U_FFFD}let l="";s.length>c.length&&(l=s.substring(c.length)),s=`${a}${l}`}else/^[\n\r\f]/.test(s)&&(s="\\"+s)}t[i]=s}n=t.join("")}return n},S=(...n)=>{if(!n.length)throw new TypeError("1 argument required, but only 0 present.");let[t]=n;if(typeof t=="string"){let r=0;for(;r>=0&&(r=t.indexOf("#",r),!(r<0));){const i=t.substring(0,r+1);let s=t.substring(r+1);const p=s.codePointAt(0);if(p===e.BIT_HYPHEN){if(/^\d$/.test(s.substring(1,2)))throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR)}else if(p>e.BIT_FFFF){const c=`\\${p.toString(e.HEX)} `;s.length===e.DUO?s=c:s=`${c}${s.substring(e.DUO)}`}t=`${i}${s}`,r++}t=t.replace(/\f|\r\n?/g,`
|
|
2
|
+
`).replace(/[\0\uD800-\uDFFF]|\\$/g,e.U_FFFD)}else if(t==null)t=Object.prototype.toString.call(t).slice(e.TYPE_FROM,e.TYPE_TO).toLowerCase();else if(Array.isArray(t))t=t.join(",");else if(Object.prototype.hasOwnProperty.call(t,"toString"))t=t.toString();else throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR);return t},d=n=>{if(n=S(n),/^$|^\s*>|,\s*$/.test(n))throw new DOMException(`Invalid selector ${n}`,e.SYNTAX_ERR);let t;try{const r=(0,g.parse)(n,{context:"selectorList",parseCustomProperty:!0});t=(0,g.toPlainObject)(r)}catch(r){const i=/(:lang\(\s*("[A-Za-z\d\-*]+")\s*\))/;if(r.message==="Identifier is expected"&&i.test(n)){const[,s,p]=i.exec(n),c=p.replaceAll("*","\\*").replace(/^"/,"").replace(/"$/,""),a=s.replace(p,c);t=d(n.replace(s,a))}else if(r.message==='"]" is expected'&&!n.endsWith("]"))t=d(`${n}]`);else if(r.message==='")" is expected'&&!n.endsWith(")"))t=d(`${n})`);else throw new DOMException(r.message,e.SYNTAX_ERR)}return t},I=(n={})=>{const t=new Set;let r;return(0,g.walk)(n,{enter:s=>{s.type===e.SELECTOR?t.add(s.children):(s.type===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(s.name)||s.type===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(s.name))&&(r=!0)}}),r&&(0,g.findAll)(n,(s,p,c)=>{if(c){if(s.type===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(s.name)){const a=c.filter(l=>{const{name:o,type:f}=l;return f===e.SELECTOR_PSEUDO_CLASS&&e.REG_LOGICAL_PSEUDO.test(o)});for(const{children:l}of a)for(const{children:o}of l)for(const{children:f}of o)t.has(f)&&t.delete(f)}else if(s.type===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(s.name)){const a=c.filter(l=>{const{name:o,type:f}=l;return f===e.SELECTOR_PSEUDO_ELEMENT&&e.REG_SHADOW_PSEUDO.test(o)});for(const{children:l}of a)for(const{children:o}of l)t.has(o)&&t.delete(o)}}}),[...t]},L=n=>{const t=[...n];if(t.length>1){const r=new Map([[e.SELECTOR_PSEUDO_ELEMENT,e.BIT_01],[e.SELECTOR_ID,e.BIT_02],[e.SELECTOR_CLASS,e.BIT_04],[e.SELECTOR_TYPE,e.BIT_08],[e.SELECTOR_ATTR,e.BIT_16],[e.SELECTOR_PSEUDO_CLASS,e.BIT_32]]);t.sort((i,s)=>{const{type:p}=i,{type:c}=s,a=r.get(p),l=r.get(c);let o;return a===l?o=0:a>l?o=1:o=-1,o})}return t},$=n=>{let t,r;if(n&&typeof n=="string")n.indexOf("|")>-1?[t,r]=n.split("|"):(t="*",r=n);else throw new DOMException(`Invalid selector ${n}`,e.SYNTAX_ERR);return{prefix:t,localName:r}};0&&(module.exports={generateCSS,parseAstName,parseSelector,preprocess,sortAST,unescapeSelector,walkAST});
|
|
3
3
|
//# sourceMappingURL=parser.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/js/parser.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * parser.js\n */\n\n/* import */\nimport { findAll, parse, toPlainObject, walk } from 'css-tree';\n\n/* constants */\nimport {\n
|
|
5
|
-
"mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,
|
|
6
|
-
"names": ["parser_exports", "__export", "parseSelector", "preprocess", "unescapeSelector", "walkAST", "__toCommonJS", "import_css_tree", "import_constant", "selector", "arr", "l", "item", "hexExists", "hex", "str", "low", "high", "deci", "postStr", "args", "index", "preHash", "postHash", "codePoint", "res", "ast", "e", "regLang", "lang", "range", "escapedRange", "escapedLang", "branches", "hasPseudoFunc", "node", "list", "itemList", "i", "name", "type", "children", "grandChildren", "greatGrandChildren"]
|
|
4
|
+
"sourcesContent": ["/**\n * parser.js\n */\n\n/* import */\nimport { findAll, parse, toPlainObject, walk } from 'css-tree';\n\n/* constants */\nimport {\n BIT_01, BIT_02, BIT_04, BIT_08, BIT_16, BIT_32, BIT_FFFF, BIT_HYPHEN,\n DUO, HEX, REG_LOGICAL_PSEUDO, REG_SHADOW_PSEUDO, SELECTOR, SELECTOR_ATTR,\n SELECTOR_CLASS, SELECTOR_ID, SELECTOR_PSEUDO_CLASS, SELECTOR_PSEUDO_ELEMENT,\n SELECTOR_TYPE, SYNTAX_ERR, TYPE_FROM, TYPE_TO, U_FFFD\n} from './constant.js';\n\n/**\n * unescape selector\n * @param {string} selector - CSS selector\n * @returns {?string} - unescaped selector\n */\nexport const unescapeSelector = (selector = '') => {\n if (typeof selector === 'string' && selector.indexOf('\\\\', 0) >= 0) {\n const arr = selector.split('\\\\');\n const l = arr.length;\n for (let i = 1; i < l; i++) {\n let item = arr[i];\n if (item === '' && i === l - 1) {\n item = U_FFFD;\n } else {\n const hexExists = /^([\\da-f]{1,6}\\s?)/i.exec(item);\n if (hexExists) {\n const [, hex] = hexExists;\n let str;\n try {\n const low = parseInt('D800', HEX);\n const high = parseInt('DFFF', HEX);\n const deci = parseInt(hex, HEX);\n if (deci === 0 || (deci >= low && deci <= high)) {\n str = U_FFFD;\n } else {\n str = String.fromCodePoint(deci);\n }\n } catch (e) {\n str = U_FFFD;\n }\n let postStr = '';\n if (item.length > hex.length) {\n postStr = item.substring(hex.length);\n }\n item = `${str}${postStr}`;\n // whitespace\n } else if (/^[\\n\\r\\f]/.test(item)) {\n item = '\\\\' + item;\n }\n }\n arr[i] = item;\n }\n selector = arr.join('');\n }\n return selector;\n};\n\n/**\n * preprocess\n * @see https://drafts.csswg.org/css-syntax-3/#input-preprocessing\n * @param {...*} args - arguments\n * @returns {string} - filtered selector string\n */\nexport const preprocess = (...args) => {\n if (!args.length) {\n throw new TypeError('1 argument required, but only 0 present.');\n }\n let [selector] = args;\n if (typeof selector === 'string') {\n let index = 0;\n while (index >= 0) {\n index = selector.indexOf('#', index);\n if (index < 0) {\n break;\n }\n const preHash = selector.substring(0, index + 1);\n let postHash = selector.substring(index + 1);\n const codePoint = postHash.codePointAt(0);\n // @see https://drafts.csswg.org/selectors/#id-selectors\n // @see https://drafts.csswg.org/css-syntax-3/#ident-token-diagram\n if (codePoint === BIT_HYPHEN) {\n if (/^\\d$/.test(postHash.substring(1, 2))) {\n throw new DOMException(`Invalid selector ${selector}`, SYNTAX_ERR);\n }\n // escape char above 0xFFFF\n } else if (codePoint > BIT_FFFF) {\n const str = `\\\\${codePoint.toString(HEX)} `;\n if (postHash.length === DUO) {\n postHash = str;\n } else {\n postHash = `${str}${postHash.substring(DUO)}`;\n }\n }\n selector = `${preHash}${postHash}`;\n index++;\n }\n selector = selector.replace(/\\f|\\r\\n?/g, '\\n')\n .replace(/[\\0\\uD800-\\uDFFF]|\\\\$/g, U_FFFD);\n } else if (selector === undefined || selector === null) {\n selector = Object.prototype.toString.call(selector)\n .slice(TYPE_FROM, TYPE_TO).toLowerCase();\n } else if (Array.isArray(selector)) {\n selector = selector.join(',');\n } else if (Object.prototype.hasOwnProperty.call(selector, 'toString')) {\n selector = selector.toString();\n } else {\n throw new DOMException(`Invalid selector ${selector}`, SYNTAX_ERR);\n }\n return selector;\n};\n\n/**\n * create AST from CSS selector\n * @param {string} selector - CSS selector\n * @returns {object} - AST\n */\nexport const parseSelector = selector => {\n selector = preprocess(selector);\n // invalid selectors\n if (/^$|^\\s*>|,\\s*$/.test(selector)) {\n throw new DOMException(`Invalid selector ${selector}`, SYNTAX_ERR);\n }\n let res;\n try {\n const ast = parse(selector, {\n context: 'selectorList',\n parseCustomProperty: true\n });\n res = toPlainObject(ast);\n } catch (e) {\n // workaround for https://github.com/csstree/csstree/issues/265\n // NOTE: still throws on `:lang(\"\")`;\n const regLang = /(:lang\\(\\s*(\"[A-Za-z\\d\\-*]+\")\\s*\\))/;\n if (e.message === 'Identifier is expected' && regLang.test(selector)) {\n const [, lang, range] = regLang.exec(selector);\n const escapedRange =\n range.replaceAll('*', '\\\\*').replace(/^\"/, '').replace(/\"$/, '');\n const escapedLang = lang.replace(range, escapedRange);\n res = parseSelector(selector.replace(lang, escapedLang));\n } else if (e.message === '\"]\" is expected' && !selector.endsWith(']')) {\n res = parseSelector(`${selector}]`);\n } else if (e.message === '\")\" is expected' && !selector.endsWith(')')) {\n res = parseSelector(`${selector})`);\n } else {\n throw new DOMException(e.message, SYNTAX_ERR);\n }\n }\n return res;\n};\n\n/**\n * walk AST\n * @param {object} ast - AST\n * @returns {Array.<object|undefined>} - collection of AST branches\n */\nexport const walkAST = (ast = {}) => {\n const branches = new Set();\n let hasPseudoFunc;\n const opt = {\n enter: node => {\n if (node.type === SELECTOR) {\n branches.add(node.children);\n } else if ((node.type === SELECTOR_PSEUDO_CLASS &&\n REG_LOGICAL_PSEUDO.test(node.name)) ||\n (node.type === SELECTOR_PSEUDO_ELEMENT &&\n REG_SHADOW_PSEUDO.test(node.name))) {\n hasPseudoFunc = true;\n }\n }\n };\n walk(ast, opt);\n if (hasPseudoFunc) {\n findAll(ast, (node, item, list) => {\n if (list) {\n if (node.type === SELECTOR_PSEUDO_CLASS &&\n REG_LOGICAL_PSEUDO.test(node.name)) {\n const itemList = list.filter(i => {\n const { name, type } = i;\n const res =\n type === SELECTOR_PSEUDO_CLASS && REG_LOGICAL_PSEUDO.test(name);\n return res;\n });\n for (const { children } of itemList) {\n // SelectorList\n for (const { children: grandChildren } of children) {\n // Selector\n for (const { children: greatGrandChildren } of grandChildren) {\n if (branches.has(greatGrandChildren)) {\n branches.delete(greatGrandChildren);\n }\n }\n }\n }\n } else if (node.type === SELECTOR_PSEUDO_ELEMENT &&\n REG_SHADOW_PSEUDO.test(node.name)) {\n const itemList = list.filter(i => {\n const { name, type } = i;\n const res =\n type === SELECTOR_PSEUDO_ELEMENT && REG_SHADOW_PSEUDO.test(name);\n return res;\n });\n for (const { children } of itemList) {\n // Selector\n for (const { children: grandChildren } of children) {\n if (branches.has(grandChildren)) {\n branches.delete(grandChildren);\n }\n }\n }\n }\n }\n });\n }\n return [...branches];\n};\n\n/**\n * sort AST\n * @param {Array.<object>} asts - collection of AST\n * @returns {Array.<object>} - collection of sorted AST\n */\nexport const sortAST = asts => {\n const arr = [...asts];\n if (arr.length > 1) {\n const order = new Map([\n [SELECTOR_PSEUDO_ELEMENT, BIT_01],\n [SELECTOR_ID, BIT_02],\n [SELECTOR_CLASS, BIT_04],\n [SELECTOR_TYPE, BIT_08],\n [SELECTOR_ATTR, BIT_16],\n [SELECTOR_PSEUDO_CLASS, BIT_32]\n ]);\n arr.sort((a, b) => {\n const { type: typeA } = a;\n const { type: typeB } = b;\n const bitA = order.get(typeA);\n const bitB = order.get(typeB);\n let res;\n if (bitA === bitB) {\n res = 0;\n } else if (bitA > bitB) {\n res = 1;\n } else {\n res = -1;\n }\n return res;\n });\n }\n return arr;\n};\n\n/**\n * parse AST name - e.g. ns|E -> { prefix: ns, localName: E }\n * @private\n * @param {string} selector - type selector\n * @returns {object} - node properties\n */\nexport const parseAstName = selector => {\n let prefix;\n let localName;\n if (selector && typeof selector === 'string') {\n if (selector.indexOf('|') > -1) {\n [prefix, localName] = selector.split('|');\n } else {\n prefix = '*';\n localName = selector;\n }\n } else {\n throw new DOMException(`Invalid selector ${selector}`, SYNTAX_ERR);\n }\n return {\n prefix,\n localName\n };\n};\n\n/* export */\nexport { generate as generateCSS } from 'css-tree';\n"],
|
|
5
|
+
"mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,6CAAAE,EAAA,kBAAAC,EAAA,eAAAC,EAAA,YAAAC,EAAA,qBAAAC,EAAA,YAAAC,IAAA,eAAAC,EAAAR,GAKA,IAAAS,EAAoD,oBAGpDC,EAKO,yBA6QPD,EAAwC,oBAtQjC,MAAMH,EAAmB,CAACK,EAAW,KAAO,CACjD,GAAI,OAAOA,GAAa,UAAYA,EAAS,QAAQ,KAAM,CAAC,G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exports", "__export", "parseAstName", "parseSelector", "preprocess", "sortAST", "unescapeSelector", "walkAST", "__toCommonJS", "import_css_tree", "import_constant", "selector", "arr", "l", "item", "hexExists", "hex", "str", "low", "high", "deci", "postStr", "args", "index", "preHash", "postHash", "codePoint", "res", "ast", "e", "regLang", "lang", "range", "escapedRange", "escapedLang", "branches", "hasPseudoFunc", "node", "list", "itemList", "i", "name", "type", "children", "grandChildren", "greatGrandChildren", "asts", "order", "a", "b", "typeA", "typeB", "bitA", "bitB", "prefix", "localName"]
|
|
7
7
|
}
|
package/package.json
CHANGED