@asamuzakjp/dom-selector 5.2.2 → 5.3.0
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/finder.js +1 -1
- package/dist/cjs/js/finder.js.map +3 -3
- package/dist/cjs/js/matcher.js +1 -1
- package/dist/cjs/js/matcher.js.map +2 -2
- package/dist/cjs/js/parser.js +2 -2
- package/dist/cjs/js/parser.js.map +3 -3
- package/dist/cjs/js/utility.js +1 -1
- package/dist/cjs/js/utility.js.map +3 -3
- package/package.json +1 -1
- package/src/index.js +3 -1
- package/src/js/constant.js +11 -40
- package/src/js/finder.js +51 -40
- package/src/js/matcher.js +7 -6
- package/src/js/parser.js +22 -22
- package/src/js/utility.js +17 -17
- package/types/js/constant.d.ts +11 -36
package/dist/cjs/js/matcher.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var y=Object.defineProperty;var
|
|
1
|
+
var y=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var S=(x,t)=>{for(var e in t)y(x,e,{get:t[e],enumerable:!0})},A=(x,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let l of N(t))!L.call(x,l)&&l!==e&&y(x,l,{get:()=>t[l],enumerable:!(s=T(t,l))||s.enumerable});return x};var O=x=>A(y({},"__esModule",{value:!0}),x);var C={};S(C,{Matcher:()=>R});module.exports=O(C);var b=require("./parser.js"),$=require("./utility.js"),i=require("./constant.js");class R{matchPseudoElementSelector(t,e={}){if(!t||typeof t!="string")throw new TypeError(`Unexpected type ${(0,$.getType)(t)}`);const{forgive:s,warn:l}=e;switch(t){case"after":case"backdrop":case"before":case"cue":case"cue-region":case"first-letter":case"first-line":case"file-selector-button":case"marker":case"placeholder":case"selection":case"target-text":{if(l)throw new DOMException(`Unsupported pseudo-element ::${t}`,i.NOT_SUPPORTED_ERR);break}case"part":case"slotted":{if(l)throw new DOMException(`Unsupported pseudo-element ::${t}()`,i.NOT_SUPPORTED_ERR);break}default:if(t.startsWith("-webkit-")){if(l)throw new DOMException(`Unsupported pseudo-element ::${t}`,i.NOT_SUPPORTED_ERR)}else if(!s)throw new DOMException(`Unknown pseudo-element ::${t}`,i.SYNTAX_ERR)}}_matchAttributeSelector(t,e){const{flags:s,matcher:l,name:p,value:d}=t;if(typeof s=="string"&&!/^[is]$/i.test(s)){const w=(0,b.generateCSS)(t);throw new DOMException(`Invalid selector ${w}`,i.SYNTAX_ERR)}const{attributes:m}=e;let h;if(m&&m.length){const w=e.ownerDocument.contentType;let n;w==="text/html"?typeof s=="string"&&/^s$/i.test(s)?n=!1:n=!0:typeof s=="string"&&/^i$/i.test(s)?n=!0:n=!1;let g=(0,b.unescapeSelector)(p.name);n&&(g=g.toLowerCase());const f=new Set;if(g.indexOf("|")>-1){const{prefix:o,localName:c}=(0,b.parseAstName)(g);for(const a of m){let{name:r,value:u}=a;switch(n&&(r=r.toLowerCase(),u=u.toLowerCase()),o){case"":{c===r&&f.add(u);break}case"*":{r.indexOf(":")>-1?r.endsWith(`:${c}`)&&f.add(u):c===r&&f.add(u);break}default:if(r.indexOf(":")>-1){const[k,E]=r.split(":");if(k==="xml"&&E==="lang")continue;o===k&&c===E&&(0,$.isNamespaceDeclared)(o,e)&&f.add(u)}}}}else for(let{name:o,value:c}of m)if(n&&(o=o.toLowerCase(),c=c.toLowerCase()),o.indexOf(":")>-1){const[a,r]=o.split(":");if(a==="xml"&&r==="lang")continue;g===r&&f.add(c)}else g===o&&f.add(c);if(f.size){const{name:o,value:c}=d??{};let a;switch(o?n?a=o.toLowerCase():a=o:c?n?a=c.toLowerCase():a=c:c===""&&(a=c),l){case"=":{typeof a=="string"&&f.has(a)&&(h=e);break}case"~=":{if(a&&typeof a=="string"){for(const r of f)if(new Set(r.split(/\s+/)).has(a)){h=e;break}}break}case"|=":{if(a&&typeof a=="string"){let r;for(const u of f)if(u===a||u.startsWith(`${a}-`)){r=u;break}r&&(h=e)}break}case"^=":{if(a&&typeof a=="string"){let r;for(const u of f)if(u.startsWith(`${a}`)){r=u;break}r&&(h=e)}break}case"$=":{if(a&&typeof a=="string"){let r;for(const u of f)if(u.endsWith(`${a}`)){r=u;break}r&&(h=e)}break}case"*=":{if(a&&typeof a=="string"){let r;for(const u of f)if(u.includes(`${a}`)){r=u;break}r&&(h=e)}break}case null:default:h=e}}}return h??null}_matchTypeSelector(t,e,s={}){const l=(0,b.unescapeSelector)(t.name),{localName:p,namespaceURI:d,prefix:m}=e,{forgive:h}=s;let{prefix:w,localName:n}=(0,b.parseAstName)(l,e);e.ownerDocument.contentType==="text/html"&&/[A-Z][\\w-]*/i.test(p)&&(w=w.toLowerCase(),n=n.toLowerCase());let g,f;p.indexOf(":")>-1?[g,f]=p.split(":"):(g=m||"",f=p);let o;switch(w){case"":{!g&&!d&&(n==="*"||n===f)&&(o=e);break}case"*":{(n==="*"||n===f)&&(o=e);break}default:{const c=e.lookupNamespaceURI(w),a=e.lookupNamespaceURI(g);if(c===a&&w===g)(n==="*"||n===f)&&(o=e);else if(!h&&!c)throw new DOMException(`Undeclared namespace ${w}`,i.SYNTAX_ERR)}}return o??null}_matchDirectionPseudoClass(t,e){const s=(0,$.getDirectionality)(e);let l;return t.name===s&&(l=e),l??null}_matchLanguagePseudoClass(t,e){if(t.name===i.EMPTY)return null;const s=(0,b.unescapeSelector)(t.name);typeof s=="string"&&s!==t.name&&(t.name=s);let l;if(s==="*")if(e.hasAttribute("lang"))e.getAttribute("lang")&&(l=e);else{let p=e.parentNode;for(;p&&p.nodeType===i.ELEMENT_NODE;){if(p.hasAttribute("lang")){p.getAttribute("lang")&&(l=e);break}p=p.parentNode}}else if(s&&new RegExp(`^(?:\\*-)?${i.ALPHA_NUM}${i.LANG_PART}$`,"i").test(s)){let d;if(s.indexOf("-")>-1){const[m,h,...w]=s.split("-");let n;m==="*"?n=`${i.ALPHA_NUM}${i.LANG_PART}`:n=`${m}${i.LANG_PART}`;const g=`-${h}${i.LANG_PART}`,f=w.length;let o="";if(f)for(let c=0;c<f;c++)o+=`-${w[c]}${i.LANG_PART}`;d=new RegExp(`^${n}${g}${o}$`,"i")}else d=new RegExp(`^${s}${i.LANG_PART}$`,"i");if(e.hasAttribute("lang"))d.test(e.getAttribute("lang"))&&(l=e);else{let m=e.parentNode;for(;m&&m.nodeType===i.ELEMENT_NODE;){if(m.hasAttribute("lang")){const h=m.getAttribute("lang");d.test(h)&&(l=e);break}m=m.parentNode}}}return l??null}matchSelector(t,e,s={},l=!1){if(!l){if(!t||!t.type)throw new TypeError(`Unexpected ast type ${(0,$.getType)(t)}`);if(!e||!e.nodeType)throw new TypeError(`Unexpected node type ${(0,$.getType)(e)}`);if(e.nodeType!==i.ELEMENT_NODE)throw new TypeError(`Unexpected node ${e.nodeName}`)}let p;switch(t.type){case i.ATTR_SELECTOR:{p=this._matchAttributeSelector(t,e);break}case i.TYPE_SELECTOR:{p=this._matchTypeSelector(t,e,s??{});break}default:{const{children:[d],name:m}=t;m==="dir"?p=this._matchDirectionPseudoClass(d,e):m==="lang"&&(p=this._matchLanguagePseudoClass(d,e))}}return p}}0&&(module.exports={Matcher});
|
|
2
2
|
//# sourceMappingURL=matcher.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/js/matcher.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * matcher.js\n */\n\n/* import */\nimport { generateCSS, parseAstName, unescapeSelector } from './parser.js';\nimport { getDirectionality, getType, isNamespaceDeclared } from './utility.js';\n\n/* constants */\nimport {\n ALPHA_NUM, ELEMENT_NODE, EMPTY, LANG_PART, NOT_SUPPORTED_ERR, REG_LANG,\n REG_TAG_NAME, SELECTOR_ATTR, SELECTOR_TYPE, SYNTAX_ERR\n} from './constant.js';\n\n/* Matcher */\nexport class Matcher {\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 */\n matchPseudoElementSelector(astName, opt = {}) {\n if (!astName || typeof astName !== 'string') {\n throw new TypeError(`Unexpected type ${getType(astName)}`);\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 throw new DOMException(`Unsupported pseudo-element ::${astName}`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n case 'part':\n case 'slotted': {\n if (warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}()`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}`,\n NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n throw new DOMException(`Unknown pseudo-element ::${astName}`,\n SYNTAX_ERR);\n }\n }\n }\n }\n\n /**\n * match attribute selector\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchAttributeSelector(ast, node) {\n const {\n flags: astFlags, matcher: astMatcher, name: astName, value: astValue\n } = ast;\n if (typeof astFlags === 'string' && !/^[is]$/i.test(astFlags)) {\n const css = generateCSS(ast);\n throw new DOMException(`Invalid selector ${css}`, SYNTAX_ERR);\n }\n const { attributes } = node;\n let res;\n if (attributes && attributes.length) {\n const 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 =\n isNamespaceDeclared(astPrefix, node);\n if (namespaceDeclared) {\n attrValues.add(itemValue);\n }\n }\n }\n }\n }\n }\n } else {\n for (let { name: itemName, value: itemValue } of attributes) {\n if (caseInsensitive) {\n itemName = itemName.toLowerCase();\n itemValue = itemValue.toLowerCase();\n }\n if (itemName.indexOf(':') > -1) {\n const [itemPrefix, itemLocalName] = itemName.split(':');\n // ignore xml:lang\n if (itemPrefix === 'xml' && itemLocalName === 'lang') {\n continue;\n } else if (astAttrName === itemLocalName) {\n attrValues.add(itemValue);\n }\n } else if (astAttrName === itemName) {\n attrValues.add(itemValue);\n }\n }\n }\n if (attrValues.size) {\n const { name: astIdentValue, value: astStringValue } = astValue ?? {};\n let attrValue;\n if (astIdentValue) {\n if (caseInsensitive) {\n attrValue = astIdentValue.toLowerCase();\n } else {\n attrValue = astIdentValue;\n }\n } else if (astStringValue) {\n if (caseInsensitive) {\n attrValue = astStringValue.toLowerCase();\n } else {\n attrValue = astStringValue;\n }\n } else if (astStringValue === '') {\n attrValue = astStringValue;\n }\n switch (astMatcher) {\n case '=': {\n if (typeof attrValue === 'string' && attrValues.has(attrValue)) {\n res = node;\n }\n break;\n }\n case '~=': {\n if (attrValue && typeof attrValue === 'string') {\n for (const value of attrValues) {\n const item = new Set(value.split(/\\s+/));\n if (item.has(attrValue)) {\n res = node;\n break;\n }\n }\n }\n break;\n }\n case '|=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value === attrValue || value.startsWith(`${attrValue}-`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '^=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.startsWith(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '$=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.endsWith(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '*=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.includes(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case null:\n default: {\n res = node;\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * match type selector\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {object} opt - options\n * @param {boolean} [opt.forgive] - forgive undeclared namespace\n * @returns {?object} - matched node\n */\n _matchTypeSelector(ast, node, opt = {}) {\n const astName = unescapeSelector(ast.name);\n const { localName, namespaceURI, prefix } = node;\n const { forgive } = opt;\n let {\n prefix: astPrefix, localName: astLocalName\n } = parseAstName(astName, node);\n if (node.ownerDocument.contentType === 'text/html' &&\n REG_TAG_NAME.test(localName)) {\n astPrefix = astPrefix.toLowerCase();\n astLocalName = astLocalName.toLowerCase();\n }\n let nodePrefix;\n let nodeLocalName;\n // just in case that the namespaced content is parsed as text/html\n if (localName.indexOf(':') > -1) {\n [nodePrefix, nodeLocalName] = localName.split(':');\n } else {\n nodePrefix = prefix || '';\n nodeLocalName = localName;\n }\n let res;\n switch (astPrefix) {\n case '': {\n if (!nodePrefix && !namespaceURI &&\n (astLocalName === '*' || astLocalName === nodeLocalName)) {\n res = node;\n }\n break;\n }\n case '*': {\n if (astLocalName === '*' || astLocalName === nodeLocalName) {\n res = node;\n }\n break;\n }\n default: {\n const astNS = node.lookupNamespaceURI(astPrefix);\n const nodeNS = node.lookupNamespaceURI(nodePrefix);\n if (astNS === nodeNS && astPrefix === nodePrefix) {\n if (astLocalName === '*' || astLocalName === nodeLocalName) {\n res = node;\n }\n } else if (!forgive && !astNS) {\n throw new DOMException(`Undeclared namespace ${astPrefix}`,\n SYNTAX_ERR);\n }\n }\n }\n return res ?? null;\n };\n\n /**\n * match directionality pseudo-class - :dir()\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchDirectionPseudoClass(ast, node) {\n const dir = getDirectionality(node);\n let res;\n if (ast.name === 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 * @private\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchLanguagePseudoClass(ast, node) {\n if (ast.name === EMPTY) {\n return null;\n }\n const astName = unescapeSelector(ast.name);\n if (typeof astName === 'string' && astName !== ast.name) {\n ast.name = astName;\n }\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 if (REG_LANG.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}${LANG_PART}`;\n } else {\n extendedMain = `${langMain}${LANG_PART}`;\n }\n const extendedSub = `-${langSub}${LANG_PART}`;\n const len = langRest.length;\n let extendedRest = '';\n if (len) {\n for (let i = 0; i < len; i++) {\n extendedRest += `-${langRest[i]}${LANG_PART}`;\n }\n }\n regExtendedLang =\n new RegExp(`^${extendedMain}${extendedSub}${extendedRest}$`, 'i');\n } else {\n regExtendedLang = new RegExp(`^${astName}${LANG_PART}$`, '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 selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {object} opt - options\n * @param {boolean} validated - args are validated\n * @returns {?object} - matched node\n */\n matchSelector(ast, node, opt = {}, validated = false) {\n if (!validated) {\n if (!ast || !ast.type) {\n throw new TypeError(`Unexpected ast type ${getType(ast)}`);\n } else if (!node || !node.nodeType) {\n throw new TypeError(`Unexpected node type ${getType(node)}`);\n } else if (node.nodeType !== ELEMENT_NODE) {\n throw new TypeError(`Unexpected node ${node.nodeName}`);\n }\n }\n let matched;\n switch (ast.type) {\n case SELECTOR_ATTR: {\n matched = this._matchAttributeSelector(ast, node);\n break;\n }\n case SELECTOR_TYPE: {\n matched = this._matchTypeSelector(ast, node, opt ?? {});\n break;\n }\n default: {\n const { children: [child], name: astName } = ast;\n if (astName === 'dir') {\n matched = this._matchDirectionPseudoClass(child, node);\n } else if (astName === 'lang') {\n matched = this._matchLanguagePseudoClass(child, node);\n }\n }\n }\n return matched;\n }\n}\n"],
|
|
5
|
-
"mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAKA,IAAAI,EAA4D,uBAC5DC,EAAgE,wBAGhEC,EAGO,yBAGA,MAAMJ,CAAQ,CAUnB,2BAA2BK,EAASC,EAAM,CAAC,EAAG,CAC5C,GAAI,CAACD,GAAW,OAAOA,GAAY,SACjC,MAAM,IAAI,UAAU,sBAAmB,WAAQA,CAAO,CAAC,EAAE,EAE3D,KAAM,CAAE,QAAAE,EAAS,KAAAC,CAAK,EAAIF,EAC1B,OAAQD,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,GAAIG,EACF,MAAM,IAAI,aAAa,gCAAgCH,CAAO,GAC5D,mBAAiB,EAErB,KACF,CACA,IAAK,OACL,IAAK,UAAW,CACd,GAAIG,EACF,MAAM,IAAI,aAAa,gCAAgCH,CAAO,KAC5D,mBAAiB,EAErB,KACF,CACA,QACE,GAAIA,EAAQ,WAAW,UAAU,GAC/B,GAAIG,EACF,MAAM,IAAI,aAAa,gCAAgCH,CAAO,GAC5D,mBAAiB,UAEZ,CAACE,EACV,MAAM,IAAI,aAAa,4BAA4BF,CAAO,GACxD,YAAU,CAGlB,CACF,CASA,wBAAwBI,EAAKC,EAAM,CACjC,KAAM,CACJ,MAAOC,EAAU,QAASC,EAAY,KAAMP,EAAS,MAAOQ,CAC9D,EAAIJ,EACJ,GAAI,OAAOE,GAAa,UAAY,CAAC,UAAU,KAAKA,CAAQ,EAAG,CAC7D,MAAMG,KAAM,eAAYL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EAAG,CACpCP,EAAOQ,EACP,KACF,CAEER,IACFP,EAAMN,EAEV,CACA,KACF,CACA,IAAK,KAAM,CACT,GAAIoB,GAAa,OAAOA,GAAc,SAAU,CAC9C,IAAIP,EACJ,UAAWQ,KAASX,EAClB,GAAIW,EAAM,SAAS,GAAGD,CAAS,EAAE,EAAG,CAClCP,EAAOQ,EACP,KACF,CAEER,IACFP,EAAMN,EAEV,CACA,KACF,CACA,IAAK,KAAM,CACT,GAAIoB,GAAa,OAAOA,GAAc,SAAU,CAC9C,IAAIP,EACJ,UAAWQ,KAASX,EAClB,GAAIW,EAAM,SAAS,GAAGD,CAAS,EAAE,EAAG,CAClCP,EAAOQ,EACP,KACF,CAEER,IACFP,EAAMN,EAEV,CACA,KACF,CACA,KAAK,KACL,QACEM,EAAMN,CAEV,CACF,CACF,CACA,OAAOM,GAAO,IAChB,CAWA,mBAAmBP,EAAKC,EAAMJ,EAAM,CAAC,EAAG,CACtC,MAAMD,KAAU,oBAAiBI,EAAI,IAAI,EACnC,CAAE,UAAAuB,EAAW,aAAAC,EAAc,OAAAC,CAAO,EAAIxB,EACtC,CAAE,QAAAH,CAAQ,EAAID,EACpB,GAAI,CACF,OAAQe,EAAW,UAAWC,CAChC,KAAI,gBAAajB,EAASK,CAAI,EAC1BA,EAAK,cAAc,cAAgB,aACnC,
|
|
4
|
+
"sourcesContent": ["/**\n * matcher.js\n */\n\n/* import */\nimport { generateCSS, parseAstName, unescapeSelector } from './parser.js';\nimport { getDirectionality, getType, isNamespaceDeclared } from './utility.js';\n\n/* constants */\nimport {\n ALPHA_NUM, ATTR_SELECTOR, ELEMENT_NODE, EMPTY, LANG_PART, NOT_SUPPORTED_ERR,\n SYNTAX_ERR, TYPE_SELECTOR\n} from './constant.js';\n\n/* Matcher */\nexport class Matcher {\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 */\n matchPseudoElementSelector(astName, opt = {}) {\n if (!astName || typeof astName !== 'string') {\n throw new TypeError(`Unexpected type ${getType(astName)}`);\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 throw new DOMException(`Unsupported pseudo-element ::${astName}`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n case 'part':\n case 'slotted': {\n if (warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}()`,\n NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (warn) {\n throw new DOMException(`Unsupported pseudo-element ::${astName}`,\n NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n throw new DOMException(`Unknown pseudo-element ::${astName}`,\n SYNTAX_ERR);\n }\n }\n }\n }\n\n /**\n * match attribute selector\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchAttributeSelector(ast, node) {\n const {\n flags: astFlags, matcher: astMatcher, name: astName, value: astValue\n } = ast;\n if (typeof astFlags === 'string' && !/^[is]$/i.test(astFlags)) {\n const css = generateCSS(ast);\n throw new DOMException(`Invalid selector ${css}`, SYNTAX_ERR);\n }\n const { attributes } = node;\n let res;\n if (attributes && attributes.length) {\n const 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 =\n isNamespaceDeclared(astPrefix, node);\n if (namespaceDeclared) {\n attrValues.add(itemValue);\n }\n }\n }\n }\n }\n }\n } else {\n for (let { name: itemName, value: itemValue } of attributes) {\n if (caseInsensitive) {\n itemName = itemName.toLowerCase();\n itemValue = itemValue.toLowerCase();\n }\n if (itemName.indexOf(':') > -1) {\n const [itemPrefix, itemLocalName] = itemName.split(':');\n // ignore xml:lang\n if (itemPrefix === 'xml' && itemLocalName === 'lang') {\n continue;\n } else if (astAttrName === itemLocalName) {\n attrValues.add(itemValue);\n }\n } else if (astAttrName === itemName) {\n attrValues.add(itemValue);\n }\n }\n }\n if (attrValues.size) {\n const { name: astIdentValue, value: astStringValue } = astValue ?? {};\n let attrValue;\n if (astIdentValue) {\n if (caseInsensitive) {\n attrValue = astIdentValue.toLowerCase();\n } else {\n attrValue = astIdentValue;\n }\n } else if (astStringValue) {\n if (caseInsensitive) {\n attrValue = astStringValue.toLowerCase();\n } else {\n attrValue = astStringValue;\n }\n } else if (astStringValue === '') {\n attrValue = astStringValue;\n }\n switch (astMatcher) {\n case '=': {\n if (typeof attrValue === 'string' && attrValues.has(attrValue)) {\n res = node;\n }\n break;\n }\n case '~=': {\n if (attrValue && typeof attrValue === 'string') {\n for (const value of attrValues) {\n const item = new Set(value.split(/\\s+/));\n if (item.has(attrValue)) {\n res = node;\n break;\n }\n }\n }\n break;\n }\n case '|=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value === attrValue || value.startsWith(`${attrValue}-`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '^=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.startsWith(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '$=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.endsWith(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '*=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.includes(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case null:\n default: {\n res = node;\n }\n }\n }\n }\n return res ?? null;\n }\n\n /**\n * match type selector\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {object} opt - options\n * @param {boolean} [opt.forgive] - forgive undeclared namespace\n * @returns {?object} - matched node\n */\n _matchTypeSelector(ast, node, opt = {}) {\n const astName = unescapeSelector(ast.name);\n const { localName, namespaceURI, prefix } = node;\n const { forgive } = opt;\n let {\n prefix: astPrefix, localName: astLocalName\n } = parseAstName(astName, node);\n if (node.ownerDocument.contentType === 'text/html' &&\n /[A-Z][\\\\w-]*/i.test(localName)) {\n astPrefix = astPrefix.toLowerCase();\n astLocalName = astLocalName.toLowerCase();\n }\n let nodePrefix;\n let nodeLocalName;\n // just in case that the namespaced content is parsed as text/html\n if (localName.indexOf(':') > -1) {\n [nodePrefix, nodeLocalName] = localName.split(':');\n } else {\n nodePrefix = prefix || '';\n nodeLocalName = localName;\n }\n let res;\n switch (astPrefix) {\n case '': {\n if (!nodePrefix && !namespaceURI &&\n (astLocalName === '*' || astLocalName === nodeLocalName)) {\n res = node;\n }\n break;\n }\n case '*': {\n if (astLocalName === '*' || astLocalName === nodeLocalName) {\n res = node;\n }\n break;\n }\n default: {\n const astNS = node.lookupNamespaceURI(astPrefix);\n const nodeNS = node.lookupNamespaceURI(nodePrefix);\n if (astNS === nodeNS && astPrefix === nodePrefix) {\n if (astLocalName === '*' || astLocalName === nodeLocalName) {\n res = node;\n }\n } else if (!forgive && !astNS) {\n throw new DOMException(`Undeclared namespace ${astPrefix}`,\n SYNTAX_ERR);\n }\n }\n }\n return res ?? null;\n };\n\n /**\n * match directionality pseudo-class - :dir()\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchDirectionPseudoClass(ast, node) {\n const dir = getDirectionality(node);\n let res;\n if (ast.name === 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 * @private\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @returns {?object} - matched node\n */\n _matchLanguagePseudoClass(ast, node) {\n if (ast.name === EMPTY) {\n return null;\n }\n const astName = unescapeSelector(ast.name);\n if (typeof astName === 'string' && astName !== ast.name) {\n ast.name = astName;\n }\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 reg = new RegExp(`^(?:\\\\*-)?${ALPHA_NUM}${LANG_PART}$`, 'i');\n if (reg.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}${LANG_PART}`;\n } else {\n extendedMain = `${langMain}${LANG_PART}`;\n }\n const extendedSub = `-${langSub}${LANG_PART}`;\n const len = langRest.length;\n let extendedRest = '';\n if (len) {\n for (let i = 0; i < len; i++) {\n extendedRest += `-${langRest[i]}${LANG_PART}`;\n }\n }\n regExtendedLang =\n new RegExp(`^${extendedMain}${extendedSub}${extendedRest}$`, 'i');\n } else {\n regExtendedLang = new RegExp(`^${astName}${LANG_PART}$`, '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 selector\n * @param {object} ast - AST\n * @param {object} node - Element node\n * @param {object} opt - options\n * @param {boolean} validated - args are validated\n * @returns {?object} - matched node\n */\n matchSelector(ast, node, opt = {}, validated = false) {\n if (!validated) {\n if (!ast || !ast.type) {\n throw new TypeError(`Unexpected ast type ${getType(ast)}`);\n } else if (!node || !node.nodeType) {\n throw new TypeError(`Unexpected node type ${getType(node)}`);\n } else if (node.nodeType !== ELEMENT_NODE) {\n throw new TypeError(`Unexpected node ${node.nodeName}`);\n }\n }\n let matched;\n switch (ast.type) {\n case ATTR_SELECTOR: {\n matched = this._matchAttributeSelector(ast, node);\n break;\n }\n case TYPE_SELECTOR: {\n matched = this._matchTypeSelector(ast, node, opt ?? {});\n break;\n }\n default: {\n const { children: [child], name: astName } = ast;\n if (astName === 'dir') {\n matched = this._matchDirectionPseudoClass(child, node);\n } else if (astName === 'lang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KAAM/C,CAAQ,EAAII,EACzCJ,IAAY,MACd8C,EAAU,KAAK,2BAA2BC,EAAO1C,CAAI,EAC5CL,IAAY,SACrB8C,EAAU,KAAK,0BAA0BC,EAAO1C,CAAI,EAExD,CACF,CACA,OAAOyC,CACT,CACF",
|
|
6
6
|
"names": ["matcher_exports", "__export", "Matcher", "__toCommonJS", "import_parser", "import_utility", "import_constant", "astName", "opt", "forgive", "warn", "ast", "node", "astFlags", "astMatcher", "astValue", "css", "attributes", "res", "contentType", "caseInsensitive", "astAttrName", "attrValues", "astPrefix", "astLocalName", "item", "itemName", "itemValue", "itemPrefix", "itemLocalName", "astIdentValue", "astStringValue", "attrValue", "value", "localName", "namespaceURI", "prefix", "nodePrefix", "nodeLocalName", "astNS", "nodeNS", "dir", "parent", "regExtendedLang", "langMain", "langSub", "langRest", "extendedMain", "extendedSub", "len", "extendedRest", "i", "validated", "matched", "child"]
|
|
7
7
|
}
|
package/dist/cjs/js/parser.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var
|
|
2
|
-
`).replace(/[\0\uD800-\uDFFF]|\\$/g,e.U_FFFD)}else if(t==null)t=(0
|
|
1
|
+
var u=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var _=(s,t)=>{for(var r in t)u(s,r,{get:t[r],enumerable:!0})},L=(s,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of w(t))!y.call(s,n)&&n!==r&&u(s,n,{get:()=>t[n],enumerable:!(o=T(t,n))||o.enumerable});return s};var b=s=>L(u({},"__esModule",{value:!0}),s);var F={};_(F,{generateCSS:()=>O.generate,parseAstName:()=>D,parseSelector:()=>g,preprocess:()=>m,sortAST:()=>C,unescapeSelector:()=>I,walkAST:()=>A});module.exports=b(F);var d=require("css-tree"),$=require("./utility.js"),e=require("./constant.js"),O=require("css-tree");const S=/(:lang\(\s*("[A-Za-z\d\-*]*")\s*\))/,x=/(:(is|where)\(\s*\))/,E=/^part|slotted$/,I=(s="")=>{if(typeof s=="string"&&s.indexOf("\\",0)>=0){const t=s.split("\\"),r=t.length;for(let o=1;o<r;o++){let n=t[o];if(n===""&&o===r-1)n=e.U_FFFD;else{const c=/^([\da-f]{1,6}\s?)/i.exec(n);if(c){const[,f]=c;let a;try{const i=parseInt("D800",e.HEX),p=parseInt("DFFF",e.HEX),h=parseInt(f,e.HEX);h===0||h>=i&&h<=p?a=e.U_FFFD:a=String.fromCodePoint(h)}catch{a=e.U_FFFD}let l="";n.length>f.length&&(l=n.substring(f.length)),n=`${a}${l}`}else/^[\n\r\f]/.test(n)&&(n="\\"+n)}t[o]=n}s=t.join("")}return s},m=(...s)=>{if(!s.length)throw new TypeError("1 argument required, but only 0 present.");let[t]=s;if(typeof t=="string"){let r=0;for(;r>=0&&(r=t.indexOf("#",r),!(r<0));){const o=t.substring(0,r+1);let n=t.substring(r+1);if(/^\d$/.test(n.substring(0,1)))throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR);const c=n.codePointAt(0);if(c===e.HYPHEN){if(/^\d$/.test(n.substring(1,2)))throw new DOMException(`Invalid selector ${t}`,e.SYNTAX_ERR)}else if(c>e.BIT_FFFF){const f=`\\${c.toString(e.HEX)} `;n.length===e.DUO?n=f:n=`${f}${n.substring(e.DUO)}`}t=`${o}${n}`,r++}t=t.replace(/\f|\r\n?/g,`
|
|
2
|
+
`).replace(/[\0\uD800-\uDFFF]|\\$/g,e.U_FFFD)}else if(t==null)t=(0,$.getType)(t).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},g=s=>{if(s=m(s),/^$|^\s*>|,\s*$/.test(s))throw new DOMException(`Invalid selector ${s}`,e.SYNTAX_ERR);let t;try{const r=(0,d.parse)(s,{context:"selectorList",parseCustomProperty:!0});t=(0,d.toPlainObject)(r)}catch(r){const{message:o}=r;if(o==="Identifier is expected"&&S.test(s)){const[,n,c]=S.exec(s),f=c.replaceAll("*","\\*").replace(/^"/,"").replace(/"$/,"");let a=n.replace(c,f);a===":lang()"&&(a=`:lang(${e.EMPTY})`),t=g(s.replace(n,a))}else if(/^(?:Identifier|Selector) is expected$/.test(o)&&x.test(s)){const[,n,c]=x.exec(s);t=g(s.replace(n,`:${c}(${e.EMPTY})`))}else if(/^(?:"\]"|Attribute selector [()\s,=~^$*|]+) is expected$/.test(o)&&!s.endsWith("]")){const n=s.lastIndexOf("["),c=s.substring(n);c.includes('"')?c.match(/"/g).length%2?t=g(`${s}"]`):t=g(`${s}]`):t=g(`${s}]`)}else if(o==='")" is expected'&&!s.endsWith(")"))t=g(`${s})`);else throw new DOMException(o,e.SYNTAX_ERR)}return t},A=(s={})=>{const t=new Set,r=new Map;return(0,d.walk)(s,{enter:n=>{switch(n.type){case e.SELECTOR:{t.add(n.children);break}case e.PS_CLASS_SELECTOR:{e.REG_LOGICAL.test(n.name)&&(r.set("hasNestedSelector",!0),r.set("hasLogicalPseudoFunc",!0),n.name==="has"&&r.set("hasHasPseudoFunc",!0));break}case e.PS_ELEMENT_SELECTOR:{E.test(n.name)&&r.set("hasNestedSelector",!0);break}case e.NTH:{n.selector&&r.set("hasNestedSelector",!0);break}default:}}}),r.get("hasNestedSelector")&&(0,d.findAll)(s,(n,c,f)=>{if(f){if(n.type===e.PS_CLASS_SELECTOR&&e.REG_LOGICAL.test(n.name)){const a=f.filter(l=>{const{name:i,type:p}=l;return p===e.PS_CLASS_SELECTOR&&e.REG_LOGICAL.test(i)});for(const{children:l}of a)for(const{children:i}of l)for(const{children:p}of i)t.has(p)&&t.delete(p)}else if(n.type===e.PS_ELEMENT_SELECTOR&&E.test(n.name)){const a=f.filter(l=>{const{name:i,type:p}=l;return p===e.PS_ELEMENT_SELECTOR&&E.test(i)});for(const{children:l}of a)for(const{children:i}of l)t.has(i)&&t.delete(i)}else if(n.type===e.NTH&&n.selector){const a=f.filter(l=>{const{selector:i,type:p}=l;return p===e.NTH&&i});for(const{selector:l}of a){const{children:i}=l;for(const{children:p}of i)t.has(p)&&t.delete(p)}}}}),{branches:[...t],info:Object.fromEntries(r)}},C=s=>{const t=[...s];if(t.length>1){const r=new Map([[e.PS_ELEMENT_SELECTOR,e.BIT_01],[e.ID_SELECTOR,e.BIT_02],[e.CLASS_SELECTOR,e.BIT_04],[e.TYPE_SELECTOR,e.BIT_08],[e.ATTR_SELECTOR,e.BIT_16],[e.PS_CLASS_SELECTOR,e.BIT_32]]);t.sort((o,n)=>{const{type:c}=o,{type:f}=n,a=r.get(c),l=r.get(f);let i;return a===l?i=0:a>l?i=1:i=-1,i})}return t},D=s=>{let t,r;if(s&&typeof s=="string")s.indexOf("|")>-1?[t,r]=s.split("|"):(t="*",r=s);else throw new DOMException(`Invalid selector ${s}`,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';\nimport { getType } from './utility.js';\n\n/* constants */\nimport {\n BIT_01, BIT_02, BIT_04, BIT_08, BIT_16, BIT_32, BIT_FFFF, BIT_HYPHEN,\n DUO, EMPTY, HEX, NTH, REG_HEX, REG_INVALID_SELECTOR, REG_LANG_QUOTED,\n REG_LOGICAL_EMPTY, REG_LOGICAL_PSEUDO, REG_SHADOW_PSEUDO, SELECTOR,\n SELECTOR_ATTR, SELECTOR_CLASS, SELECTOR_ID, SELECTOR_PSEUDO_CLASS,\n SELECTOR_PSEUDO_ELEMENT, SELECTOR_TYPE, SYNTAX_ERR, 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 = REG_HEX.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 // @see https://drafts.csswg.org/selectors/#id-selectors\n // @see https://drafts.csswg.org/css-syntax-3/#ident-token-diagram\n if (/^\\d$/.test(postHash.substring(0, 1))) {\n throw new DOMException(`Invalid selector ${selector}`, SYNTAX_ERR);\n }\n const codePoint = postHash.codePointAt(0);\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 = getType(selector).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 (REG_INVALID_SELECTOR.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 const { message } = e;\n // workaround for https://github.com/csstree/csstree/issues/265\n if (message === 'Identifier is expected' &&\n REG_LANG_QUOTED.test(selector)) {\n const [, lang, range] = REG_LANG_QUOTED.exec(selector);\n const escapedRange =\n range.replaceAll('*', '\\\\*').replace(/^\"/, '').replace(/\"$/, '');\n let escapedLang = lang.replace(range, escapedRange);\n if (escapedLang === ':lang()') {\n escapedLang = `:lang(${EMPTY})`;\n }\n res = parseSelector(selector.replace(lang, escapedLang));\n } else if (/^(?:Identifier|Selector) is expected$/.test(message) &&\n REG_LOGICAL_EMPTY.test(selector)) {\n const [, sel, name] = REG_LOGICAL_EMPTY.exec(selector);\n res = parseSelector(selector.replace(sel, `:${name}(${EMPTY})`));\n } else if (/^(?:\"\\]\"|Attribute selector [()\\s,=~^$*|]+) is expected$/.test(message) &&\n !selector.endsWith(']')) {\n const index = selector.lastIndexOf('[');\n const sel = selector.substring(index);\n if (sel.includes('\"')) {\n const quotes = sel.match(/\"/g).length;\n if (quotes % 2) {\n res = parseSelector(`${selector}\"]`);\n } else {\n res = parseSelector(`${selector}]`);\n }\n } else {\n res = parseSelector(`${selector}]`);\n }\n } else if (message === '\")\" is expected' && !selector.endsWith(')')) {\n res = parseSelector(`${selector})`);\n } else {\n throw new DOMException(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 const info = new Map();\n const opt = {\n enter: node => {\n switch (node.type) {\n case SELECTOR: {\n branches.add(node.children);\n break;\n }\n case SELECTOR_PSEUDO_CLASS: {\n if (REG_LOGICAL_PSEUDO.test(node.name)) {\n info.set('hasNestedSelector', true);\n info.set('hasLogicalPseudoFunc', true);\n if (node.name === 'has') {\n info.set('hasHasPseudoFunc', true);\n }\n }\n break;\n }\n case SELECTOR_PSEUDO_ELEMENT: {\n if (REG_SHADOW_PSEUDO.test(node.name)) {\n info.set('hasNestedSelector', true);\n }\n break;\n }\n case NTH: {\n if (node.selector) {\n info.set('hasNestedSelector', true);\n }\n break;\n }\n default:\n }\n }\n };\n walk(ast, opt);\n if (info.get('hasNestedSelector')) {\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 } else if (node.type === NTH && node.selector) {\n const itemList = list.filter(i => {\n const { selector, type } = i;\n const res = type === NTH && selector;\n return res;\n });\n for (const { selector } of itemList) {\n const { children } = selector;\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 {\n branches: [...branches],\n info: Object.fromEntries(info)\n };\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 * @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,oBACpDC,EAAwB,wBAGxBC,
|
|
6
|
-
"names": ["parser_exports", "__export", "parseAstName", "parseSelector", "preprocess", "sortAST", "unescapeSelector", "walkAST", "__toCommonJS", "import_css_tree", "import_utility", "import_constant", "selector", "arr", "l", "i", "item", "hexExists", "hex", "str", "low", "high", "deci", "postStr", "args", "index", "preHash", "postHash", "codePoint", "res", "ast", "e", "message", "lang", "range", "escapedRange", "escapedLang", "sel", "name", "branches", "info", "node", "list", "itemList", "type", "children", "grandChildren", "greatGrandChildren", "asts", "order", "a", "b", "typeA", "typeB", "bitA", "bitB", "prefix", "localName"]
|
|
4
|
+
"sourcesContent": ["/**\n * parser.js\n */\n\n/* import */\nimport { findAll, parse, toPlainObject, walk } from 'css-tree';\nimport { getType } from './utility.js';\n\n/* constants */\nimport {\n ATTR_SELECTOR, BIT_01, BIT_02, BIT_04, BIT_08, BIT_16, BIT_32, BIT_FFFF,\n CLASS_SELECTOR, DUO, EMPTY, HEX, HYPHEN, ID_SELECTOR, NTH, PS_CLASS_SELECTOR,\n PS_ELEMENT_SELECTOR, REG_LOGICAL, SELECTOR, SYNTAX_ERR, TYPE_SELECTOR, U_FFFD\n} from './constant.js';\nconst REG_LANG_QUOTED = /(:lang\\(\\s*(\"[A-Za-z\\d\\-*]*\")\\s*\\))/;\nconst REG_LOGICAL_EMPTY = /(:(is|where)\\(\\s*\\))/;\nconst REG_SHADOW_PSEUDO = /^part|slotted$/;\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 // @see https://drafts.csswg.org/selectors/#id-selectors\n // @see https://drafts.csswg.org/css-syntax-3/#ident-token-diagram\n if (/^\\d$/.test(postHash.substring(0, 1))) {\n throw new DOMException(`Invalid selector ${selector}`, SYNTAX_ERR);\n }\n const codePoint = postHash.codePointAt(0);\n if (codePoint === 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 = getType(selector).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 const { message } = e;\n // workaround for https://github.com/csstree/csstree/issues/265\n if (message === 'Identifier is expected' &&\n REG_LANG_QUOTED.test(selector)) {\n const [, lang, range] = REG_LANG_QUOTED.exec(selector);\n const escapedRange =\n range.replaceAll('*', '\\\\*').replace(/^\"/, '').replace(/\"$/, '');\n let escapedLang = lang.replace(range, escapedRange);\n if (escapedLang === ':lang()') {\n escapedLang = `:lang(${EMPTY})`;\n }\n res = parseSelector(selector.replace(lang, escapedLang));\n } else if (/^(?:Identifier|Selector) is expected$/.test(message) &&\n REG_LOGICAL_EMPTY.test(selector)) {\n const [, sel, name] = REG_LOGICAL_EMPTY.exec(selector);\n res = parseSelector(selector.replace(sel, `:${name}(${EMPTY})`));\n } else if (/^(?:\"\\]\"|Attribute selector [()\\s,=~^$*|]+) is expected$/.test(message) &&\n !selector.endsWith(']')) {\n const index = selector.lastIndexOf('[');\n const sel = selector.substring(index);\n if (sel.includes('\"')) {\n const quotes = sel.match(/\"/g).length;\n if (quotes % 2) {\n res = parseSelector(`${selector}\"]`);\n } else {\n res = parseSelector(`${selector}]`);\n }\n } else {\n res = parseSelector(`${selector}]`);\n }\n } else if (message === '\")\" is expected' && !selector.endsWith(')')) {\n res = parseSelector(`${selector})`);\n } else {\n throw new DOMException(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 const info = new Map();\n const opt = {\n enter: node => {\n switch (node.type) {\n case SELECTOR: {\n branches.add(node.children);\n break;\n }\n case PS_CLASS_SELECTOR: {\n if (REG_LOGICAL.test(node.name)) {\n info.set('hasNestedSelector', true);\n info.set('hasLogicalPseudoFunc', true);\n if (node.name === 'has') {\n info.set('hasHasPseudoFunc', true);\n }\n }\n break;\n }\n case PS_ELEMENT_SELECTOR: {\n if (REG_SHADOW_PSEUDO.test(node.name)) {\n info.set('hasNestedSelector', true);\n }\n break;\n }\n case NTH: {\n if (node.selector) {\n info.set('hasNestedSelector', true);\n }\n break;\n }\n default:\n }\n }\n };\n walk(ast, opt);\n if (info.get('hasNestedSelector')) {\n findAll(ast, (node, item, list) => {\n if (list) {\n if (node.type === PS_CLASS_SELECTOR && REG_LOGICAL.test(node.name)) {\n const itemList = list.filter(i => {\n const { name, type } = i;\n const res =\n type === PS_CLASS_SELECTOR && REG_LOGICAL.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 === PS_ELEMENT_SELECTOR &&\n REG_SHADOW_PSEUDO.test(node.name)) {\n const itemList = list.filter(i => {\n const { name, type } = i;\n const res =\n type === PS_ELEMENT_SELECTOR && 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 } else if (node.type === NTH && node.selector) {\n const itemList = list.filter(i => {\n const { selector, type } = i;\n const res = type === NTH && selector;\n return res;\n });\n for (const { selector } of itemList) {\n const { children } = selector;\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 {\n branches: [...branches],\n info: Object.fromEntries(info)\n };\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 [PS_ELEMENT_SELECTOR, BIT_01],\n [ID_SELECTOR, BIT_02],\n [CLASS_SELECTOR, BIT_04],\n [TYPE_SELECTOR, BIT_08],\n [ATTR_SELECTOR, BIT_16],\n [PS_CLASS_SELECTOR, 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 * @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,IAA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B,CACT,EAOad,EAAea,GAAY,CACtC,IAAI4C,EACAC,EACJ,GAAI7C,GAAY,OAAOA,GAAa,SAC9BA,EAAS,QAAQ,GAAG,EAAI,GAC1B,CAAC4C,EAAQC,CAAS,EAAI7C,EAAS,MAAM,GAAG,GAExC4C,EAAS,IACTC,EAAY7C,OAGd,OAAM,IAAI,aAAa,oBAAoBA,CAAQ,GAAI,YAAU,EAEnE,MAAO,CACL,OAAA4C,EACA,UAAAC,CACF,CACF",
|
|
6
|
+
"names": ["parser_exports", "__export", "parseAstName", "parseSelector", "preprocess", "sortAST", "unescapeSelector", "walkAST", "__toCommonJS", "import_css_tree", "import_utility", "import_constant", "REG_LANG_QUOTED", "REG_LOGICAL_EMPTY", "REG_SHADOW_PSEUDO", "selector", "arr", "l", "i", "item", "hexExists", "hex", "str", "low", "high", "deci", "postStr", "args", "index", "preHash", "postHash", "codePoint", "res", "ast", "e", "message", "lang", "range", "escapedRange", "escapedLang", "sel", "name", "branches", "info", "node", "list", "itemList", "type", "children", "grandChildren", "greatGrandChildren", "asts", "order", "a", "b", "typeA", "typeB", "bitA", "bitB", "prefix", "localName"]
|
|
7
7
|
}
|
package/dist/cjs/js/utility.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var D=Object.create;var f=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var L=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var R=(e,t)=>{for(var i in t)f(e,i,{get:t[i],enumerable:!0})},w=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of _(t))!I.call(e,o)&&o!==i&&f(e,o,{get:()=>t[o],enumerable:!(r=U(t,o))||r.enumerable});return e};var y=(e,t,i)=>(i=e!=null?D(L(e)):{},w(t||!e||!e.__esModule?f(i,"default",{value:e,enumerable:!0}):i,e)),k=e=>w(f({},"__esModule",{value:!0}),e);var K={};R(K,{filterSelector:()=>H,getDirectionality:()=>m,getNamespaceURI:()=>g,getSlottedTextContent:()=>u,getType:()=>p,initNwsapi:()=>j,isContentEditable:()=>x,isCustomElement:()=>G,isFocusVisible:()=>V,isFocusable:()=>W,isInShadowTree:()=>$,isNamespaceDeclared:()=>X,isPreceding:()=>C,isVisible:()=>F,resolveContent:()=>A,sortNodes:()=>Y,traverseNode:()=>S});module.exports=k(K);var h=y(require("@asamuzakjp/nwsapi"),1),O=y(require("bidi-js"),1),T=y(require("is-potential-custom-element-name"),1),s=require("./constant.js");const M=new RegExp(`:(?!${s.PSEUDO_CLASS}|${s.N_TH}|${s.LOGICAL_COMPLEX})`),P=new RegExp(`:(?!${s.PSEUDO_CLASS}|${s.N_TH}|${s.LOGICAL_COMPOUND})`),v=new RegExp(`:(?!${s.PSEUDO_CLASS}|${s.N_TH})`),p=e=>Object.prototype.toString.call(e).slice(s.TYPE_FROM,s.TYPE_TO),A=e=>{if(!e?.nodeType)throw new TypeError(`Unexpected type ${p(e)}`);let t,i;switch(e.nodeType){case s.DOCUMENT_NODE:{t=e,i=e;break}case s.DOCUMENT_FRAGMENT_NODE:{t=e.ownerDocument,i=e;break}case s.ELEMENT_NODE:{t=e.ownerDocument;let o=e;for(;o&&o.parentNode;)o=o.parentNode;i=o;break}default:throw new TypeError(`Unexpected node ${e.nodeName}`)}const r=t.createTreeWalker(i,s.WALKER_FILTER);return[t,i,r]},S=(e,t)=>{if(!e?.nodeType)throw new TypeError(`Unexpected type ${p(e)}`);let i;if(t?.currentNode){let r=t.currentNode;if(r===e)i=r;else if(r.contains(e))for(r=t.nextNode();r;){if(r===e){i=r;break}r=t.nextNode()}else{if(r!==t.root)for(;r&&!(r===t.root||r===e);)r=t.parentNode();if(e.nodeType===s.ELEMENT_NODE)for(;r;){if(r===e){i=r;break}r=t.nextNode()}else i=r}}return i??null},G=(e,t={})=>{if(!e?.nodeType)throw new TypeError(`Unexpected type ${p(e)}`);let i;if(e.nodeType===s.ELEMENT_NODE){const{localName:r,ownerDocument:o}=e,{formAssociated:a}=t,n=o.defaultView;let l;const c=e.getAttribute("is");c?l=(0,T.default)(c)&&n.customElements.get(c):l=(0,T.default)(r)&&n.customElements.get(r),l&&(a?i=l.formAssociated:i=!0)}return!!i},$=e=>{if(!e?.nodeType)throw new TypeError(`Unexpected type ${p(e)}`);let t;if(e.nodeType===s.ELEMENT_NODE||e.nodeType===s.DOCUMENT_FRAGMENT_NODE){let i=e;for(;i;){const{host:r,mode:o,nodeType:a,parentNode:n}=i;if(r&&o&&a===s.DOCUMENT_FRAGMENT_NODE&&/^(?:close|open)$/.test(o)){t=!0;break}i=n}}return!!t},u=e=>{if(!e?.nodeType)throw new TypeError(`Unexpected type ${p(e)}`);let t;if(e.localName==="slot"&&$(e)){const i=e.assignedNodes();if(i.length){for(const r of i)if(t=r.textContent.trim(),t)break}else t=e.textContent.trim()}return t??null},m=e=>{if(!e?.nodeType)throw new TypeError(`Unexpected type ${p(e)}`);let t;if(e.nodeType===s.ELEMENT_NODE){const{dir:i,localName:r,parentNode:o}=e,{getEmbeddingLevels:a}=(0,O.default)();if(/^(?:ltr|rtl)$/.test(i))t=i;else if(i==="auto"){let n;switch(r){case"input":{!e.type||/^(?:button|email|hidden|password|reset|search|submit|tel|text|url)$/.test(e.type)?n=e.value:/^(?:checkbox|color|date|image|number|radio|range|time)$/.test(e.type)&&(t="ltr");break}case"slot":{n=u(e);break}case"textarea":{n=e.value;break}default:{const l=[].slice.call(e.childNodes);for(const c of l){const{dir:d,localName:b,nodeType:E,textContent:N}=c;if(E===s.TEXT_NODE?n=N.trim():E===s.ELEMENT_NODE&&!/^(?:bdi|script|style|textarea)$/.test(b)&&(!d||!/^(?:ltr|rtl)$/.test(d))&&(b==="slot"?n=u(c):n=N.trim()),n)break}}}if(n){const{paragraphs:[{level:l}]}=a(n);l%2===1?t="rtl":t="ltr"}if(!t)if(o){const{nodeType:l}=o;l===s.ELEMENT_NODE?t=m(o):(l===s.DOCUMENT_NODE||l===s.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}else t="ltr"}else if(r==="bdi"){const n=e.textContent.trim();if(n){const{paragraphs:[{level:l}]}=a(n);l%2===1?t="rtl":t="ltr"}t||o||(t="ltr")}else if(r==="input"&&e.type==="tel")t="ltr";else if(o){if(r==="slot"){const n=u(e);if(n){const{paragraphs:[{level:l}]}=a(n);l%2===1?t="rtl":t="ltr"}}if(!t){const{nodeType:n}=o;n===s.ELEMENT_NODE?t=m(o):(n===s.DOCUMENT_NODE||n===s.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}}else t="ltr"}return t??null},x=e=>{if(!e?.nodeType)throw new TypeError(`Unexpected type ${p(e)}`);let t;if(e.nodeType===s.ELEMENT_NODE){if(typeof e.isContentEditable=="boolean")t=e.isContentEditable;else if(e.ownerDocument.designMode==="on")t=!0;else if(e.hasAttribute("contenteditable")){const i=e.getAttribute("contenteditable");if(i===""||/^(?:plaintext-only|true)$/.test(i))t=!0;else if(i==="inherit"){let r=e.parentNode;for(;r;){if(x(r)){t=!0;break}r=r.parentNode}}}}return!!t},F=e=>{let t;if(e?.nodeType===s.ELEMENT_NODE){const i=e.ownerDocument.defaultView,{display:r,visibility:o}=i.getComputedStyle(e);r!=="none"&&o==="visible"&&(t=!0)}return!!t},V=e=>{let t;if(e?.nodeType===s.ELEMENT_NODE){const{localName:i,type:r}=e;switch(i){case"input":{(!r||s.REG_INPUT_TYPE.test(r))&&(t=!0);break}case"textarea":{t=!0;break}default:t=x(e)}}return!!t},W=e=>{let t;if(e?.nodeType===s.ELEMENT_NODE){const i=e.ownerDocument.defaultView;let r=e;for(t=!0;r;){if(r.disabled||r.hasAttribute("disabled"))return!1;(r.hidden||r.hasAttribute("hidden"))&&(t=!1);const{contentVisibility:o,display:a,visibility:n}=i.getComputedStyle(r);if(a==="none"||n!=="visible"||o==="hidden"&&r!==e?t=!1:t=!0,t&&r?.parentNode?.nodeType===s.ELEMENT_NODE)r=r.parentNode;else break}}return!!t},g=(e,t)=>{if(typeof e!="string")throw new TypeError(`Unexpected type ${p(e)}`);if(!t?.nodeType)throw new TypeError(`Unexpected type ${p(t)}`);let i;if(e&&t.nodeType===s.ELEMENT_NODE){const{attributes:r}=t;for(const o of r){const{name:a,namespaceURI:n,prefix:l,value:c}=o;if(a===`xmlns:${e}`){i=c;break}else if(l===e){i=n;break}}}return i??null},X=(e="",t={})=>{let i;if(e&&typeof e=="string"&&t.nodeType===s.ELEMENT_NODE&&(i=t.lookupNamespaceURI(e),!i)){const r=t.ownerDocument.documentElement;let o=t;for(;o&&(i=g(e,o),!(i||o===r));)o=o.parentNode}return!!i},C=(e,t)=>{if(e?.nodeType){if(!t?.nodeType)throw new TypeError(`Unexpected type ${p(t)}`)}else throw new TypeError(`Unexpected type ${p(e)}`);let i;if(e.nodeType===s.ELEMENT_NODE&&t.nodeType===s.ELEMENT_NODE){const r=t.compareDocumentPosition(e);i=r&s.DOCUMENT_POSITION_PRECEDING||r&s.DOCUMENT_POSITION_CONTAINS}return!!i},Y=(e=[])=>{const t=[...e];return t.length>1&&t.sort((i,r)=>{let o;return C(r,i)?o=1:o=-1,o}),t},j=(e,t)=>{if(!e?.DOMException)throw new TypeError(`Unexpected global object ${p(e)}`);t?.nodeType!==s.DOCUMENT_NODE&&(t=e.document);const i=(0,h.default)({document:t,DOMException:e.DOMException});return i.configure({LOGERRORS:!1}),i},H=(e,t={})=>{if(!e||typeof e!="string")return!1;if(e.includes("[")){const i=e.lastIndexOf("[");if(e.substring(i).indexOf("]")<0)return!1}if(/[|\\]|::|[^\u0021-\u007F\s]|\[\s*[\w$*=^|~-]+(?:(?:"[\w$*=^|~\s'-]+"|'[\w$*=^|~\s"-]+')?(?:\s+[\w$*=^|~-]+)+|"[^"\]]{1,255}|'[^'\]]{1,255})\s*\]|:(?:is|where)\(\s*\)/.test(e))return!1;if(e.includes(":")){const{complex:i,descend:r}=t;return/:(?:is|not)\(/.test(e)?i?!M.test(e):!P.test(e):r?!1:!v.test(e)}return!0};0&&(module.exports={filterSelector,getDirectionality,getNamespaceURI,getSlottedTextContent,getType,initNwsapi,isContentEditable,isCustomElement,isFocusVisible,isFocusable,isInShadowTree,isNamespaceDeclared,isPreceding,isVisible,resolveContent,sortNodes,traverseNode});
|
|
2
2
|
//# sourceMappingURL=utility.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/js/utility.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * utility.js\n */\n\n/* import */\nimport nwsapi from '@asamuzakjp/nwsapi';\nimport bidiFactory from 'bidi-js';\nimport isCustomElementName from 'is-potential-custom-element-name';\n\n/* constants */\nimport {\n DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINS,\n DOCUMENT_POSITION_PRECEDING, ELEMENT_NODE, REG_DIR, REG_FILTER_COMPLEX,\n REG_FILTER_COMPOUND, REG_FILTER_SIMPLE, REG_SHADOW_MODE, REG_TYPE_INPUT,\n TEXT_NODE, TYPE_FROM, TYPE_TO, WALKER_FILTER\n} from './constant.js';\n\n/**\n * get type\n * @param {*} o - object to check\n * @returns {string} - type of object\n */\nexport const getType = o =>\n Object.prototype.toString.call(o).slice(TYPE_FROM, TYPE_TO);\n\n/**\n * resolve content document, root node and tree walker\n * @param {object} node - Document, DocumentFragment, Element node\n * @returns {Array.<object>} - array of document, root node, tree walker\n */\nexport const resolveContent = node => {\n if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\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 document = node.ownerDocument;\n let parent = node;\n while (parent) {\n if (parent.parentNode) {\n parent = parent.parentNode;\n } else {\n break;\n }\n }\n root = parent;\n break;\n }\n default : {\n throw new TypeError(`Unexpected node ${node.nodeName}`);\n }\n }\n const walker = document.createTreeWalker(root, WALKER_FILTER);\n return [\n document,\n root,\n walker\n ];\n};\n\n/**\n * traverse node tree\n * @private\n * @param {object} node - node\n * @param {object} walker - tree walker\n * @returns {?object} - current node\n */\nexport const traverseNode = (node, walker) => {\n if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\n let current;\n if (walker?.currentNode) {\n let refNode = walker.currentNode;\n if (refNode === node) {\n current = refNode;\n } else if (refNode.contains(node)) {\n refNode = walker.nextNode();\n while (refNode) {\n if (refNode === node) {\n current = refNode;\n break;\n }\n refNode = walker.nextNode();\n }\n } else {\n if (refNode !== walker.root) {\n while (refNode) {\n if (refNode === walker.root || 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 }\n return current ?? null;\n};\n\n/**\n * is custom element\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {boolean} - result;\n */\nexport const isCustomElement = (node, opt = {}) => {\n if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\n let bool;\n if (node.nodeType === ELEMENT_NODE) {\n const { localName, ownerDocument } = node;\n const { formAssociated } = opt;\n const window = ownerDocument.defaultView;\n let elmConstructor;\n const attr = node.getAttribute('is');\n if (attr) {\n elmConstructor =\n isCustomElementName(attr) && window.customElements.get(attr);\n } else {\n elmConstructor =\n isCustomElementName(localName) && window.customElements.get(localName);\n }\n if (elmConstructor) {\n if (formAssociated) {\n bool = elmConstructor.formAssociated;\n } else {\n bool = true;\n }\n }\n }\n return !!bool;\n};\n\n/**\n * is in shadow tree\n * @param {object} node - node\n * @returns {boolean} - result;\n */\nexport const isInShadowTree = node => {\n if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\n let bool;\n if (node.nodeType === ELEMENT_NODE ||\n node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n let refNode = node;\n while (refNode) {\n const { host, mode, nodeType, parentNode } = refNode;\n if (host && mode && nodeType === DOCUMENT_FRAGMENT_NODE &&\n REG_SHADOW_MODE.test(mode)) {\n bool = true;\n break;\n }\n refNode = parentNode;\n }\n }\n return !!bool;\n};\n\n/**\n * get slotted text content\n * @param {object} node - Element node\n * @returns {?string} - text content\n */\nexport const getSlottedTextContent = node => {\n if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\n let res;\n if (node.localName === 'slot' && isInShadowTree(node)) {\n const nodes = node.assignedNodes();\n if (nodes.length) {\n for (const item of nodes) {\n res = item.textContent.trim();\n if (res) {\n break;\n }\n }\n } else {\n res = node.textContent.trim();\n }\n }\n return res ?? null;\n};\n\n/**\n * get directionality of node\n * @see https://html.spec.whatwg.org/multipage/dom.html#the-dir-attribute\n * @param {object} node - Element node\n * @returns {?string} - 'ltr' / 'rtl'\n */\nexport const getDirectionality = node => {\n if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\n let res;\n if (node.nodeType === ELEMENT_NODE) {\n const { dir: nodeDir, localName, parentNode } = node;\n const { getEmbeddingLevels } = bidiFactory();\n if (REG_DIR.test(nodeDir)) {\n res = nodeDir;\n } else if (nodeDir === 'auto') {\n let text;\n switch (localName) {\n case 'input': {\n if (!node.type || /^(?:button|email|hidden|password|reset|search|submit|tel|text|url)$/.test(node.type)) {\n text = node.value;\n } else if (/^(?:checkbox|color|date|image|number|radio|range|time)$/.test(node.type)) {\n res = 'ltr';\n }\n break;\n }\n case 'slot': {\n text = getSlottedTextContent(node);\n break;\n }\n case 'textarea': {\n text = node.value;\n break;\n }\n default: {\n const items = [].slice.call(node.childNodes);\n for (const item of items) {\n const {\n dir: itemDir, localName: itemLocalName, nodeType: itemNodeType,\n textContent: itemTextContent\n } = item;\n if (itemNodeType === TEXT_NODE) {\n text = itemTextContent.trim();\n } else if (itemNodeType === ELEMENT_NODE) {\n if (!/^(?:bdi|script|style|textarea)$/.test(itemLocalName) &&\n (!itemDir || !REG_DIR.test(itemDir))) {\n if (itemLocalName === 'slot') {\n text = getSlottedTextContent(item);\n } else {\n text = itemTextContent.trim();\n }\n }\n }\n if (text) {\n break;\n }\n }\n }\n }\n if (text) {\n const { paragraphs: [{ level }] } = getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n if (!res) {\n if (parentNode) {\n const { nodeType: parentNodeType } = parentNode;\n if (parentNodeType === ELEMENT_NODE) {\n res = getDirectionality(parentNode);\n } else if (parentNodeType === DOCUMENT_NODE ||\n parentNodeType === DOCUMENT_FRAGMENT_NODE) {\n res = 'ltr';\n }\n } else {\n res = 'ltr';\n }\n }\n } else if (localName === 'bdi') {\n const text = node.textContent.trim();\n if (text) {\n const { paragraphs: [{ level }] } = getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n if (!(res || parentNode)) {\n res = 'ltr';\n }\n } else if (localName === 'input' && node.type === 'tel') {\n res = 'ltr';\n } else if (parentNode) {\n if (localName === 'slot') {\n const text = getSlottedTextContent(node);\n if (text) {\n const { paragraphs: [{ level }] } = getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n }\n if (!res) {\n const { nodeType: parentNodeType } = parentNode;\n if (parentNodeType === ELEMENT_NODE) {\n res = getDirectionality(parentNode);\n } else if (parentNodeType === DOCUMENT_NODE ||\n parentNodeType === DOCUMENT_FRAGMENT_NODE) {\n res = 'ltr';\n }\n }\n } else {\n res = 'ltr';\n }\n }\n return res ?? null;\n};\n\n/**\n * is content editable\n * NOTE: not implemented in jsdom https://github.com/jsdom/jsdom/issues/1670\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isContentEditable = node => {\n if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\n let res;\n if (node.nodeType === ELEMENT_NODE) {\n if (typeof node.isContentEditable === 'boolean') {\n res = node.isContentEditable;\n } else if (node.ownerDocument.designMode === 'on') {\n res = true;\n } else if (node.hasAttribute('contenteditable')) {\n const attr = node.getAttribute('contenteditable');\n if (attr === '' || /^(?:plaintext-only|true)$/.test(attr)) {\n res = true;\n } else if (attr === 'inherit') {\n let parent = node.parentNode;\n while (parent) {\n if (isContentEditable(parent)) {\n res = true;\n break;\n }\n parent = parent.parentNode;\n }\n }\n }\n }\n return !!res;\n};\n\n/**\n * is node visible\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isVisible = node => {\n let res;\n if (node?.nodeType === ELEMENT_NODE) {\n const window = node.ownerDocument.defaultView;\n const { display, visibility } = window.getComputedStyle(node);\n if (display !== 'none' && visibility === 'visible') {\n res = true;\n }\n }\n return !!res;\n};\n\n/**\n * is focus visible\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isFocusVisible = node => {\n let res;\n if (node?.nodeType === ELEMENT_NODE) {\n const { localName, type } = node;\n switch (localName) {\n case 'input': {\n if (!type || REG_TYPE_INPUT.test(type)) {\n res = true;\n }\n break;\n }\n case 'textarea': {\n res = true;\n break;\n }\n default: {\n res = isContentEditable(node);\n }\n }\n }\n return !!res;\n};\n\n/**\n * is focusable\n * NOTE: workaround for jsdom issue: https://github.com/jsdom/jsdom/issues/3464\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isFocusable = node => {\n let res;\n if (node?.nodeType === ELEMENT_NODE) {\n const window = node.ownerDocument.defaultView;\n let refNode = node;\n res = true;\n while (refNode) {\n if (refNode.disabled || refNode.hasAttribute('disabled')) {\n return false;\n }\n if (refNode.hidden || refNode.hasAttribute('hidden')) {\n res = false;\n }\n const {\n contentVisibility, display, visibility\n } = window.getComputedStyle(refNode);\n if (display === 'none' || visibility !== 'visible' ||\n (contentVisibility === 'hidden' && refNode !== node)) {\n res = false;\n } else {\n res = true;\n }\n if (res && refNode?.parentNode?.nodeType === ELEMENT_NODE) {\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n }\n return !!res;\n};\n\n/**\n * get namespace URI\n * @param {string} ns - namespace prefix\n * @param {Array} node - Element node\n * @returns {?string} - namespace URI\n */\nexport const getNamespaceURI = (ns, node) => {\n if (typeof ns !== 'string') {\n throw new TypeError(`Unexpected type ${getType(ns)}`);\n } else if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\n let res;\n if (ns && node.nodeType === ELEMENT_NODE) {\n const { attributes } = node;\n for (const attr of attributes) {\n const { name, namespaceURI, prefix, value } = attr;\n if (name === `xmlns:${ns}`) {\n res = value;\n break;\n } else if (prefix === ns) {\n res = namespaceURI;\n break;\n }\n }\n }\n return res ?? null;\n};\n\n/**\n * is namespace declared\n * @param {string} ns - namespace\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isNamespaceDeclared = (ns = '', node = {}) => {\n let res;\n if (ns && typeof ns === 'string' && node.nodeType === ELEMENT_NODE) {\n res = node.lookupNamespaceURI(ns);\n if (!res) {\n const root = node.ownerDocument.documentElement;\n let parent = node;\n while (parent) {\n res = getNamespaceURI(ns, parent);\n if (res || parent === root) {\n break;\n }\n parent = parent.parentNode;\n }\n }\n }\n return !!res;\n};\n\n/**\n * is preceding - nodeA precedes and/or contains nodeB\n * @param {object} nodeA - Element node\n * @param {object} nodeB - Element node\n * @returns {boolean} - result\n */\nexport const isPreceding = (nodeA, nodeB) => {\n if (!nodeA?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(nodeA)}`);\n } else if (!nodeB?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(nodeB)}`);\n }\n let res;\n if (nodeA.nodeType === ELEMENT_NODE && nodeB.nodeType === ELEMENT_NODE) {\n const posBit = nodeB.compareDocumentPosition(nodeA);\n res = posBit & DOCUMENT_POSITION_PRECEDING ||\n posBit & DOCUMENT_POSITION_CONTAINS;\n }\n return !!res;\n};\n\n/**\n * sort nodes\n * @param {Array.<object>|Set.<object>} nodes - collection of nodes\n * @returns {Array.<object|undefined>} - collection of sorted nodes\n */\nexport const sortNodes = (nodes = []) => {\n const arr = [...nodes];\n if (arr.length > 1) {\n arr.sort((a, b) => {\n let res;\n if (isPreceding(b, a)) {\n res = 1;\n } else {\n res = -1;\n }\n return res;\n });\n }\n return arr;\n};\n\n/**\n * init nwsapi\n * @param {object} window - Window\n * @param {object} document - Document\n * @returns {object} - nwsapi\n */\nexport const initNwsapi = (window, document) => {\n if (!window?.DOMException) {\n throw new TypeError(`Unexpected global object ${getType(window)}`);\n }\n if (document?.nodeType !== DOCUMENT_NODE) {\n document = window.document;\n }\n const nw = nwsapi({\n document,\n DOMException: window.DOMException\n });\n nw.configure({\n LOGERRORS: false\n });\n return nw;\n};\n\n/**\n * filter selector (for nwsapi)\n * @param {string} selector - selector\n * @param {object} opt - options\n * @returns {boolean} - result\n */\nexport const filterSelector = (selector, opt = {}) => {\n if (!selector || typeof selector !== 'string') {\n return false;\n }\n // filter missing close square bracket\n if (selector.includes('[')) {\n const index = selector.lastIndexOf('[');\n const sel = selector.substring(index);\n if (sel.indexOf(']') < 0) {\n return false;\n }\n }\n // filter namespace selector, escaped selector, pseudo-element selector,\n // selector containing non-ASCII or control character other than whitespace,\n // attribute selector with case flag, e.g. [attr i], or with unclosed quotes,\n // and empty :is() or :where()\n if (/[|\\\\]|::|[^\\u0021-\\u007F\\s]|\\[\\s*[\\w$*=^|~-]+(?:(?:\"[\\w$*=^|~\\s'-]+\"|'[\\w$*=^|~\\s\"-]+')?(?:\\s+[\\w$*=^|~-]+)+|\"[^\"\\]]{1,255}|'[^'\\]]{1,255})\\s*\\]|:(?:is|where)\\(\\s*\\)/.test(selector)) {\n return false;\n }\n // filter pseudo-classes\n if (selector.includes(':')) {\n const { complex, descend } = opt;\n let reg;\n if (/:(?:is|not)\\(/.test(selector)) {\n if (complex) {\n reg = REG_FILTER_COMPLEX;\n } else {\n reg = REG_FILTER_COMPOUND;\n }\n } else {\n if (descend) {\n return false;\n }\n reg = REG_FILTER_SIMPLE;\n }\n if (reg.test(selector)) {\n return false;\n }\n }\n return true;\n};\n"],
|
|
5
|
-
"mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,oBAAAE,EAAA,sBAAAC,EAAA,oBAAAC,EAAA,0BAAAC,EAAA,YAAAC,EAAA,eAAAC,EAAA,sBAAAC,EAAA,oBAAAC,EAAA,mBAAAC,EAAA,gBAAAC,EAAA,mBAAAC,EAAA,wBAAAC,EAAA,gBAAAC,EAAA,cAAAC,EAAA,mBAAAC,EAAA,cAAAC,EAAA,iBAAAC,IAAA,eAAAC,EAAAnB,GAKA,IAAAoB,EAAmB,mCACnBC,EAAwB,wBACxBC,EAAgC,iDAGhCC,EAKO,
|
|
6
|
-
"names": ["utility_exports", "__export", "filterSelector", "getDirectionality", "getNamespaceURI", "getSlottedTextContent", "getType", "initNwsapi", "isContentEditable", "isCustomElement", "isFocusVisible", "isFocusable", "isInShadowTree", "isNamespaceDeclared", "isPreceding", "isVisible", "resolveContent", "sortNodes", "traverseNode", "__toCommonJS", "import_nwsapi", "import_bidi_js", "import_is_potential_custom_element_name", "import_constant", "o", "node", "document", "root", "parent", "walker", "current", "refNode", "opt", "bool", "localName", "ownerDocument", "formAssociated", "window", "elmConstructor", "attr", "isCustomElementName", "host", "mode", "nodeType", "parentNode", "res", "nodes", "item", "nodeDir", "getEmbeddingLevels", "bidiFactory", "text", "items", "itemDir", "itemLocalName", "itemNodeType", "itemTextContent", "level", "parentNodeType", "display", "visibility", "type", "contentVisibility", "ns", "attributes", "name", "namespaceURI", "prefix", "value", "nodeA", "nodeB", "posBit", "arr", "a", "b", "nw", "nwsapi", "selector", "index", "complex", "descend"
|
|
4
|
+
"sourcesContent": ["/**\n * utility.js\n */\n\n/* import */\nimport nwsapi from '@asamuzakjp/nwsapi';\nimport bidiFactory from 'bidi-js';\nimport isCustomElementName from 'is-potential-custom-element-name';\n\n/* constants */\nimport {\n DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINS,\n DOCUMENT_POSITION_PRECEDING, ELEMENT_NODE, N_TH, LOGICAL_COMPLEX,\n LOGICAL_COMPOUND, PSEUDO_CLASS, REG_INPUT_TYPE, TEXT_NODE, TYPE_FROM,\n TYPE_TO, WALKER_FILTER\n} from './constant.js';\nconst REG_LOGICAL_COMPLEX =\n new RegExp(`:(?!${PSEUDO_CLASS}|${N_TH}|${LOGICAL_COMPLEX})`);\nconst REG_LOGICAL_COMPOUND =\n new RegExp(`:(?!${PSEUDO_CLASS}|${N_TH}|${LOGICAL_COMPOUND})`);\nconst REG_WO_LOGICAL = new RegExp(`:(?!${PSEUDO_CLASS}|${N_TH})`);\n\n/**\n * get type\n * @param {*} o - object to check\n * @returns {string} - type of object\n */\nexport const getType = o =>\n Object.prototype.toString.call(o).slice(TYPE_FROM, TYPE_TO);\n\n/**\n * resolve content document, root node and tree walker\n * @param {object} node - Document, DocumentFragment, Element node\n * @returns {Array.<object>} - array of document, root node, tree walker\n */\nexport const resolveContent = node => {\n if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\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 document = node.ownerDocument;\n let parent = node;\n while (parent) {\n if (parent.parentNode) {\n parent = parent.parentNode;\n } else {\n break;\n }\n }\n root = parent;\n break;\n }\n default : {\n throw new TypeError(`Unexpected node ${node.nodeName}`);\n }\n }\n const walker = document.createTreeWalker(root, WALKER_FILTER);\n return [\n document,\n root,\n walker\n ];\n};\n\n/**\n * traverse node tree\n * @private\n * @param {object} node - node\n * @param {object} walker - tree walker\n * @returns {?object} - current node\n */\nexport const traverseNode = (node, walker) => {\n if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\n let current;\n if (walker?.currentNode) {\n let refNode = walker.currentNode;\n if (refNode === node) {\n current = refNode;\n } else if (refNode.contains(node)) {\n refNode = walker.nextNode();\n while (refNode) {\n if (refNode === node) {\n current = refNode;\n break;\n }\n refNode = walker.nextNode();\n }\n } else {\n if (refNode !== walker.root) {\n while (refNode) {\n if (refNode === walker.root || 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 }\n return current ?? null;\n};\n\n/**\n * is custom element\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {boolean} - result;\n */\nexport const isCustomElement = (node, opt = {}) => {\n if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\n let bool;\n if (node.nodeType === ELEMENT_NODE) {\n const { localName, ownerDocument } = node;\n const { formAssociated } = opt;\n const window = ownerDocument.defaultView;\n let elmConstructor;\n const attr = node.getAttribute('is');\n if (attr) {\n elmConstructor =\n isCustomElementName(attr) && window.customElements.get(attr);\n } else {\n elmConstructor =\n isCustomElementName(localName) && window.customElements.get(localName);\n }\n if (elmConstructor) {\n if (formAssociated) {\n bool = elmConstructor.formAssociated;\n } else {\n bool = true;\n }\n }\n }\n return !!bool;\n};\n\n/**\n * is in shadow tree\n * @param {object} node - node\n * @returns {boolean} - result;\n */\nexport const isInShadowTree = node => {\n if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\n let bool;\n if (node.nodeType === ELEMENT_NODE ||\n node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n let refNode = node;\n while (refNode) {\n const { host, mode, nodeType, parentNode } = refNode;\n if (host && mode && nodeType === DOCUMENT_FRAGMENT_NODE &&\n /^(?:close|open)$/.test(mode)) {\n bool = true;\n break;\n }\n refNode = parentNode;\n }\n }\n return !!bool;\n};\n\n/**\n * get slotted text content\n * @param {object} node - Element node\n * @returns {?string} - text content\n */\nexport const getSlottedTextContent = node => {\n if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\n let res;\n if (node.localName === 'slot' && isInShadowTree(node)) {\n const nodes = node.assignedNodes();\n if (nodes.length) {\n for (const item of nodes) {\n res = item.textContent.trim();\n if (res) {\n break;\n }\n }\n } else {\n res = node.textContent.trim();\n }\n }\n return res ?? null;\n};\n\n/**\n * get directionality of node\n * @see https://html.spec.whatwg.org/multipage/dom.html#the-dir-attribute\n * @param {object} node - Element node\n * @returns {?string} - 'ltr' / 'rtl'\n */\nexport const getDirectionality = node => {\n if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\n let res;\n if (node.nodeType === ELEMENT_NODE) {\n const { dir: nodeDir, localName, parentNode } = node;\n const { getEmbeddingLevels } = bidiFactory();\n if (/^(?:ltr|rtl)$/.test(nodeDir)) {\n res = nodeDir;\n } else if (nodeDir === 'auto') {\n let text;\n switch (localName) {\n case 'input': {\n if (!node.type || /^(?:button|email|hidden|password|reset|search|submit|tel|text|url)$/.test(node.type)) {\n text = node.value;\n } else if (/^(?:checkbox|color|date|image|number|radio|range|time)$/.test(node.type)) {\n res = 'ltr';\n }\n break;\n }\n case 'slot': {\n text = getSlottedTextContent(node);\n break;\n }\n case 'textarea': {\n text = node.value;\n break;\n }\n default: {\n const items = [].slice.call(node.childNodes);\n for (const item of items) {\n const {\n dir: itemDir, localName: itemLocalName, nodeType: itemNodeType,\n textContent: itemTextContent\n } = item;\n if (itemNodeType === TEXT_NODE) {\n text = itemTextContent.trim();\n } else if (itemNodeType === ELEMENT_NODE) {\n if (!/^(?:bdi|script|style|textarea)$/.test(itemLocalName) &&\n (!itemDir || !/^(?:ltr|rtl)$/.test(itemDir))) {\n if (itemLocalName === 'slot') {\n text = getSlottedTextContent(item);\n } else {\n text = itemTextContent.trim();\n }\n }\n }\n if (text) {\n break;\n }\n }\n }\n }\n if (text) {\n const { paragraphs: [{ level }] } = getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n if (!res) {\n if (parentNode) {\n const { nodeType: parentNodeType } = parentNode;\n if (parentNodeType === ELEMENT_NODE) {\n res = getDirectionality(parentNode);\n } else if (parentNodeType === DOCUMENT_NODE ||\n parentNodeType === DOCUMENT_FRAGMENT_NODE) {\n res = 'ltr';\n }\n } else {\n res = 'ltr';\n }\n }\n } else if (localName === 'bdi') {\n const text = node.textContent.trim();\n if (text) {\n const { paragraphs: [{ level }] } = getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n if (!(res || parentNode)) {\n res = 'ltr';\n }\n } else if (localName === 'input' && node.type === 'tel') {\n res = 'ltr';\n } else if (parentNode) {\n if (localName === 'slot') {\n const text = getSlottedTextContent(node);\n if (text) {\n const { paragraphs: [{ level }] } = getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n }\n if (!res) {\n const { nodeType: parentNodeType } = parentNode;\n if (parentNodeType === ELEMENT_NODE) {\n res = getDirectionality(parentNode);\n } else if (parentNodeType === DOCUMENT_NODE ||\n parentNodeType === DOCUMENT_FRAGMENT_NODE) {\n res = 'ltr';\n }\n }\n } else {\n res = 'ltr';\n }\n }\n return res ?? null;\n};\n\n/**\n * is content editable\n * NOTE: not implemented in jsdom https://github.com/jsdom/jsdom/issues/1670\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isContentEditable = node => {\n if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\n let res;\n if (node.nodeType === ELEMENT_NODE) {\n if (typeof node.isContentEditable === 'boolean') {\n res = node.isContentEditable;\n } else if (node.ownerDocument.designMode === 'on') {\n res = true;\n } else if (node.hasAttribute('contenteditable')) {\n const attr = node.getAttribute('contenteditable');\n if (attr === '' || /^(?:plaintext-only|true)$/.test(attr)) {\n res = true;\n } else if (attr === 'inherit') {\n let parent = node.parentNode;\n while (parent) {\n if (isContentEditable(parent)) {\n res = true;\n break;\n }\n parent = parent.parentNode;\n }\n }\n }\n }\n return !!res;\n};\n\n/**\n * is node visible\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isVisible = node => {\n let res;\n if (node?.nodeType === ELEMENT_NODE) {\n const window = node.ownerDocument.defaultView;\n const { display, visibility } = window.getComputedStyle(node);\n if (display !== 'none' && visibility === 'visible') {\n res = true;\n }\n }\n return !!res;\n};\n\n/**\n * is focus visible\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isFocusVisible = node => {\n let res;\n if (node?.nodeType === ELEMENT_NODE) {\n const { localName, type } = node;\n switch (localName) {\n case 'input': {\n if (!type || REG_INPUT_TYPE.test(type)) {\n res = true;\n }\n break;\n }\n case 'textarea': {\n res = true;\n break;\n }\n default: {\n res = isContentEditable(node);\n }\n }\n }\n return !!res;\n};\n\n/**\n * is focusable\n * NOTE: workaround for jsdom issue: https://github.com/jsdom/jsdom/issues/3464\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isFocusable = node => {\n let res;\n if (node?.nodeType === ELEMENT_NODE) {\n const window = node.ownerDocument.defaultView;\n let refNode = node;\n res = true;\n while (refNode) {\n if (refNode.disabled || refNode.hasAttribute('disabled')) {\n return false;\n }\n if (refNode.hidden || refNode.hasAttribute('hidden')) {\n res = false;\n }\n const {\n contentVisibility, display, visibility\n } = window.getComputedStyle(refNode);\n if (display === 'none' || visibility !== 'visible' ||\n (contentVisibility === 'hidden' && refNode !== node)) {\n res = false;\n } else {\n res = true;\n }\n if (res && refNode?.parentNode?.nodeType === ELEMENT_NODE) {\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n }\n return !!res;\n};\n\n/**\n * get namespace URI\n * @param {string} ns - namespace prefix\n * @param {Array} node - Element node\n * @returns {?string} - namespace URI\n */\nexport const getNamespaceURI = (ns, node) => {\n if (typeof ns !== 'string') {\n throw new TypeError(`Unexpected type ${getType(ns)}`);\n } else if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\n let res;\n if (ns && node.nodeType === ELEMENT_NODE) {\n const { attributes } = node;\n for (const attr of attributes) {\n const { name, namespaceURI, prefix, value } = attr;\n if (name === `xmlns:${ns}`) {\n res = value;\n break;\n } else if (prefix === ns) {\n res = namespaceURI;\n break;\n }\n }\n }\n return res ?? null;\n};\n\n/**\n * is namespace declared\n * @param {string} ns - namespace\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isNamespaceDeclared = (ns = '', node = {}) => {\n let res;\n if (ns && typeof ns === 'string' && node.nodeType === ELEMENT_NODE) {\n res = node.lookupNamespaceURI(ns);\n if (!res) {\n const root = node.ownerDocument.documentElement;\n let parent = node;\n while (parent) {\n res = getNamespaceURI(ns, parent);\n if (res || parent === root) {\n break;\n }\n parent = parent.parentNode;\n }\n }\n }\n return !!res;\n};\n\n/**\n * is preceding - nodeA precedes and/or contains nodeB\n * @param {object} nodeA - Element node\n * @param {object} nodeB - Element node\n * @returns {boolean} - result\n */\nexport const isPreceding = (nodeA, nodeB) => {\n if (!nodeA?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(nodeA)}`);\n } else if (!nodeB?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(nodeB)}`);\n }\n let res;\n if (nodeA.nodeType === ELEMENT_NODE && nodeB.nodeType === ELEMENT_NODE) {\n const posBit = nodeB.compareDocumentPosition(nodeA);\n res = posBit & DOCUMENT_POSITION_PRECEDING ||\n posBit & DOCUMENT_POSITION_CONTAINS;\n }\n return !!res;\n};\n\n/**\n * sort nodes\n * @param {Array.<object>|Set.<object>} nodes - collection of nodes\n * @returns {Array.<object|undefined>} - collection of sorted nodes\n */\nexport const sortNodes = (nodes = []) => {\n const arr = [...nodes];\n if (arr.length > 1) {\n arr.sort((a, b) => {\n let res;\n if (isPreceding(b, a)) {\n res = 1;\n } else {\n res = -1;\n }\n return res;\n });\n }\n return arr;\n};\n\n/**\n * init nwsapi\n * @param {object} window - Window\n * @param {object} document - Document\n * @returns {object} - nwsapi\n */\nexport const initNwsapi = (window, document) => {\n if (!window?.DOMException) {\n throw new TypeError(`Unexpected global object ${getType(window)}`);\n }\n if (document?.nodeType !== DOCUMENT_NODE) {\n document = window.document;\n }\n const nw = nwsapi({\n document,\n DOMException: window.DOMException\n });\n nw.configure({\n LOGERRORS: false\n });\n return nw;\n};\n\n/**\n * filter selector (for nwsapi)\n * @param {string} selector - selector\n * @param {object} opt - options\n * @returns {boolean} - result\n */\nexport const filterSelector = (selector, opt = {}) => {\n if (!selector || typeof selector !== 'string') {\n return false;\n }\n // filter missing close square bracket\n if (selector.includes('[')) {\n const index = selector.lastIndexOf('[');\n const sel = selector.substring(index);\n if (sel.indexOf(']') < 0) {\n return false;\n }\n }\n // filter namespace selector, escaped selector, pseudo-element selector,\n // selector containing non-ASCII or control character other than whitespace,\n // attribute selector with case flag, e.g. [attr i], or with unclosed quotes,\n // and empty :is() or :where()\n if (/[|\\\\]|::|[^\\u0021-\\u007F\\s]|\\[\\s*[\\w$*=^|~-]+(?:(?:\"[\\w$*=^|~\\s'-]+\"|'[\\w$*=^|~\\s\"-]+')?(?:\\s+[\\w$*=^|~-]+)+|\"[^\"\\]]{1,255}|'[^'\\]]{1,255})\\s*\\]|:(?:is|where)\\(\\s*\\)/.test(selector)) {\n return false;\n }\n // filter pseudo-classes\n if (selector.includes(':')) {\n const { complex, descend } = opt;\n if (/:(?:is|not)\\(/.test(selector)) {\n if (complex) {\n return !REG_LOGICAL_COMPLEX.test(selector);\n } else {\n return !REG_LOGICAL_COMPOUND.test(selector);\n }\n } else if (descend) {\n return false;\n } else {\n return !REG_WO_LOGICAL.test(selector);\n }\n }\n return true;\n};\n"],
|
|
5
|
+
"mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,oBAAAE,EAAA,sBAAAC,EAAA,oBAAAC,EAAA,0BAAAC,EAAA,YAAAC,EAAA,eAAAC,EA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A4BlC,EAAQkC,CAAM,CAAC,EAAE,EAE/DX,GAAU,WAAa,kBACzBA,EAAWW,EAAO,UAEpB,MAAMsC,KAAK,EAAAC,SAAO,CAChB,SAAAlD,EACA,aAAcW,EAAO,YACvB,CAAC,EACD,OAAAsC,EAAG,UAAU,CACX,UAAW,EACb,CAAC,EACMA,CACT,EAQa5E,EAAiB,CAAC8E,EAAU7C,EAAM,CAAC,IAAM,CACpD,GAAI,CAAC6C,GAAY,OAAOA,GAAa,SACnC,MAAO,GAGT,GAAIA,EAAS,SAAS,GAAG,EAAG,CAC1B,MAAMC,EAAQD,EAAS,YAAY,GAAG,EAEtC,GADYA,EAAS,UAAUC,CAAK,EAC5B,QAAQ,GAAG,EAAI,EACrB,MAAO,EAEX,CAKA,GAAI,wKAAwK,KAAKD,CAAQ,EACvL,MAAO,GAGT,GAAIA,EAAS,SAAS,GAAG,EAAG,CAC1B,KAAM,CAAE,QAAAE,EAAS,QAAAC,CAAQ,EAAIhD,EAC7B,MAAI,gBAAgB,KAAK6C,CAAQ,EAC3BE,EACK,CAAC1D,EAAoB,KAAKwD,CAAQ,EAElC,CAACvD,EAAqB,KAAKuD,CAAQ,EAEnCG,EACF,GAEA,CAACzD,EAAe,KAAKsD,CAAQ,CAExC,CACA,MAAO,EACT",
|
|
6
|
+
"names": ["utility_exports", "__export", "filterSelector", "getDirectionality", "getNamespaceURI", "getSlottedTextContent", "getType", "initNwsapi", "isContentEditable", "isCustomElement", "isFocusVisible", "isFocusable", "isInShadowTree", "isNamespaceDeclared", "isPreceding", "isVisible", "resolveContent", "sortNodes", "traverseNode", "__toCommonJS", "import_nwsapi", "import_bidi_js", "import_is_potential_custom_element_name", "import_constant", "REG_LOGICAL_COMPLEX", "REG_LOGICAL_COMPOUND", "REG_WO_LOGICAL", "o", "node", "document", "root", "parent", "walker", "current", "refNode", "opt", "bool", "localName", "ownerDocument", "formAssociated", "window", "elmConstructor", "attr", "isCustomElementName", "host", "mode", "nodeType", "parentNode", "res", "nodes", "item", "nodeDir", "getEmbeddingLevels", "bidiFactory", "text", "items", "itemDir", "itemLocalName", "itemNodeType", "itemTextContent", "level", "parentNodeType", "display", "visibility", "type", "contentVisibility", "ns", "attributes", "name", "namespaceURI", "prefix", "value", "nodeA", "nodeB", "posBit", "arr", "a", "b", "nw", "nwsapi", "selector", "index", "complex", "descend"]
|
|
7
7
|
}
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -11,9 +11,11 @@ import { filterSelector, getType, initNwsapi } from './js/utility.js';
|
|
|
11
11
|
|
|
12
12
|
/* constants */
|
|
13
13
|
import {
|
|
14
|
-
|
|
14
|
+
COMBO, COMPOUND_I, DESCEND, DOCUMENT_NODE, ELEMENT_NODE, TARGET_ALL,
|
|
15
15
|
TARGET_FIRST, TARGET_LINEAL, TARGET_SELF
|
|
16
16
|
} from './js/constant.js';
|
|
17
|
+
const REG_COMPLEX = new RegExp(`${COMBO}${COMPOUND_I}`, 'i');
|
|
18
|
+
const REG_DESCEND = new RegExp(`${DESCEND}${COMPOUND_I}`, 'i');
|
|
17
19
|
|
|
18
20
|
/* DOMSelector */
|
|
19
21
|
export class DOMSelector {
|