@asamuzakjp/dom-selector 2.0.3-a.2 → 2.0.3-a.3

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.
@@ -1,2 +1,2 @@
1
- var T=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var N=(t,e)=>{for(var r in e)T(t,r,{get:e[r],enumerable:!0})},_=(t,e,r,c)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of C(e))!D.call(t,s)&&s!==r&&T(t,s,{get:()=>e[s],enumerable:!(c=$(e,s))||c.enumerable});return t};var v=t=>_(T({},"__esModule",{value:!0}),t);var U={};N(U,{_matchAttributeSelector:()=>O,_matchClassSelector:()=>S,_matchIDSelector:()=>k,_matchTypeSelector:()=>L,matchPseudoElementSelector:()=>P,matchSelector:()=>R});module.exports=v(U);var E=require("./dom-util.js"),d=require("./parser.js"),i=require("./constant.js");const O=(t,e)=>{const{flags:r,matcher:c,name:s,value:g}=t;if(typeof r=="string"&&!/^[is]$/i.test(r)){const n=`Invalid selector ${(0,d.generateCSS)(t)}`;throw new DOMException(n,i.SYNTAX_ERR)}const{attributes:x}=e;let u;if(x&&x.length){const w=e.ownerDocument.contentType;let n;w==="text/html"?typeof r=="string"&&/^s$/i.test(r)?n=!1:n=!0:typeof r=="string"&&/^i$/i.test(r)?n=!0:n=!1;let h=(0,d.unescapeSelector)(s.name);n&&(h=h.toLowerCase());const l=new Set;if(h.indexOf("|")>-1){const{prefix:m,localName:f}=(0,d.parseAstName)(h);for(const o of x){let{name:a,value:p}=o;switch(n&&(a=a.toLowerCase(),p=p.toLowerCase()),m){case"":{f===a&&l.add(p);break}case"*":{a.indexOf(":")>-1?a.endsWith(`:${f}`)&&l.add(p):f===a&&l.add(p);break}default:if(a.indexOf(":")>-1){const[y,b]=a.split(":");if(y==="xml"&&b==="lang")continue;m===y&&f===b&&(0,E.isNamespaceDeclared)(y,e)&&l.add(p)}}}}else for(let{name:m,value:f}of x)if(n&&(m=m.toLowerCase(),f=f.toLowerCase()),m.indexOf(":")>-1){const[o,a]=m.split(":");if(o==="xml"&&a==="lang")continue;h===a&&l.add(f)}else h===m&&l.add(f);if(l.size){const{name:m,value:f}=g??{};let o;switch(m?n?o=m.toLowerCase():o=m:f?n?o=f.toLowerCase():o=f:f===""&&(o=f),c){case"=":{typeof o=="string"&&l.has(o)&&(u=e);break}case"~=":{if(o&&typeof o=="string"){for(const a of l)if(new Set(a.split(/\s+/)).has(o)){u=e;break}}break}case"|=":{if(o&&typeof o=="string"){let a;for(const p of l)if(p===o||p.startsWith(`${o}-`)){a=p;break}a&&(u=e)}break}case"^=":{if(o&&typeof o=="string"){let a;for(const p of l)if(p.startsWith(`${o}`)){a=p;break}a&&(u=e)}break}case"$=":{if(o&&typeof o=="string"){let a;for(const p of l)if(p.endsWith(`${o}`)){a=p;break}a&&(u=e)}break}case"*=":{if(o&&typeof o=="string"){let a;for(const p of l)if(p.includes(`${o}`)){a=p;break}a&&(u=e)}break}case null:default:u=e}}}return u??null},S=(t,e)=>{const r=(0,d.unescapeSelector)(t.name),{classList:c}=e;let s;return c.contains(r)&&(s=e),s??null},k=(t,e)=>{const r=(0,d.unescapeSelector)(t.name),{id:c}=e;let s;return r===c&&(s=e),s??null},L=(t,e,r={})=>{const c=(0,d.unescapeSelector)(t.name),{localName:s,namespaceURI:g,prefix:x}=e,{forgive:u}=r;let{prefix:w,localName:n}=(0,d.parseAstName)(c,e);e.ownerDocument.contentType==="text/html"&&(w=w.toLowerCase(),n=n.toLowerCase());let l,m;s.indexOf(":")>-1?[l,m]=s.split(":"):(l=x||"",m=s);let f;if(w===""&&l==="")g===null&&(n==="*"||n===m)&&(f=e);else if(w==="*")(n==="*"||n===m)&&(f=e);else if(w&&l){const o=(0,E.isNamespaceDeclared)(l,e);if(w===l){if(o)(n==="*"||n===m)&&(f=e);else if(!u){const a=`Undeclared namespace ${w}`;throw new DOMException(a,i.SYNTAX_ERR)}}}return f??null},R=(t,e,r)=>{if(!t||!t.type){const g=`Unexpected node ${Object.prototype.toString.call(t).slice(i.TYPE_FROM,i.TYPE_TO)}`;throw new TypeError(g)}else if(!e||!e.nodeType){const g=`Unexpected node ${Object.prototype.toString.call(e).slice(i.TYPE_FROM,i.TYPE_TO)}`;throw new TypeError(g)}else if(e.nodeType!==i.ELEMENT_NODE){const s=`Unexpected node ${e.nodeName}`;throw new TypeError(s)}let c;switch(t.type){case i.SELECTOR_ATTR:{c=O(t,e);break}case i.SELECTOR_CLASS:{c=S(t,e);break}case i.SELECTOR_ID:{c=k(t,e);break}case i.SELECTOR_TYPE:default:c=L(t,e,r)}return c},P=(t,e={})=>{if(!t||typeof t!="string"){const g=`Unexpected type ${Object.prototype.toString.call(t).slice(i.TYPE_FROM,i.TYPE_TO)}`;throw new TypeError(g)}const{forgive:r,warn:c}=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(c){const s=`Unsupported pseudo-element ::${t}`;throw new DOMException(s,i.NOT_SUPPORTED_ERR)}break}case"part":case"slotted":{if(c){const s=`Unsupported pseudo-element ::${t}()`;throw new DOMException(s,i.NOT_SUPPORTED_ERR)}break}default:if(t.startsWith("-webkit-")){if(c){const s=`Unsupported pseudo-element ::${t}`;throw new DOMException(s,i.NOT_SUPPORTED_ERR)}}else if(!r){const s=`Unknown pseudo-element ::${t}`;throw new DOMException(s,i.SYNTAX_ERR)}}};0&&(module.exports={_matchAttributeSelector,_matchClassSelector,_matchIDSelector,_matchTypeSelector,matchPseudoElementSelector,matchSelector});
1
+ var T=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var N=(t,e)=>{for(var c in e)T(t,c,{get:e[c],enumerable:!0})},_=(t,e,c,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of D(e))!C.call(t,s)&&s!==c&&T(t,s,{get:()=>e[s],enumerable:!(r=$(e,s))||r.enumerable});return t};var v=t=>_(T({},"__esModule",{value:!0}),t);var P={};N(P,{_matchAttributeSelector:()=>O,_matchClassSelector:()=>S,_matchIDSelector:()=>k,_matchTypeSelector:()=>L,matchPseudoElementSelector:()=>U,matchSelector:()=>R});module.exports=v(P);var E=require("./dom-util.js"),d=require("./parser.js"),i=require("./constant.js");const O=(t,e)=>{const{flags:c,matcher:r,name:s,value:g}=t;if(typeof c=="string"&&!/^[is]$/i.test(c)){const n=`Invalid selector ${(0,d.generateCSS)(t)}`;throw new DOMException(n,i.SYNTAX_ERR)}const{attributes:x}=e;let w;if(x&&x.length){const u=e.ownerDocument.contentType;let n;u==="text/html"?typeof c=="string"&&/^s$/i.test(c)?n=!1:n=!0:typeof c=="string"&&/^i$/i.test(c)?n=!0:n=!1;let h=(0,d.unescapeSelector)(s.name);n&&(h=h.toLowerCase());const p=new Set;if(h.indexOf("|")>-1){const{prefix:m,localName:l}=(0,d.parseAstName)(h);for(const o of x){let{name:a,value:f}=o;switch(n&&(a=a.toLowerCase(),f=f.toLowerCase()),m){case"":{l===a&&p.add(f);break}case"*":{a.indexOf(":")>-1?a.endsWith(`:${l}`)&&p.add(f):l===a&&p.add(f);break}default:if(a.indexOf(":")>-1){const[y,b]=a.split(":");if(y==="xml"&&b==="lang")continue;m===y&&l===b&&(0,E.isNamespaceDeclared)(y,e)&&p.add(f)}}}}else for(let{name:m,value:l}of x)if(n&&(m=m.toLowerCase(),l=l.toLowerCase()),m.indexOf(":")>-1){const[o,a]=m.split(":");if(o==="xml"&&a==="lang")continue;h===a&&p.add(l)}else h===m&&p.add(l);if(p.size){const{name:m,value:l}=g??{};let o;switch(m?n?o=m.toLowerCase():o=m:l?n?o=l.toLowerCase():o=l:l===""&&(o=l),r){case"=":{typeof o=="string"&&p.has(o)&&(w=e);break}case"~=":{if(o&&typeof o=="string"){for(const a of p)if(new Set(a.split(/\s+/)).has(o)){w=e;break}}break}case"|=":{if(o&&typeof o=="string"){let a;for(const f of p)if(f===o||f.startsWith(`${o}-`)){a=f;break}a&&(w=e)}break}case"^=":{if(o&&typeof o=="string"){let a;for(const f of p)if(f.startsWith(`${o}`)){a=f;break}a&&(w=e)}break}case"$=":{if(o&&typeof o=="string"){let a;for(const f of p)if(f.endsWith(`${o}`)){a=f;break}a&&(w=e)}break}case"*=":{if(o&&typeof o=="string"){let a;for(const f of p)if(f.includes(`${o}`)){a=f;break}a&&(w=e)}break}case null:default:w=e}}}return w??null},S=(t,e)=>{const c=(0,d.unescapeSelector)(t.name),{classList:r}=e;let s;return r.contains(c)&&(s=e),s??null},k=(t,e)=>{const c=(0,d.unescapeSelector)(t.name),{id:r}=e;let s;return c===r&&(s=e),s??null},L=(t,e,c={})=>{const r=(0,d.unescapeSelector)(t.name),{localName:s,namespaceURI:g,prefix:x}=e,{forgive:w}=c;let{prefix:u,localName:n}=(0,d.parseAstName)(r,e);e.ownerDocument.contentType==="text/html"&&(u=u.toLowerCase(),n=n.toLowerCase());let p,m;s.indexOf(":")>-1?[p,m]=s.split(":"):(p=x||"",m=s);let l;const o=(0,E.isNamespaceDeclared)(u,e);if(u===""&&p==="")g===null&&(n==="*"||n===m)&&(l=e);else if(u==="*")(n==="*"||n===m)&&(l=e);else if(u&&p){if(u===p){if(o)(n==="*"||n===m)&&(l=e);else if(!w){const a=`Undeclared namespace ${u}`;throw new DOMException(a,i.SYNTAX_ERR)}}}else if(u&&!w&&!o){const a=`Undeclared namespace ${u}`;throw new DOMException(a,i.SYNTAX_ERR)}return l??null},R=(t,e,c)=>{if(!t||!t.type){const g=`Unexpected node ${Object.prototype.toString.call(t).slice(i.TYPE_FROM,i.TYPE_TO)}`;throw new TypeError(g)}else if(!e||!e.nodeType){const g=`Unexpected node ${Object.prototype.toString.call(e).slice(i.TYPE_FROM,i.TYPE_TO)}`;throw new TypeError(g)}else if(e.nodeType!==i.ELEMENT_NODE){const s=`Unexpected node ${e.nodeName}`;throw new TypeError(s)}let r;switch(t.type){case i.SELECTOR_ATTR:{r=O(t,e);break}case i.SELECTOR_CLASS:{r=S(t,e);break}case i.SELECTOR_ID:{r=k(t,e);break}case i.SELECTOR_TYPE:default:r=L(t,e,c)}return r},U=(t,e={})=>{if(!t||typeof t!="string"){const g=`Unexpected type ${Object.prototype.toString.call(t).slice(i.TYPE_FROM,i.TYPE_TO)}`;throw new TypeError(g)}const{forgive:c,warn:r}=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(r){const s=`Unsupported pseudo-element ::${t}`;throw new DOMException(s,i.NOT_SUPPORTED_ERR)}break}case"part":case"slotted":{if(r){const s=`Unsupported pseudo-element ::${t}()`;throw new DOMException(s,i.NOT_SUPPORTED_ERR)}break}default:if(t.startsWith("-webkit-")){if(r){const s=`Unsupported pseudo-element ::${t}`;throw new DOMException(s,i.NOT_SUPPORTED_ERR)}}else if(!c){const s=`Unknown pseudo-element ::${t}`;throw new DOMException(s,i.SYNTAX_ERR)}}};0&&(module.exports={_matchAttributeSelector,_matchClassSelector,_matchIDSelector,_matchTypeSelector,matchPseudoElementSelector,matchSelector});
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 * NOTE: Pseudo-class selector matching is done within `./finder.js`.\n * Functions that begin with `_` are not intended for general use,\n * and are exported for testing purposes only.\n */\n\n/* import */\nimport { isNamespaceDeclared } from './dom-util.js';\nimport { generateCSS, parseAstName, unescapeSelector } from './parser.js';\n\n/* constants */\nimport {\n ELEMENT_NODE, NOT_SUPPORTED_ERR, SELECTOR_ATTR, SELECTOR_CLASS, SELECTOR_ID,\n SELECTOR_TYPE, SYNTAX_ERR, TYPE_FROM, TYPE_TO\n} from './constant.js';\n\n/**\n * match attribute selector\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node or structured clone\n * @returns {?object} - matched node\n */\nexport const _matchAttributeSelector = (ast, node) => {\n const {\n flags: astFlags, matcher: astMatcher, name: astName, value: astValue\n } = ast;\n if (typeof astFlags === 'string' && !/^[is]$/i.test(astFlags)) {\n const css = generateCSS(ast);\n const msg = `Invalid selector ${css}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n const { attributes } = node;\n let res;\n if (attributes && attributes.length) {\n const contentType = node.ownerDocument.contentType;\n let caseInsensitive;\n if (contentType === 'text/html') {\n if (typeof astFlags === 'string' && /^s$/i.test(astFlags)) {\n caseInsensitive = false;\n } else {\n caseInsensitive = true;\n }\n } else if (typeof astFlags === 'string' && /^i$/i.test(astFlags)) {\n caseInsensitive = true;\n } else {\n caseInsensitive = false;\n }\n let astAttrName = unescapeSelector(astName.name);\n if (caseInsensitive) {\n astAttrName = astAttrName.toLowerCase();\n }\n const attrValues = new Set();\n // namespaced\n if (astAttrName.indexOf('|') > -1) {\n const {\n prefix: astPrefix, localName: astLocalName\n } = parseAstName(astAttrName);\n for (const item of attributes) {\n let { name: itemName, value: itemValue } = item;\n if (caseInsensitive) {\n itemName = itemName.toLowerCase();\n itemValue = itemValue.toLowerCase();\n }\n switch (astPrefix) {\n case '': {\n if (astLocalName === itemName) {\n attrValues.add(itemValue);\n }\n break;\n }\n case '*': {\n if (itemName.indexOf(':') > -1) {\n if (itemName.endsWith(`:${astLocalName}`)) {\n attrValues.add(itemValue);\n }\n } else if (astLocalName === itemName) {\n attrValues.add(itemValue);\n }\n break;\n }\n default: {\n if (itemName.indexOf(':') > -1) {\n const [itemPrefix, itemLocalName] = itemName.split(':');\n // ignore xml:lang\n if (itemPrefix === 'xml' && itemLocalName === 'lang') {\n continue;\n } else if (astPrefix === itemPrefix &&\n astLocalName === itemLocalName) {\n const namespaceDeclared = isNamespaceDeclared(itemPrefix, node);\n if (namespaceDeclared) {\n attrValues.add(itemValue);\n }\n }\n }\n }\n }\n }\n } else {\n for (let { name: itemName, value: itemValue } of attributes) {\n if (caseInsensitive) {\n itemName = itemName.toLowerCase();\n itemValue = itemValue.toLowerCase();\n }\n if (itemName.indexOf(':') > -1) {\n const [itemPrefix, itemLocalName] = itemName.split(':');\n // ignore xml:lang\n if (itemPrefix === 'xml' && itemLocalName === 'lang') {\n continue;\n } else if (astAttrName === itemLocalName) {\n attrValues.add(itemValue);\n }\n } else if (astAttrName === itemName) {\n attrValues.add(itemValue);\n }\n }\n }\n if (attrValues.size) {\n const { name: astIdentValue, value: astStringValue } = astValue ?? {};\n let attrValue;\n if (astIdentValue) {\n if (caseInsensitive) {\n attrValue = astIdentValue.toLowerCase();\n } else {\n attrValue = astIdentValue;\n }\n } else if (astStringValue) {\n if (caseInsensitive) {\n attrValue = astStringValue.toLowerCase();\n } else {\n attrValue = astStringValue;\n }\n } else if (astStringValue === '') {\n attrValue = astStringValue;\n }\n switch (astMatcher) {\n case '=': {\n if (typeof attrValue === 'string' && attrValues.has(attrValue)) {\n res = node;\n }\n break;\n }\n case '~=': {\n if (attrValue && typeof attrValue === 'string') {\n for (const value of attrValues) {\n const item = new Set(value.split(/\\s+/));\n if (item.has(attrValue)) {\n res = node;\n break;\n }\n }\n }\n break;\n }\n case '|=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value === attrValue || value.startsWith(`${attrValue}-`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '^=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.startsWith(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '$=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.endsWith(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '*=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.includes(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case null:\n default: {\n res = node;\n }\n }\n }\n }\n return res ?? null;\n};\n\n/**\n * match class selector\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node or structured clone\n * @returns {?object} - matched node\n */\nexport const _matchClassSelector = (ast, node) => {\n const astName = unescapeSelector(ast.name);\n const { classList } = node;\n let res;\n if (classList.contains(astName)) {\n res = node;\n }\n return res ?? null;\n};\n\n/**\n * match ID selector\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node or structured clone\n * @returns {?object} - matched node\n */\nexport const _matchIDSelector = (ast, node) => {\n const astName = unescapeSelector(ast.name);\n const { id } = node;\n let res;\n if (astName === id) {\n res = node;\n }\n return res ?? null;\n};\n\n/**\n * match type selector\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node or structured clone\n * @param {object} opt - options\n * @param {boolean} [opt.forgive] - forgive undeclared namespace\n * @returns {?object} - matched node\n */\nexport const _matchTypeSelector = (ast, node, opt = {}) => {\n const astName = unescapeSelector(ast.name);\n const { localName, namespaceURI, prefix } = node;\n const { forgive } = opt;\n let {\n prefix: astPrefix, localName: astLocalName\n } = parseAstName(astName, node);\n const contentType = node.ownerDocument.contentType;\n if (contentType === 'text/html') {\n astPrefix = astPrefix.toLowerCase();\n astLocalName = astLocalName.toLowerCase();\n }\n let nodePrefix;\n let nodeLocalName;\n // just in case that the namespaced content is parsed as text/html\n if (localName.indexOf(':') > -1) {\n [nodePrefix, nodeLocalName] = localName.split(':');\n } else {\n nodePrefix = prefix || '';\n nodeLocalName = localName;\n }\n let res;\n if (astPrefix === '' && nodePrefix === '') {\n if (namespaceURI === null &&\n (astLocalName === '*' || astLocalName === nodeLocalName)) {\n res = node;\n }\n } else if (astPrefix === '*') {\n if (astLocalName === '*' || astLocalName === nodeLocalName) {\n res = node;\n }\n } else if (astPrefix && nodePrefix) {\n const namespaceDeclared = isNamespaceDeclared(nodePrefix, node);\n if (astPrefix === nodePrefix) {\n if (namespaceDeclared) {\n if (astLocalName === '*' || astLocalName === nodeLocalName) {\n res = node;\n }\n } else if (!forgive) {\n const msg = `Undeclared namespace ${astPrefix}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n }\n }\n return res ?? null;\n};\n\n/**\n * match selector\n * @param {object} ast - AST\n * @param {object} node - Element node or structured clone\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\nexport const matchSelector = (ast, node, opt) => {\n if (!ast || !ast.type) {\n const nodeType =\n Object.prototype.toString.call(ast).slice(TYPE_FROM, TYPE_TO);\n const msg = `Unexpected node ${nodeType}`;\n throw new TypeError(msg);\n } else if (!node || !node.nodeType) {\n const nodeType =\n Object.prototype.toString.call(node).slice(TYPE_FROM, TYPE_TO);\n const msg = `Unexpected node ${nodeType}`;\n throw new TypeError(msg);\n } else if (node.nodeType !== ELEMENT_NODE) {\n const msg = `Unexpected node ${node.nodeName}`;\n throw new TypeError(msg);\n }\n let matched;\n switch (ast.type) {\n case SELECTOR_ATTR: {\n matched = _matchAttributeSelector(ast, node);\n break;\n }\n case SELECTOR_CLASS: {\n matched = _matchClassSelector(ast, node);\n break;\n }\n case SELECTOR_ID: {\n matched = _matchIDSelector(ast, node);\n break;\n }\n case SELECTOR_TYPE:\n default: {\n matched = _matchTypeSelector(ast, node, opt);\n }\n }\n return matched;\n};\n\n/**\n * match pseudo-element selector\n * @param {string} astName - AST name\n * @param {object} opt - options\n * @param {boolean} [opt.forgive] - forgive unknown pseudo-element\n * @param {boolean} [opt.warn] - warn unsupported pseudo-element\n * @throws {DOMException}\n * @returns {void}\n */\nexport const matchPseudoElementSelector = (astName, opt = {}) => {\n if (!astName || typeof astName !== 'string') {\n const nodeType =\n Object.prototype.toString.call(astName).slice(TYPE_FROM, TYPE_TO);\n const msg = `Unexpected type ${nodeType}`;\n throw new TypeError(msg);\n }\n const { forgive, warn } = opt;\n switch (astName) {\n case 'after':\n case 'backdrop':\n case 'before':\n case 'cue':\n case 'cue-region':\n case 'first-letter':\n case 'first-line':\n case 'file-selector-button':\n case 'marker':\n case 'placeholder':\n case 'selection':\n case 'target-text': {\n if (warn) {\n const msg = `Unsupported pseudo-element ::${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n case 'part':\n case 'slotted': {\n if (warn) {\n const msg = `Unsupported pseudo-element ::${astName}()`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (warn) {\n const msg = `Unsupported pseudo-element ::${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n const msg = `Unknown pseudo-element ::${astName}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n }\n }\n};\n"],
5
- "mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,6BAAAE,EAAA,wBAAAC,EAAA,qBAAAC,EAAA,uBAAAC,EAAA,+BAAAC,EAAA,kBAAAC,IAAA,eAAAC,EAAAR,GAQA,IAAAS,EAAoC,yBACpCC,EAA4D,uBAG5DC,EAGO,yBASA,MAAMT,EAA0B,CAACU,EAAKC,IAAS,CACpD,KAAM,CACJ,MAAOC,EAAU,QAASC,EAAY,KAAMC,EAAS,MAAOC,CAC9D,EAAIL,EACJ,GAAI,OAAOE,GAAa,UAAY,CAAC,UAAU,KAAKA,CAAQ,EAAG,CAE7D,MAAMI,EAAM,uBADA,eAAYN,CAAG,CACQ,GACnC,MAAM,IAAI,aAAaM,EAAK,YAAU,CACxC,CACA,KAAM,CAAE,WAAAC,CAAW,EAAIN,EACvB,IAAIO,EACJ,GAAID,GAAcA,EAAW,OAAQ,CACnC,MAAME,EAAcR,EAAK,cAAc,YACvC,IAAIS,EACAD,IAAgB,YACd,OAAOP,GAAa,UAAY,OAAO,KAAKA,CAAQ,EACtDQ,EAAkB,GAElBA,EAAkB,GAEX,OAAOR,GAAa,UAAY,OAAO,KAAKA,CAAQ,EAC7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,CAAO,EAAE,MAAM,YAAW,SAAO,CAC3B,GACvC,MAAM,IAAI,UAAUE,CAAG,CACzB,CACA,KAAM,CAAE,QAAAwB,EAAS,KAAAK,CAAK,EAAIT,EAC1B,OAAQtB,EAAS,CACf,IAAK,QACL,IAAK,WACL,IAAK,SACL,IAAK,MACL,IAAK,aACL,IAAK,eACL,IAAK,aACL,IAAK,uBACL,IAAK,SACL,IAAK,cACL,IAAK,YACL,IAAK,cAAe,CAClB,GAAI+B,EAAM,CACR,MAAM7B,EAAM,gCAAgCF,CAAO,GACnD,MAAM,IAAI,aAAaE,EAAK,mBAAiB,CAC/C,CACA,KACF,CACA,IAAK,OACL,IAAK,UAAW,CACd,GAAI6B,EAAM,CACR,MAAM7B,EAAM,gCAAgCF,CAAO,KACnD,MAAM,IAAI,aAAaE,EAAK,mBAAiB,CAC/C,CACA,KACF,CACA,QACE,GAAIF,EAAQ,WAAW,UAAU,GAC/B,GAAI+B,EAAM,CACR,MAAM7B,EAAM,gCAAgCF,CAAO,GACnD,MAAM,IAAI,aAAaE,EAAK,mBAAiB,CAC/C,UACS,CAACwB,EAAS,CACnB,MAAMxB,EAAM,4BAA4BF,CAAO,GAC/C,MAAM,IAAI,aAAaE,EAAK,YAAU,CACxC,CAEJ,CACF",
4
+ "sourcesContent": ["/**\n * matcher.js\n * NOTE: Pseudo-class selector matching is done within `./finder.js`.\n * Functions that begin with `_` are not intended for general use,\n * and are exported for testing purposes only.\n */\n\n/* import */\nimport { isNamespaceDeclared } from './dom-util.js';\nimport { generateCSS, parseAstName, unescapeSelector } from './parser.js';\n\n/* constants */\nimport {\n ELEMENT_NODE, NOT_SUPPORTED_ERR, SELECTOR_ATTR, SELECTOR_CLASS, SELECTOR_ID,\n SELECTOR_TYPE, SYNTAX_ERR, TYPE_FROM, TYPE_TO\n} from './constant.js';\n\n/**\n * match attribute selector\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node or structured clone\n * @returns {?object} - matched node\n */\nexport const _matchAttributeSelector = (ast, node) => {\n const {\n flags: astFlags, matcher: astMatcher, name: astName, value: astValue\n } = ast;\n if (typeof astFlags === 'string' && !/^[is]$/i.test(astFlags)) {\n const css = generateCSS(ast);\n const msg = `Invalid selector ${css}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n const { attributes } = node;\n let res;\n if (attributes && attributes.length) {\n const contentType = node.ownerDocument.contentType;\n let caseInsensitive;\n if (contentType === 'text/html') {\n if (typeof astFlags === 'string' && /^s$/i.test(astFlags)) {\n caseInsensitive = false;\n } else {\n caseInsensitive = true;\n }\n } else if (typeof astFlags === 'string' && /^i$/i.test(astFlags)) {\n caseInsensitive = true;\n } else {\n caseInsensitive = false;\n }\n let astAttrName = unescapeSelector(astName.name);\n if (caseInsensitive) {\n astAttrName = astAttrName.toLowerCase();\n }\n const attrValues = new Set();\n // namespaced\n if (astAttrName.indexOf('|') > -1) {\n const {\n prefix: astPrefix, localName: astLocalName\n } = parseAstName(astAttrName);\n for (const item of attributes) {\n let { name: itemName, value: itemValue } = item;\n if (caseInsensitive) {\n itemName = itemName.toLowerCase();\n itemValue = itemValue.toLowerCase();\n }\n switch (astPrefix) {\n case '': {\n if (astLocalName === itemName) {\n attrValues.add(itemValue);\n }\n break;\n }\n case '*': {\n if (itemName.indexOf(':') > -1) {\n if (itemName.endsWith(`:${astLocalName}`)) {\n attrValues.add(itemValue);\n }\n } else if (astLocalName === itemName) {\n attrValues.add(itemValue);\n }\n break;\n }\n default: {\n if (itemName.indexOf(':') > -1) {\n const [itemPrefix, itemLocalName] = itemName.split(':');\n // ignore xml:lang\n if (itemPrefix === 'xml' && itemLocalName === 'lang') {\n continue;\n } else if (astPrefix === itemPrefix &&\n astLocalName === itemLocalName) {\n const namespaceDeclared = isNamespaceDeclared(itemPrefix, node);\n if (namespaceDeclared) {\n attrValues.add(itemValue);\n }\n }\n }\n }\n }\n }\n } else {\n for (let { name: itemName, value: itemValue } of attributes) {\n if (caseInsensitive) {\n itemName = itemName.toLowerCase();\n itemValue = itemValue.toLowerCase();\n }\n if (itemName.indexOf(':') > -1) {\n const [itemPrefix, itemLocalName] = itemName.split(':');\n // ignore xml:lang\n if (itemPrefix === 'xml' && itemLocalName === 'lang') {\n continue;\n } else if (astAttrName === itemLocalName) {\n attrValues.add(itemValue);\n }\n } else if (astAttrName === itemName) {\n attrValues.add(itemValue);\n }\n }\n }\n if (attrValues.size) {\n const { name: astIdentValue, value: astStringValue } = astValue ?? {};\n let attrValue;\n if (astIdentValue) {\n if (caseInsensitive) {\n attrValue = astIdentValue.toLowerCase();\n } else {\n attrValue = astIdentValue;\n }\n } else if (astStringValue) {\n if (caseInsensitive) {\n attrValue = astStringValue.toLowerCase();\n } else {\n attrValue = astStringValue;\n }\n } else if (astStringValue === '') {\n attrValue = astStringValue;\n }\n switch (astMatcher) {\n case '=': {\n if (typeof attrValue === 'string' && attrValues.has(attrValue)) {\n res = node;\n }\n break;\n }\n case '~=': {\n if (attrValue && typeof attrValue === 'string') {\n for (const value of attrValues) {\n const item = new Set(value.split(/\\s+/));\n if (item.has(attrValue)) {\n res = node;\n break;\n }\n }\n }\n break;\n }\n case '|=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value === attrValue || value.startsWith(`${attrValue}-`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '^=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.startsWith(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '$=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.endsWith(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case '*=': {\n if (attrValue && typeof attrValue === 'string') {\n let item;\n for (const value of attrValues) {\n if (value.includes(`${attrValue}`)) {\n item = value;\n break;\n }\n }\n if (item) {\n res = node;\n }\n }\n break;\n }\n case null:\n default: {\n res = node;\n }\n }\n }\n }\n return res ?? null;\n};\n\n/**\n * match class selector\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node or structured clone\n * @returns {?object} - matched node\n */\nexport const _matchClassSelector = (ast, node) => {\n const astName = unescapeSelector(ast.name);\n const { classList } = node;\n let res;\n if (classList.contains(astName)) {\n res = node;\n }\n return res ?? null;\n};\n\n/**\n * match ID selector\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node or structured clone\n * @returns {?object} - matched node\n */\nexport const _matchIDSelector = (ast, node) => {\n const astName = unescapeSelector(ast.name);\n const { id } = node;\n let res;\n if (astName === id) {\n res = node;\n }\n return res ?? null;\n};\n\n/**\n * match type selector\n * @private\n * @param {object} ast - AST\n * @param {object} node - Element node or structured clone\n * @param {object} opt - options\n * @param {boolean} [opt.forgive] - forgive undeclared namespace\n * @returns {?object} - matched node\n */\nexport const _matchTypeSelector = (ast, node, opt = {}) => {\n const astName = unescapeSelector(ast.name);\n const { localName, namespaceURI, prefix } = node;\n const { forgive } = opt;\n let {\n prefix: astPrefix, localName: astLocalName\n } = parseAstName(astName, node);\n const contentType = node.ownerDocument.contentType;\n if (contentType === 'text/html') {\n astPrefix = astPrefix.toLowerCase();\n astLocalName = astLocalName.toLowerCase();\n }\n let nodePrefix;\n let nodeLocalName;\n // just in case that the namespaced content is parsed as text/html\n if (localName.indexOf(':') > -1) {\n [nodePrefix, nodeLocalName] = localName.split(':');\n } else {\n nodePrefix = prefix || '';\n nodeLocalName = localName;\n }\n let res;\n const namespaceDeclared = isNamespaceDeclared(astPrefix, node);\n if (astPrefix === '' && nodePrefix === '') {\n if (namespaceURI === null &&\n (astLocalName === '*' || astLocalName === nodeLocalName)) {\n res = node;\n }\n } else if (astPrefix === '*') {\n if (astLocalName === '*' || astLocalName === nodeLocalName) {\n res = node;\n }\n } else if (astPrefix && nodePrefix) {\n if (astPrefix === nodePrefix) {\n if (namespaceDeclared) {\n if (astLocalName === '*' || astLocalName === nodeLocalName) {\n res = node;\n }\n } else if (!forgive) {\n const msg = `Undeclared namespace ${astPrefix}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n }\n } else if (astPrefix && !forgive && !namespaceDeclared) {\n const msg = `Undeclared namespace ${astPrefix}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n return res ?? null;\n};\n\n/**\n * match selector\n * @param {object} ast - AST\n * @param {object} node - Element node or structured clone\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\nexport const matchSelector = (ast, node, opt) => {\n if (!ast || !ast.type) {\n const nodeType =\n Object.prototype.toString.call(ast).slice(TYPE_FROM, TYPE_TO);\n const msg = `Unexpected node ${nodeType}`;\n throw new TypeError(msg);\n } else if (!node || !node.nodeType) {\n const nodeType =\n Object.prototype.toString.call(node).slice(TYPE_FROM, TYPE_TO);\n const msg = `Unexpected node ${nodeType}`;\n throw new TypeError(msg);\n } else if (node.nodeType !== ELEMENT_NODE) {\n const msg = `Unexpected node ${node.nodeName}`;\n throw new TypeError(msg);\n }\n let matched;\n switch (ast.type) {\n case SELECTOR_ATTR: {\n matched = _matchAttributeSelector(ast, node);\n break;\n }\n case SELECTOR_CLASS: {\n matched = _matchClassSelector(ast, node);\n break;\n }\n case SELECTOR_ID: {\n matched = _matchIDSelector(ast, node);\n break;\n }\n case SELECTOR_TYPE:\n default: {\n matched = _matchTypeSelector(ast, node, opt);\n }\n }\n return matched;\n};\n\n/**\n * match pseudo-element selector\n * @param {string} astName - AST name\n * @param {object} opt - options\n * @param {boolean} [opt.forgive] - forgive unknown pseudo-element\n * @param {boolean} [opt.warn] - warn unsupported pseudo-element\n * @throws {DOMException}\n * @returns {void}\n */\nexport const matchPseudoElementSelector = (astName, opt = {}) => {\n if (!astName || typeof astName !== 'string') {\n const nodeType =\n Object.prototype.toString.call(astName).slice(TYPE_FROM, TYPE_TO);\n const msg = `Unexpected type ${nodeType}`;\n throw new TypeError(msg);\n }\n const { forgive, warn } = opt;\n switch (astName) {\n case 'after':\n case 'backdrop':\n case 'before':\n case 'cue':\n case 'cue-region':\n case 'first-letter':\n case 'first-line':\n case 'file-selector-button':\n case 'marker':\n case 'placeholder':\n case 'selection':\n case 'target-text': {\n if (warn) {\n const msg = `Unsupported pseudo-element ::${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n case 'part':\n case 'slotted': {\n if (warn) {\n const msg = `Unsupported pseudo-element ::${astName}()`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n break;\n }\n default: {\n if (astName.startsWith('-webkit-')) {\n if (warn) {\n const msg = `Unsupported pseudo-element ::${astName}`;\n throw new DOMException(msg, NOT_SUPPORTED_ERR);\n }\n } else if (!forgive) {\n const msg = `Unknown pseudo-element ::${astName}`;\n throw new DOMException(msg, SYNTAX_ERR);\n }\n }\n }\n};\n"],
5
+ "mappings": "4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,6BAAAE,EAAA,wBAAAC,EAAA,qBAAAC,EAAA,uBAAAC,EAAA,+BAAAC,EAAA,kBAAAC,IAAA,eAAAC,EAAAR,GAQA,IAAAS,EAAoC,yBACpCC,EAA4D,uBAG5DC,EAGO,yBASA,MAAMT,EAA0B,CAACU,EAAKC,IAAS,CACpD,KAAM,CACJ,MAAOC,EAAU,QAASC,EAAY,KAAMC,EAAS,MAAOC,CAC9D,EAAIL,EACJ,GAAI,OAAOE,GAAa,UAAY,CAAC,UAAU,KAAKA,CAAQ,EAAG,CAE7D,MAAMI,EAAM,uBADA,eAAYN,CAAG,CACQ,GACnC,MAAM,IAAI,aAAaM,EAAK,YAAU,CACxC,CACA,KAAM,CAAE,WAAAC,CAAW,EAAIN,EACvB,IAAIO,EACJ,GAAID,GAAcA,EAAW,OAAQ,CACnC,MAAME,EAAcR,EAAK,cAAc,YACvC,IAAIS,EACAD,IAAgB,YACd,OAAOP,GAAa,UAAY,OAAO,KAAKA,CAAQ,EACtDQ,EAAkB,GAElBA,EAAkB,GAEX,OAAOR,GAAa,UA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AWaxC,EAA6B,CAACU,EAASsB,EAAM,CAAC,IAAM,CAC/D,GAAI,CAACtB,GAAW,OAAOA,GAAY,SAAU,CAG3C,MAAME,EAAM,mBADV,OAAO,UAAU,SAAS,KAAKF,CAAO,EAAE,MAAM,YAAW,SAAO,CAC3B,GACvC,MAAM,IAAI,UAAUE,CAAG,CACzB,CACA,KAAM,CAAE,QAAAwB,EAAS,KAAAK,CAAK,EAAIT,EAC1B,OAAQtB,EAAS,CACf,IAAK,QACL,IAAK,WACL,IAAK,SACL,IAAK,MACL,IAAK,aACL,IAAK,eACL,IAAK,aACL,IAAK,uBACL,IAAK,SACL,IAAK,cACL,IAAK,YACL,IAAK,cAAe,CAClB,GAAI+B,EAAM,CACR,MAAM7B,EAAM,gCAAgCF,CAAO,GACnD,MAAM,IAAI,aAAaE,EAAK,mBAAiB,CAC/C,CACA,KACF,CACA,IAAK,OACL,IAAK,UAAW,CACd,GAAI6B,EAAM,CACR,MAAM7B,EAAM,gCAAgCF,CAAO,KACnD,MAAM,IAAI,aAAaE,EAAK,mBAAiB,CAC/C,CACA,KACF,CACA,QACE,GAAIF,EAAQ,WAAW,UAAU,GAC/B,GAAI+B,EAAM,CACR,MAAM7B,EAAM,gCAAgCF,CAAO,GACnD,MAAM,IAAI,aAAaE,EAAK,mBAAiB,CAC/C,UACS,CAACwB,EAAS,CACnB,MAAMxB,EAAM,4BAA4BF,CAAO,GAC/C,MAAM,IAAI,aAAaE,EAAK,YAAU,CACxC,CAEJ,CACF",
6
6
  "names": ["matcher_exports", "__export", "_matchAttributeSelector", "_matchClassSelector", "_matchIDSelector", "_matchTypeSelector", "matchPseudoElementSelector", "matchSelector", "__toCommonJS", "import_dom_util", "import_parser", "import_constant", "ast", "node", "astFlags", "astMatcher", "astName", "astValue", "msg", "attributes", "res", "contentType", "caseInsensitive", "astAttrName", "attrValues", "astPrefix", "astLocalName", "item", "itemName", "itemValue", "itemPrefix", "itemLocalName", "astIdentValue", "astStringValue", "attrValue", "value", "classList", "id", "opt", "localName", "namespaceURI", "prefix", "forgive", "nodePrefix", "nodeLocalName", "namespaceDeclared", "matched", "warn"]
7
7
  }
package/package.json CHANGED
@@ -59,5 +59,5 @@
59
59
  "tsc": "npx tsc",
60
60
  "update-wpt": "git submodule update --init --recursive --remote"
61
61
  },
62
- "version": "2.0.3-a.2"
62
+ "version": "2.0.3-a.3"
63
63
  }
package/src/js/matcher.js CHANGED
@@ -288,6 +288,7 @@ export const _matchTypeSelector = (ast, node, opt = {}) => {
288
288
  nodeLocalName = localName;
289
289
  }
290
290
  let res;
291
+ const namespaceDeclared = isNamespaceDeclared(astPrefix, node);
291
292
  if (astPrefix === '' && nodePrefix === '') {
292
293
  if (namespaceURI === null &&
293
294
  (astLocalName === '*' || astLocalName === nodeLocalName)) {
@@ -298,7 +299,6 @@ export const _matchTypeSelector = (ast, node, opt = {}) => {
298
299
  res = node;
299
300
  }
300
301
  } else if (astPrefix && nodePrefix) {
301
- const namespaceDeclared = isNamespaceDeclared(nodePrefix, node);
302
302
  if (astPrefix === nodePrefix) {
303
303
  if (namespaceDeclared) {
304
304
  if (astLocalName === '*' || astLocalName === nodeLocalName) {
@@ -309,6 +309,9 @@ export const _matchTypeSelector = (ast, node, opt = {}) => {
309
309
  throw new DOMException(msg, SYNTAX_ERR);
310
310
  }
311
311
  }
312
+ } else if (astPrefix && !forgive && !namespaceDeclared) {
313
+ const msg = `Undeclared namespace ${astPrefix}`;
314
+ throw new DOMException(msg, SYNTAX_ERR);
312
315
  }
313
316
  return res ?? null;
314
317
  };