nwmatcher
Advanced tools
Comparing version 1.4.2 to 1.4.3
{ | ||
"name": "nwmatcher", | ||
"version": "1.4.2", | ||
"version": "1.4.3", | ||
"description": "A CSS3-compliant JavaScript selector engine.", | ||
@@ -5,0 +5,0 @@ "homepage": "http://javascript.nwbox.com/NWMatcher/", |
@@ -90,2 +90,3 @@ # [NWMatcher](http://dperini.github.io/nwmatcher/) | ||
* `SIMPLENOT`: true - true to disallow complex selectors nested in ':not()' classes | ||
* `SVG_LCASE`: false - false to disable matching lowercase tag names of SVG elements | ||
* `UNIQUE_ID`: true - true to disallow multiple elements with the same id (strict) | ||
@@ -92,0 +93,0 @@ * `USE_HTML5`: true - true to use HTML5 specs for ":checked" and similar UI states |
@@ -8,5 +8,5 @@ /* | ||
* Author: Diego Perini <diego.perini at gmail com> | ||
* Version: 1.4.2 | ||
* Version: 1.4.3 | ||
* Created: 20070722 | ||
* Release: 20170804 | ||
* Release: 20171011 | ||
* | ||
@@ -32,3 +32,3 @@ * License: | ||
var version = 'nwmatcher-1.4.2', | ||
var version = 'nwmatcher-1.4.3', | ||
@@ -344,2 +344,3 @@ doc = global.document, | ||
SIMPLENOT: true, | ||
SVG_LCASE: false, | ||
UNIQUE_ID: true, | ||
@@ -372,3 +373,3 @@ USE_HTML5: true, | ||
attributes = whitespace + '*(' + identifier + '(?::' + identifier + ')?)' + | ||
whitespace + '*(?:' + operators + whitespace + '*' + attrcheck + ')?' + whitespace + '*'; | ||
whitespace + '*(?:' + operators + whitespace + '*' + attrcheck + ')?' + whitespace + '*' + '(i)?' + whitespace + '*'; | ||
attrmatcher = attributes.replace(attrcheck, '([\\x22\\x27]*)((?:\\\\?.)*?)\\3'); | ||
@@ -484,5 +485,6 @@ | ||
else if ((match = selector.match(Patterns.tagName))) { | ||
test = Config.SVG_LCASE ? '||e.nodeName=="' + match[1].toLowerCase() + '"' : ''; | ||
source = 'if(e.nodeName' + (XML_DOCUMENT ? | ||
'=="' + match[1] + '"' : TO_UPPER_CASE + | ||
'=="' + match[1].toUpperCase() + '"') + | ||
'=="' + match[1].toUpperCase() + '"' + test) + | ||
'){' + source + '}'; | ||
@@ -512,3 +514,3 @@ } | ||
match[4] = (/\\/).test(match[4]) ? convertEscapes(match[4]) : match[4]; | ||
type = XML_DOCUMENT ? 0 : HTML_TABLE[expr.toLowerCase()]; | ||
type = match[5] == 'i' || HTML_TABLE[expr.toLowerCase()]; | ||
test = test.replace(/\%m/g, type ? match[4].toLowerCase() : match[4]); | ||
@@ -678,3 +680,3 @@ } else if (match[2] == '!=' || match[2] == '=') { | ||
if (Config.UNIQUE_ID && (parts = lastSlice.match(Optimize.ID)) && (token = parts[1])) { | ||
if (Config.UNIQUE_ID && lastSlice && (parts = lastSlice.match(Optimize.ID)) && (token = parts[1])) { | ||
if ((element = _byId(token, from))) { | ||
@@ -706,3 +708,3 @@ if (match(element, selector)) { | ||
if (!XML_DOCUMENT && GEBTN && (parts = lastSlice.match(Optimize.TAG)) && (token = parts[1])) { | ||
if (!XML_DOCUMENT && GEBTN && lastSlice && (parts = lastSlice.match(Optimize.TAG)) && (token = parts[1])) { | ||
if ((elements = from.getElementsByTagName(token)).length === 0) { return [ ]; } | ||
@@ -712,3 +714,3 @@ selector = selector.slice(0, lastPosition) + selector.slice(lastPosition).replace(token, '*'); | ||
else if (!XML_DOCUMENT && GEBCN && (parts = lastSlice.match(Optimize.CLASS)) && (token = parts[1])) { | ||
else if (!XML_DOCUMENT && GEBCN && lastSlice && (parts = lastSlice.match(Optimize.CLASS)) && (token = parts[1])) { | ||
if ((elements = from.getElementsByClassName(unescapeIdentifier(token))).length === 0) { return [ ]; } | ||
@@ -715,0 +717,0 @@ selector = selector.slice(0, lastPosition) + selector.slice(lastPosition).replace('.' + token, |
@@ -8,5 +8,5 @@ /* | ||
* Author: Diego Perini <diego.perini at gmail com> | ||
* Version: 1.4.2 | ||
* Version: 1.4.3 | ||
* Created: 20070722 | ||
* Release: 20170804 | ||
* Release: 20171011 | ||
* | ||
@@ -32,3 +32,3 @@ * License: | ||
var version = 'nwmatcher-1.4.2', | ||
var version = 'nwmatcher-1.4.3', | ||
@@ -82,3 +82,3 @@ doc = global.document, | ||
spseudos: /^\:(root|empty|(?:first|last|only)(?:-child|-of-type)|nth(?:-last)?(?:-child|-of-type)\(\s*(even|odd|(?:[-+]{0,1}\d*n\s*)?[-+]{0,1}\s*\d*)\s*\))?(.*)/i, | ||
dpseudos: /^\:(link|visited|target|active|focus|hover|checked|disabled|enabled|selected|lang\(([-\w]{2,})\)|not\(\s*(:nth(?:-last)?(?:-child|-of-type)\(\s*(?:even|odd|(?:[-+]{0,1}\d*n\s*)?[-+]{0,1}\s*\d*)\s*\)|[^()]*)\s*\))?(.*)/i, | ||
dpseudos: /^\:(link|visited|target|active|focus|hover|checked|disabled|enabled|selected|lang\(([-\w]{2,})\)|(?:matches|not)\(\s*(:nth(?:-last)?(?:-child|-of-type)\(\s*(?:even|odd|(?:[-+]{0,1}\d*n\s*)?[-+]{0,1}\s*\d*)\s*\)|[^()]*)\s*\))?(.*)/i, | ||
epseudos: /^((?:[:]{1,2}(?:after|before|first-letter|first-line))|(?:[:]{2,2}(?:selection|backdrop|placeholder)))?(.*)/i, | ||
@@ -395,2 +395,3 @@ children: RegExp('^' + whitespace + '*\\>' + whitespace + '*(.*)'), | ||
SIMPLENOT: true, | ||
SVG_LCASE: false, | ||
UNIQUE_ID: true, | ||
@@ -423,3 +424,3 @@ USE_HTML5: true, | ||
attributes = whitespace + '*(' + identifier + '(?::' + identifier + ')?)' + | ||
whitespace + '*(?:' + operators + whitespace + '*' + attrcheck + ')?' + whitespace + '*'; | ||
whitespace + '*(?:' + operators + whitespace + '*' + attrcheck + ')?' + whitespace + '*' + '(i)?' + whitespace + '*'; | ||
attrmatcher = attributes.replace(attrcheck, '([\\x22\\x27]*)((?:\\\\?.)*?)\\3'); | ||
@@ -535,5 +536,6 @@ | ||
else if ((match = selector.match(Patterns.tagName))) { | ||
test = Config.SVG_LCASE ? '||e.nodeName=="' + match[1].toLowerCase() + '"' : ''; | ||
source = 'if(e.nodeName' + (XML_DOCUMENT ? | ||
'=="' + match[1] + '"' : TO_UPPER_CASE + | ||
'=="' + match[1].toUpperCase() + '"') + | ||
'=="' + match[1].toUpperCase() + '"' + test) + | ||
'){' + source + '}'; | ||
@@ -563,3 +565,3 @@ } | ||
match[4] = (/\\/).test(match[4]) ? convertEscapes(match[4]) : match[4]; | ||
type = XML_DOCUMENT ? 0 : HTML_TABLE[expr.toLowerCase()]; | ||
type = match[5] == 'i' || HTML_TABLE[expr.toLowerCase()]; | ||
test = test.replace(/\%m/g, type ? match[4].toLowerCase() : match[4]); | ||
@@ -650,2 +652,7 @@ } else if (match[2] == '!=' || match[2] == '=') { | ||
switch (match[1].match(/^\w+/)[0]) { | ||
case 'matches': | ||
expr = match[3].replace(reTrimSpaces, ''); | ||
source = 'if(s.match(e, "' + expr.replace(/\x22/g, '\\"') + '",g)){' + source +'}'; | ||
break; | ||
case 'not': | ||
@@ -854,3 +861,3 @@ expr = match[3].replace(reTrimSpaces, ''); | ||
if (Config.UNIQUE_ID && (parts = lastSlice.match(Optimize.ID)) && (token = parts[1])) { | ||
if (Config.UNIQUE_ID && lastSlice && (parts = lastSlice.match(Optimize.ID)) && (token = parts[1])) { | ||
if ((element = _byId(token, from))) { | ||
@@ -882,3 +889,3 @@ if (match(element, selector)) { | ||
if (!XML_DOCUMENT && GEBTN && (parts = lastSlice.match(Optimize.TAG)) && (token = parts[1])) { | ||
if (!XML_DOCUMENT && GEBTN && lastSlice && (parts = lastSlice.match(Optimize.TAG)) && (token = parts[1])) { | ||
if ((elements = from.getElementsByTagName(token)).length === 0) { return [ ]; } | ||
@@ -888,3 +895,3 @@ selector = selector.slice(0, lastPosition) + selector.slice(lastPosition).replace(token, '*'); | ||
else if (!XML_DOCUMENT && GEBCN && (parts = lastSlice.match(Optimize.CLASS)) && (token = parts[1])) { | ||
else if (!XML_DOCUMENT && GEBCN && lastSlice && (parts = lastSlice.match(Optimize.CLASS)) && (token = parts[1])) { | ||
if ((elements = from.getElementsByClassName(unescapeIdentifier(token))).length === 0) { return [ ]; } | ||
@@ -891,0 +898,0 @@ selector = selector.slice(0, lastPosition) + selector.slice(lastPosition).replace('.' + token, |
@@ -8,5 +8,5 @@ /* | ||
* Author: Diego Perini <diego.perini at gmail com> | ||
* Version: 1.4.2 | ||
* Version: 1.4.3 | ||
* Created: 20070722 | ||
* Release: 20170804 | ||
* Release: 20171011 | ||
* | ||
@@ -32,3 +32,3 @@ * License: | ||
var version = 'nwmatcher-1.4.2', | ||
var version = 'nwmatcher-1.4.3', | ||
@@ -128,3 +128,3 @@ // processing context & root element | ||
// uistates + dynamic + negation pseudo-classes | ||
dpseudos: /^\:(link|visited|target|active|focus|hover|checked|disabled|enabled|selected|lang\(([-\w]{2,})\)|not\(\s*(:nth(?:-last)?(?:-child|-of-type)\(\s*(?:even|odd|(?:[-+]{0,1}\d*n\s*)?[-+]{0,1}\s*\d*)\s*\)|[^()]*)\s*\))?(.*)/i, | ||
dpseudos: /^\:(link|visited|target|active|focus|hover|checked|disabled|enabled|selected|lang\(([-\w]{2,})\)|(?:matches|not)\(\s*(:nth(?:-last)?(?:-child|-of-type)\(\s*(?:even|odd|(?:[-+]{0,1}\d*n\s*)?[-+]{0,1}\s*\d*)\s*\)|[^()]*)\s*\))?(.*)/i, | ||
// pseudo-elements selectors | ||
@@ -862,2 +862,5 @@ epseudos: /^((?:[:]{1,2}(?:after|before|first-letter|first-line))|(?:[:]{2,2}(?:selection|backdrop|placeholder)))?(.*)/i, | ||
// true to match lowercase tag names of SVG elements in HTML | ||
SVG_LCASE: false, | ||
// strict QSA match all non-unique IDs (false) | ||
@@ -910,3 +913,3 @@ // speed & libs compat match unique ID (true) | ||
attributes = whitespace + '*(' + identifier + '(?::' + identifier + ')?)' + | ||
whitespace + '*(?:' + operators + whitespace + '*' + attrcheck + ')?' + whitespace + '*'; | ||
whitespace + '*(?:' + operators + whitespace + '*' + attrcheck + ')?' + whitespace + '*' + '(i)?' + whitespace + '*'; | ||
attrmatcher = attributes.replace(attrcheck, '([\\x22\\x27]*)((?:\\\\?.)*?)\\3'); | ||
@@ -1077,5 +1080,6 @@ | ||
// depending on their creation NAMESPACE in createElementNS() | ||
test = Config.SVG_LCASE ? '||e.nodeName=="' + match[1].toLowerCase() + '"' : ''; | ||
source = 'if(e.nodeName' + (XML_DOCUMENT ? | ||
'=="' + match[1] + '"' : '.toUpperCase()' + | ||
'=="' + match[1].toUpperCase() + '"') + | ||
'=="' + match[1].toUpperCase() + '"' + test) + | ||
'){' + source + '}'; | ||
@@ -1119,3 +1123,3 @@ } | ||
// case treatment depends on document type | ||
type = XML_DOCUMENT ? 0 : HTML_TABLE[expr.toLowerCase()]; | ||
type = match[5] == 'i' || HTML_TABLE[expr.toLowerCase()]; | ||
test = test.replace(/\%m/g, type ? match[4].toLowerCase() : match[4]); | ||
@@ -1237,2 +1241,3 @@ } else if (match[2] == '!=' || match[2] == '=') { | ||
// *** UI element states and dynamic pseudo-classes | ||
// CSS4 :matches | ||
// CSS3 :not, :checked, :enabled, :disabled, :target | ||
@@ -1244,2 +1249,8 @@ // CSS3 :active, :hover, :focus | ||
switch (match[1].match(/^\w+/)[0]) { | ||
// CSS4 matches pseudo-class | ||
case 'matches': | ||
expr = match[3].replace(reTrimSpaces, ''); | ||
source = 'if(s.match(e, "' + expr.replace(/\x22/g, '\\"') + '",g)){' + source +'}'; | ||
break; | ||
// CSS3 negation pseudo-class | ||
@@ -1553,3 +1564,3 @@ case 'not': | ||
// ID optimization RTL, to reduce number of elements to visit | ||
if (Config.UNIQUE_ID && (parts = lastSlice.match(Optimize.ID)) && (token = parts[1])) { | ||
if (Config.UNIQUE_ID && lastSlice && (parts = lastSlice.match(Optimize.ID)) && (token = parts[1])) { | ||
if ((element = _byId(token, from))) { | ||
@@ -1582,3 +1593,3 @@ if (match(element, selector)) { | ||
if (!NATIVE_GEBCN && (parts = lastSlice.match(Optimize.TAG)) && (token = parts[1])) { | ||
if (!NATIVE_GEBCN && lastSlice && (parts = lastSlice.match(Optimize.TAG)) && (token = parts[1])) { | ||
if ((elements = _byTag(token, from)).length === 0) { return [ ]; } | ||
@@ -1588,3 +1599,3 @@ selector = selector.slice(0, lastPosition) + selector.slice(lastPosition).replace(token, '*'); | ||
else if ((parts = lastSlice.match(Optimize.CLASS)) && (token = parts[1])) { | ||
else if (lastSlice && (parts = lastSlice.match(Optimize.CLASS)) && (token = parts[1])) { | ||
if ((elements = _byClass(token, from)).length === 0) { return [ ]; } | ||
@@ -1605,3 +1616,3 @@ selector = selector.slice(0, lastPosition) + selector.slice(lastPosition).replace('.' + token, | ||
else if (NATIVE_GEBCN && (parts = lastSlice.match(Optimize.TAG)) && (token = parts[1])) { | ||
else if (NATIVE_GEBCN && lastSlice && (parts = lastSlice.match(Optimize.TAG)) && (token = parts[1])) { | ||
if ((elements = _byTag(token, from)).length === 0) { return [ ]; } | ||
@@ -1608,0 +1619,0 @@ selector = selector.slice(0, lastPosition) + selector.slice(lastPosition).replace(token, '*'); |
151853
3704
114