site/node_modules/@asamuzakjp/dom-selector/dist/cjs/js/matcher.js.map

8 lines
137 KiB
Plaintext
Raw Permalink Normal View History

2024-10-14 06:09:33 +00:00
{
"version": 3,
"sources": ["../../../src/js/matcher.js"],
"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';\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 #shadow;\n #tree;\n #warn;\n #window;\n\n /**\n * construct\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} [opt] - options\n * @param {boolean} [opt.warn] - console warn\n */\n constructor(selector, node, opt = {}) {\n const { warn } = opt;\n this.#bit = new Map([\n [SELECTOR_PSEUDO_ELEMENT, BIT_01],\n [SELECTOR_ID, BIT_02],\n [SELECTOR_CLASS, BIT_04],\n [SELECTOR_TYPE, BIT_08],\n [SELECTOR_ATTR, BIT_16],\n [SELECTOR_PSEUDO_CLASS, BIT_32]\n ]);\n this.#cache = new WeakMap();\n this.#node = node;\n [this.#window, this.#document, this.#root, this.#tree] = this._setup(node);\n this.#shadow = isInShadowTree(node);\n [this.#ast, this.#nodes] = this._correspond(selector);\n this.#warn = !!warn;\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 e instanceof this.#window.DOMException) &&\n e.name === NOT_SUPPORTED_ERR) {\n if (this.#warn) {\n console.warn(e.message);\n }\n } else if (e instanceof DOMException) {\n throw new this.#window.DOMException(e.message, e.name);\n } else if (e instanceof TypeError) {\n throw new this.#window.TypeError(e.message);\n } else {\n throw e;\n }\n }\n\n /**\n * set up #window, #document, #root, #walker\n * @param {object} node - Document, DocumentFragment, Element node\n * @returns {Array.<object>} - array of #window, #document, #root, #walker\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 (par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ACpB,KAAO6B,GAAS,CACd,GAAIA,IAAY7B,EAAM,CACpB4B,EAAUC,EACV,KACF,CACAA,EAAUpB,EAAO,SAAS,CAC5B,MAEAmB,EAAUC,CAEd,CACA,OAAOD,GAAW,IACpB,CAYA,iBAAiBE,EAAK9B,EAAM,CAC1B,KAAM,CAAE,EAAAY,EAAG,EAAAC,EAAG,QAAAkB,EAAS,SAAAhC,CAAS,EAAI+B,EAC9B,CAAE,WAAAE,CAAW,EAAIhC,EACvB,IAAIiC,EAAU,IAAI,IACdC,EASJ,GARInC,IACE,KAAKV,GAAO,IAAIU,CAAQ,EAC1BmC,EAAmB,KAAK7C,GAAO,IAAIU,CAAQ,GAE3CmC,KAAmB,WAAQnC,CAAQ,EACnC,KAAKV,GAAO,IAAIU,EAAUmC,CAAgB,IAG1CF,EAAY,CACd,MAAMxB,EAAS,gBAAgB,yBAAyB,eAClDC,EAAS,KAAKnB,GAAU,iBAAiB0C,EAAYxB,CAAM,EACjE,IAAI2B,EAAI,EACJN,EAAUpB,EAAO,WAAW,EAChC,KAAOoB,GACLM,IACAN,EAAUpB,EAAO,YAAY,EAE/BoB,EAAU,KAAK,UAAUG,EAAYvB,CAAM,EAC3C,MAAM2B,EAAgB,IAAI,IAC1B,GAAIF,EAGF,IAFAL,EAAU,KAAK,UAAUG,EAAYvB,CAAM,EAC3CoB,EAAUpB,EAAO,WAAW,EACrBoB,GAAS,CACd,IAAIQ,EACJ,UAAW3B,KAAUwB,EAEnB,GADAG,EAAO,KAAK,aAAa3B,EAAQmB,CAAO,EACpC,CAACQ,EACH,MAGAA,GACFD,EAAc,IAAIP,CAAO,EAE3BA,EAAUpB,EAAO,YAAY,CAC/B,CAGF,GAAIG,IAAM,GACR,GA
"names": ["matcher_exports", "__export", "Matcher", "__toCommonJS", "import_is_potential_custom_element_name", "import_dom_util", "import_parser", "import_constant", "DIR_NEXT", "DIR_PREV", "TARGET_ALL", "TARGET_FIRST", "TARGET_LINEAL", "TARGET_SELF", "#ast", "#bit", "#cache", "#document", "#finder", "#node", "#nodes", "#root", "#shadow", "#tree", "#warn", "#window", "selector", "node", "opt", "warn", "e", "document", "root", "parent", "msg", "filter", "walker", "leaves", "arr", "a", "b", "typeA", "typeB", "bitA", "bitB", "res", "cssAst", "branches", "ast", "nodes", "i", "items", "branch", "item", "nextItem", "current", "refNode", "anb", "reverse", "parentNode", "matched", "selectorBranches", "l", "selectorNodes", "bool", "nth", "j", "m", "localName", "prefix", "itemLocalName", "itemPrefix", "nthName", "nthIdentName", "identName", "anbMap", "astName", "forgive", "dir", "langPart", "regExtendedLang", "langMain", "langSub", "langRest", "extendedMain", "extendedSub", "len", "extendedRest", "value", "leaf", "leafType", "combo", "twigLeaves", "itemType", "twig", "nextNode", "astData", "twigBranches", "lastIndex", "nextNodes", "astChildren", "selectors", "css", "leavesSet", "regAnchor", "regFormCtrl", "regFormValidity", "regInteract", "regTypeCheck", "regTypeDate", "regTypeRange", "regTypeText", "href", "origin", "pathname", "attrURL", "hash", "id", "isCustomElementName", "targetNode", "nodeName", "checked", "regTypeReset", "regTypeSubmit", "form", "isMultiple", "defaultOpt", "inputType", "node1", "node2", "astFlags", "astMatcher", "astValue", "attributes", "caseInsensitive", "astAttrName", "attrValues", "astAttrPrefix", "astAttrLocalName", "itemName", "itemValue", "itemNamePrefix", "itemNameLocalName", "astAttrIdentValue", "astAttrStringValue", "attrValue", "astPrefix", "astNodeName", "nodePrefix", "host", "astType", "baseNode", "filterLeaves", "leafName", "compound", "pending", "comboName", "matchedNode", "targetType", "filtered", "branchLen", "complex", "firstTwig", "firstCombo", "firstType", "lastTwig", "lastType", "sibling", "pendingItems", "pendingItem", "index", "find", "entryNodes", "n", "entryLeaves", "nextCombo", "entryNode"]
}