Comparing version 1.3.9 to 1.4.0
{ | ||
"name": "nwmatcher", | ||
"version": "1.3.9", | ||
"version": "1.4.0", | ||
"description": "A CSS3-compliant JavaScript selector engine.", | ||
@@ -5,0 +5,0 @@ "homepage": "http://javascript.nwbox.com/NWMatcher/", |
@@ -81,11 +81,16 @@ # [NWMatcher](http://dperini.github.io/nwmatcher/) | ||
The following options exist and can be set to `true` or `false`: | ||
The following is the list of currently available configuration options, their default values and descriptions, they are boolean flags that can be set to `true` or `false`: | ||
* `CACHING`: enable caching of results | ||
* `SHORTCUTS`: allow accepting mangled selectors | ||
* `SIMPLENOT`: disallow nested complex `:not()` selectors | ||
* `UNIQUE_ID`: disallow multiple elements with same ID | ||
* `USE_QSAPI`: enable native `querySelectorAll` if available | ||
* `USE_HTML5`: enable special HTML5 rules, related to the relationship between `:checked` and `:selected` | ||
* `VERBOSITY`: choose between throwing errors or just console warnings | ||
* `CACHING`: false - false to disable caching of result sets, true to enable | ||
* `ESCAPECHR`: true - true to allow CSS escaped identifiers, false to disallow | ||
* `NON_ASCII`: true - true to allow identifiers containing non-ASCII (utf-8) chars | ||
* `SELECTOR3`: true - switch syntax RE, true to use Level 3, false to use Level 2 | ||
* `UNICODE16`: true - true to allow identifiers containing Unicode (utf-16) chars | ||
* `SHORTCUTS`: false - false to disable mangled selector strings like "+div" or "ul>" | ||
* `SIMPLENOT`: true - true to disallow complex selectors nested in ':not()' classes | ||
* `UNIQUE_ID`: true - true to disallow multiple elements with the same id (strict) | ||
* `USE_HTML5`: true - true to use HTML5 specs for ":checked" and similar UI states | ||
* `USE_QSAPI`: true - true to use browsers native Query Selector API if available | ||
* `VERBOSITY`: true - true to throw exceptions, false to skip throwing exceptions | ||
* `LOGERRORS`: true - true to print console errors or warnings, false to mute them | ||
@@ -92,0 +97,0 @@ Example: |
/* | ||
* Copyright (C) 2007-2016 Diego Perini | ||
* Copyright (C) 2007-2017 Diego Perini | ||
* All rights reserved. | ||
@@ -4,0 +4,0 @@ * |
/* | ||
* Copyright (C) 2007-2016 Diego Perini | ||
* Copyright (C) 2007-2017 Diego Perini | ||
* All rights reserved. | ||
@@ -4,0 +4,0 @@ * |
/* | ||
* Copyright (C) 2007-2016 Diego Perini | ||
* Copyright (C) 2007-2017 Diego Perini | ||
* All rights reserved. | ||
@@ -196,3 +196,3 @@ * | ||
if ('compatMode' in doc) { | ||
source = 'if(!' + NW.Dom.compile(expr, '', false) + '(e,s,r,d,h,g)){' + source + '}'; | ||
source = 'if(!' + NW.Dom.compile(expr, '', false) + '(e,s,d,h,g)){' + source + '}'; | ||
} else { | ||
@@ -275,1 +275,36 @@ source = 'if(!s.match(e, "' + expr.replace(/\x22/g, '\\"') + '",g)){' + source +'}'; | ||
})(this)); | ||
NW.Dom.registerSelector( | ||
'nwmatcher:epseudos', | ||
/^((?:[:]{1,2}(?:after|before|first-letter|first-line))|(?:[:]{2,2}(?:selection|backdrop|placeholder)))?(.*)/i, | ||
(function(global) { | ||
return function(match, source) { | ||
var status = true; | ||
switch (match[1].match(/(\w+)$/)[0]) { | ||
case 'after': | ||
case 'before': | ||
case 'first-letter': | ||
case 'first-line': | ||
case 'selection': | ||
case 'backdrop': | ||
case 'placeholder': | ||
source = 'if(!(/1|11/).test(e.nodeType)){' + source + '}'; | ||
break; | ||
default: | ||
status = false; | ||
break; | ||
} | ||
return { | ||
'source': source, | ||
'status': status | ||
}; | ||
}; | ||
})(this)); |
/* | ||
* Copyright (C) 2007-2016 Diego Perini | ||
* Copyright (C) 2007-2017 Diego Perini | ||
* All rights reserved. | ||
@@ -4,0 +4,0 @@ * |
/* | ||
* Copyright (C) 2007-2016 Diego Perini | ||
* Copyright (C) 2007-2017 Diego Perini | ||
* All rights reserved. | ||
@@ -8,5 +8,5 @@ * | ||
* Author: Diego Perini <diego.perini at gmail com> | ||
* Version: 1.3.9 | ||
* Version: 1.4.0 | ||
* Created: 20070722 | ||
* Release: 20161026 | ||
* Release: 20170520 | ||
* | ||
@@ -32,3 +32,3 @@ * License: | ||
var version = 'nwmatcher-1.3.9', | ||
var version = 'nwmatcher-1.4.0', | ||
@@ -51,3 +51,3 @@ doc = global.document, | ||
prefixes = '[#.:]?', | ||
prefixes = '(?:[#.:]|::)?', | ||
operators = '([~*^$|!]?={1})', | ||
@@ -323,3 +323,3 @@ whitespace = '[\\x20\\t\\n\\r\\f]', | ||
if (Config.VERBOSITY) { throw Error(message); } | ||
if (console && console.log) { | ||
if (Config.LOGERRORS && console && console.log) { | ||
console.log(message); | ||
@@ -339,3 +339,4 @@ } | ||
USE_HTML5: true, | ||
VERBOSITY: true | ||
VERBOSITY: true, | ||
LOGERRORS: true | ||
}, | ||
@@ -363,3 +364,3 @@ | ||
attrcheck = '(' + quotedvalue + '|' + identifier + ')'; | ||
attributes = whitespace + '*(' + identifier + ':?' + identifier + ')' + | ||
attributes = whitespace + '*(' + identifier + '(?::' + identifier + ')?)' + | ||
whitespace + '*(?:' + operators + whitespace + '*' + attrcheck + ')?' + whitespace + '*'; | ||
@@ -445,6 +446,6 @@ attrmatcher = attributes.replace(attrcheck, '([\\x22\\x27]*)((?:\\\\?.)*?)\\3'); | ||
if (mode) { | ||
return Function('c,s,r,d,h,g,f,v', | ||
'var N,n,x=0,k=-1,e;main:while((e=c[++k])){' + source + '}return r;'); | ||
return Function('c,s,d,h,g,f', | ||
'var N,n,x=0,k=-1,e,r=[];main:while((e=c[++k])){' + source + '}return r;'); | ||
} else { | ||
return Function('e,s,r,d,h,g,f,v', | ||
return Function('e,s,d,h,g,f', | ||
'var N,n,x=0,k=e;' + source + 'return false;'); | ||
@@ -454,8 +455,2 @@ } | ||
FILTER = | ||
'var z=v[@]||(v[@]=[]),l=z.length-1;' + | ||
'while(l>=0&&z[l]!==e)--l;' + | ||
'if(l!==-1){break;}' + | ||
'z[z.length]=e;', | ||
compileSelector = | ||
@@ -521,3 +516,2 @@ function(selector, source, mode) { | ||
else if ((match = selector.match(Patterns.adjacent))) { | ||
source = (mode ? '' : FILTER.replace(/@/g, k)) + source; | ||
source = 'var N' + k + '=e;while(e&&(e=e.previousSibling)){if(e.nodeName>"@"){' + source + 'break;}}e=N' + k + ';'; | ||
@@ -527,3 +521,2 @@ } | ||
else if ((match = selector.match(Patterns.relative))) { | ||
source = (mode ? '' : FILTER.replace(/@/g, k)) + source; | ||
source = 'var N' + k + '=e;e=e.parentNode.firstChild;while(e&&e!==N' + k + '){if(e.nodeName>"@"){' + source + '}e=e.nextSibling;}e=N' + k + ';'; | ||
@@ -533,3 +526,2 @@ } | ||
else if ((match = selector.match(Patterns.children))) { | ||
source = (mode ? '' : FILTER.replace(/@/g, k)) + source; | ||
source = 'var N' + k + '=e;while(e&&e!==h&&e!==g&&(e=e.parentNode)){' + source + 'break;}e=N' + k + ';'; | ||
@@ -539,3 +531,2 @@ } | ||
else if ((match = selector.match(Patterns.ancestor))) { | ||
source = (mode ? '' : FILTER.replace(/@/g, k)) + source; | ||
source = 'var N' + k + '=e;while(e&&e!==h&&e!==g&&(e=e.parentNode)){' + source + '}e=N' + k + ';'; | ||
@@ -551,2 +542,3 @@ } | ||
result = Selectors[expr].Callback(match, source); | ||
if ('match' in result) { match = result.match; } | ||
source = result.source; | ||
@@ -618,3 +610,3 @@ status = result.status; | ||
return matchResolvers[selector](element, Snapshot, [ ], doc, root, from, callback, { }); | ||
return matchResolvers[selector](element, Snapshot, doc, root, from, callback); | ||
}, | ||
@@ -732,3 +724,3 @@ | ||
elements = selectResolvers[selector](elements, Snapshot, [ ], doc, root, from, callback, { }); | ||
elements = selectResolvers[selector](elements, Snapshot, doc, root, from, callback); | ||
@@ -735,0 +727,0 @@ Config.CACHING && Dom.saveResults(original, from, doc, elements); |
/* | ||
* Copyright (C) 2007-2016 Diego Perini | ||
* Copyright (C) 2007-2017 Diego Perini | ||
* All rights reserved. | ||
@@ -8,5 +8,5 @@ * | ||
* Author: Diego Perini <diego.perini at gmail com> | ||
* Version: 1.3.9 | ||
* Version: 1.4.0 | ||
* Created: 20070722 | ||
* Release: 20161026 | ||
* Release: 20170520 | ||
* | ||
@@ -32,3 +32,3 @@ * License: | ||
var version = 'nwmatcher-1.3.9', | ||
var version = 'nwmatcher-1.4.0', | ||
@@ -51,3 +51,3 @@ doc = global.document, | ||
prefixes = '[#.:]?', | ||
prefixes = '(?:[#.:]|::)?', | ||
operators = '([~*^$|!]?={1})', | ||
@@ -84,2 +84,3 @@ whitespace = '[\\x20\\t\\n\\r\\f]', | ||
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, | ||
epseudos: /^((?:[:]{1,2}(?:after|before|first-letter|first-line))|(?:[:]{2,2}(?:selection|backdrop|placeholder)))?(.*)/i, | ||
children: RegExp('^' + whitespace + '*\\>' + whitespace + '*(.*)'), | ||
@@ -373,3 +374,3 @@ adjacent: RegExp('^' + whitespace + '*\\+' + whitespace + '*(.*)'), | ||
if (Config.VERBOSITY) { throw Error(message); } | ||
if (console && console.log) { | ||
if (Config.LOGERRORS && console && console.log) { | ||
console.log(message); | ||
@@ -389,3 +390,4 @@ } | ||
USE_HTML5: true, | ||
VERBOSITY: true | ||
VERBOSITY: true, | ||
LOGERRORS: true | ||
}, | ||
@@ -413,3 +415,3 @@ | ||
attrcheck = '(' + quotedvalue + '|' + identifier + ')'; | ||
attributes = whitespace + '*(' + identifier + ':?' + identifier + ')' + | ||
attributes = whitespace + '*(' + identifier + '(?::' + identifier + ')?)' + | ||
whitespace + '*(?:' + operators + whitespace + '*' + attrcheck + ')?' + whitespace + '*'; | ||
@@ -495,6 +497,6 @@ attrmatcher = attributes.replace(attrcheck, '([\\x22\\x27]*)((?:\\\\?.)*?)\\3'); | ||
if (mode) { | ||
return Function('c,s,r,d,h,g,f,v', | ||
'var N,n,x=0,k=-1,e;main:while((e=c[++k])){' + source + '}return r;'); | ||
return Function('c,s,d,h,g,f', | ||
'var N,n,x=0,k=-1,e,r=[];main:while((e=c[++k])){' + source + '}return r;'); | ||
} else { | ||
return Function('e,s,r,d,h,g,f,v', | ||
return Function('e,s,d,h,g,f', | ||
'var N,n,x=0,k=e;' + source + 'return false;'); | ||
@@ -504,8 +506,2 @@ } | ||
FILTER = | ||
'var z=v[@]||(v[@]=[]),l=z.length-1;' + | ||
'while(l>=0&&z[l]!==e)--l;' + | ||
'if(l!==-1){break;}' + | ||
'z[z.length]=e;', | ||
compileSelector = | ||
@@ -571,3 +567,2 @@ function(selector, source, mode) { | ||
else if ((match = selector.match(Patterns.adjacent))) { | ||
source = (mode ? '' : FILTER.replace(/@/g, k)) + source; | ||
source = 'var N' + k + '=e;while(e&&(e=e.previousSibling)){if(e.nodeName>"@"){' + source + 'break;}}e=N' + k + ';'; | ||
@@ -577,3 +572,2 @@ } | ||
else if ((match = selector.match(Patterns.relative))) { | ||
source = (mode ? '' : FILTER.replace(/@/g, k)) + source; | ||
source = 'var N' + k + '=e;e=e.parentNode.firstChild;while(e&&e!==N' + k + '){if(e.nodeName>"@"){' + source + '}e=e.nextSibling;}e=N' + k + ';'; | ||
@@ -583,3 +577,2 @@ } | ||
else if ((match = selector.match(Patterns.children))) { | ||
source = (mode ? '' : FILTER.replace(/@/g, k)) + source; | ||
source = 'var N' + k + '=e;while(e&&e!==h&&e!==g&&(e=e.parentNode)){' + source + 'break;}e=N' + k + ';'; | ||
@@ -589,3 +582,2 @@ } | ||
else if ((match = selector.match(Patterns.ancestor))) { | ||
source = (mode ? '' : FILTER.replace(/@/g, k)) + source; | ||
source = 'var N' + k + '=e;while(e&&e!==h&&e!==g&&(e=e.parentNode)){' + source + '}e=N' + k + ';'; | ||
@@ -656,3 +648,3 @@ } | ||
if ('compatMode' in doc) { | ||
source = 'if(!' + compile(expr, '', false) + '(e,s,r,d,h,g)){' + source + '}'; | ||
source = 'if(!' + compile(expr, '', false) + '(e,s,d,h,g)){' + source + '}'; | ||
} else { | ||
@@ -715,2 +707,6 @@ source = 'if(!s.match(e, "' + expr.replace(/\x22/g, '\\"') + '",g)){' + source +'}'; | ||
else if ((match = selector.match(Patterns.epseudos)) && match[1]) { | ||
source = 'if(!(/1|11/).test(e.nodeType)){' + source + '}'; | ||
} | ||
else { | ||
@@ -723,2 +719,3 @@ | ||
result = Selectors[expr].Callback(match, source); | ||
if ('match' in result) { match = result.match; } | ||
source = result.source; | ||
@@ -790,3 +787,3 @@ status = result.status; | ||
return matchResolvers[selector](element, Snapshot, [ ], doc, root, from, callback, { }); | ||
return matchResolvers[selector](element, Snapshot, doc, root, from, callback); | ||
}, | ||
@@ -904,3 +901,3 @@ | ||
elements = selectResolvers[selector](elements, Snapshot, [ ], doc, root, from, callback, { }); | ||
elements = selectResolvers[selector](elements, Snapshot, doc, root, from, callback); | ||
@@ -907,0 +904,0 @@ Config.CACHING && Dom.saveResults(original, from, doc, elements); |
/* | ||
* Copyright (C) 2007-2016 Diego Perini | ||
* Copyright (C) 2007-2017 Diego Perini | ||
* All rights reserved. | ||
@@ -8,5 +8,5 @@ * | ||
* Author: Diego Perini <diego.perini at gmail com> | ||
* Version: 1.3.9 | ||
* Version: 1.4.0 | ||
* Created: 20070722 | ||
* Release: 20161026 | ||
* Release: 20170520 | ||
* | ||
@@ -32,3 +32,3 @@ * License: | ||
var version = 'nwmatcher-1.3.9', | ||
var version = 'nwmatcher-1.4.0', | ||
@@ -58,3 +58,3 @@ // processing context & root element | ||
// (id, class & pseudo-class) | ||
prefixes = '[#.:]?', | ||
prefixes = '(?:[#.:]|::)?', | ||
@@ -130,2 +130,4 @@ // accepted attribute operators | ||
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, | ||
// pseudo-elements selectors | ||
epseudos: /^((?:[:]{1,2}(?:after|before|first-letter|first-line))|(?:[:]{2,2}(?:selection|backdrop|placeholder)))?(.*)/i, | ||
// E > F | ||
@@ -842,3 +844,3 @@ children: RegExp('^' + whitespace + '*\\>' + whitespace + '*(.*)'), | ||
if (Config.VERBOSITY) { throw Error(message); } | ||
if (console && console.log) { | ||
if (Config.LOGERRORS && console && console.log) { | ||
console.log(message); | ||
@@ -850,24 +852,24 @@ } | ||
// used to enable/disable caching of result sets | ||
// true to enable caching of result sets, false to disable | ||
CACHING: false, | ||
// used to enable/disable CSS escaped identifiers | ||
// true to allow CSS escaped identifiers, false to disallow | ||
ESCAPECHR: true, | ||
// add non-ascii (utf-8) to the identifier syntax RE | ||
// true to allow identifiers containing non-ASCII (utf-8) chars | ||
NON_ASCII: true, | ||
// switch between CSS2 and CSS3 identifier syntax RE | ||
// switch syntax RE, true to use Level 3, false to use Level 2 | ||
SELECTOR3: true, | ||
// add Unicode (utf-16) to the identifier syntax RE | ||
// true to allow identifiers containing Unicode (utf-16) chars | ||
UNICODE16: true, | ||
// by default do not add missing left/right context | ||
// to selector string shortcuts like "+div" or "ul>" | ||
// to mangled selector strings like "+div" or "ul>" | ||
// callable Dom.shortcuts method has to be available | ||
SHORTCUTS: false, | ||
// by default disable complex selectors nested in | ||
// ':not()' pseudo-classes, as for specifications | ||
// true to disable complex selectors nested in | ||
// ':not()' pseudo-classes as for specifications | ||
SIMPLENOT: true, | ||
@@ -879,11 +881,15 @@ | ||
// HTML5 handling for the ":checked" pseudo-class | ||
// true to follow HTML5 specs handling of ":checked" | ||
// pseudo-class and similar UI states (indeterminate) | ||
USE_HTML5: true, | ||
// controls enabling the Query Selector API branch | ||
// true to use browsers native Query Selector API if available | ||
USE_QSAPI: NATIVE_QSAPI, | ||
// controls the engine error/warning notifications | ||
VERBOSITY: true | ||
// true to throw exceptions, false to skip throwing exceptions | ||
VERBOSITY: true, | ||
// true to print console errors or warnings, false to mute them | ||
LOGERRORS: true | ||
}, | ||
@@ -918,3 +924,3 @@ | ||
attrcheck = '(' + quotedvalue + '|' + identifier + ')'; | ||
attributes = whitespace + '*(' + identifier + ':?' + identifier + ')' + | ||
attributes = whitespace + '*(' + identifier + '(?::' + identifier + ')?)' + | ||
whitespace + '*(?:' + operators + whitespace + '*' + attrcheck + ')?' + whitespace + '*'; | ||
@@ -1040,7 +1046,7 @@ attrmatcher = attributes.replace(attrcheck, '([\\x22\\x27]*)((?:\\\\?.)*?)\\3'); | ||
// for select method | ||
return Function('c,s,r,d,h,g,f,v', | ||
'var N,n,x=0,k=-1,e;main:while((e=c[++k])){' + source + '}return r;'); | ||
return Function('c,s,d,h,g,f', | ||
'var N,n,x=0,k=-1,e,r=[];main:while((e=c[++k])){' + source + '}return r;'); | ||
} else { | ||
// for match method | ||
return Function('e,s,r,d,h,g,f,v', | ||
return Function('e,s,d,h,g,f', | ||
'var N,n,x=0,k=e;' + source + 'return false;'); | ||
@@ -1050,9 +1056,2 @@ } | ||
// allows to cache already visited nodes | ||
FILTER = | ||
'var z=v[@]||(v[@]=[]),l=z.length-1;' + | ||
'while(l>=0&&z[l]!==e)--l;' + | ||
'if(l!==-1){break;}' + | ||
'z[z.length]=e;', | ||
// compile a CSS3 string selector into ad-hoc javascript matching function | ||
@@ -1153,3 +1152,2 @@ // @return string (to be compiled) | ||
else if ((match = selector.match(Patterns.adjacent))) { | ||
source = (mode ? '' : FILTER.replace(/@/g, k)) + source; | ||
source = NATIVE_TRAVERSAL_API ? | ||
@@ -1163,3 +1161,2 @@ 'var N' + k + '=e;while(e&&(e=e.previousElementSibling)){' + source + 'break;}e=N' + k + ';' : | ||
else if ((match = selector.match(Patterns.relative))) { | ||
source = (mode ? '' : FILTER.replace(/@/g, k)) + source; | ||
source = NATIVE_TRAVERSAL_API ? | ||
@@ -1175,3 +1172,2 @@ ('var N' + k + '=e;e=e.parentNode.firstElementChild;' + | ||
else if ((match = selector.match(Patterns.children))) { | ||
source = (mode ? '' : FILTER.replace(/@/g, k)) + source; | ||
source = 'var N' + k + '=e;while(e&&e!==h&&e!==g&&(e=e.parentNode)){' + source + 'break;}e=N' + k + ';'; | ||
@@ -1183,3 +1179,2 @@ } | ||
else if ((match = selector.match(Patterns.ancestor))) { | ||
source = (mode ? '' : FILTER.replace(/@/g, k)) + source; | ||
source = 'var N' + k + '=e;while(e&&e!==h&&e!==g&&(e=e.parentNode)){' + source + '}e=N' + k + ';'; | ||
@@ -1283,3 +1278,3 @@ } | ||
if ('compatMode' in doc) { | ||
source = 'if(!' + compile(expr, '', false) + '(e,s,r,d,h,g)){' + source + '}'; | ||
source = 'if(!' + compile(expr, '', false) + '(e,s,d,h,g)){' + source + '}'; | ||
} else { | ||
@@ -1366,2 +1361,6 @@ source = 'if(!s.match(e, "' + expr.replace(/\x22/g, '\\"') + '",g)){' + source +'}'; | ||
else if ((match = selector.match(Patterns.epseudos)) && match[1]) { | ||
source = 'if(!(/1|11/).test(e.nodeType)){' + source + '}'; | ||
} | ||
else { | ||
@@ -1376,2 +1375,3 @@ | ||
result = Selectors[expr].Callback(match, source); | ||
if ('match' in result) { match = result.match; } | ||
source = result.source; | ||
@@ -1465,3 +1465,3 @@ status = result.status; | ||
return matchResolvers[selector](element, Snapshot, [ ], doc, root, from, callback, { }); | ||
return matchResolvers[selector](element, Snapshot, doc, root, from, callback); | ||
}, | ||
@@ -1648,3 +1648,3 @@ | ||
elements = selectResolvers[selector](elements, Snapshot, [ ], doc, root, from, callback, { }); | ||
elements = selectResolvers[selector](elements, Snapshot, doc, root, from, callback); | ||
@@ -1651,0 +1651,0 @@ Config.CACHING && Dom.saveResults(original, from, doc, elements); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
149758
3675
113