Socket
Socket
Sign inDemoInstall

nwmatcher

Package Overview
Dependencies
0
Maintainers
2
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.3.8 to 1.3.9

2

package.json
{
"name": "nwmatcher",
"version": "1.3.8",
"version": "1.3.9",
"description": "A CSS3-compliant JavaScript selector engine.",

@@ -5,0 +5,0 @@ "homepage": "http://javascript.nwbox.com/NWMatcher/",

@@ -24,7 +24,7 @@ /*

// create or extend NW namespace
((global.NW || (global.NW = global.Object())) &&
(global.NW.Dom || (global.NW.Dom = global.Object()))),
((global.NW || (global.NW = { })) &&
(global.NW.Dom || (global.NW.Dom = { })),
Contexts = global.Object(),
Results = global.Object(),
Contexts = { },
Results = { },

@@ -38,2 +38,5 @@ isEnabled = false,

// timing pauses
now = 0,
// last time cache initialization was called

@@ -76,6 +79,6 @@ lastCalled = 0,

// hammered by dom mutations (jdalton)
now = (new global.Date).getTime();
now = (new Date).getTime();
if ((now - lastCalled) < minCacheRest) {
isPaused = isExpired = true;
global.setTimeout(function() { isPaused = false; }, minCacheRest);
setTimeout(function() { isPaused = false; }, minCacheRest);
} else setCache(true, doc);

@@ -150,4 +153,4 @@ lastCalled = now;

isExpired = true;
Contexts = global.Object();
Results = global.Object();
Contexts = { };
Results = { };
};

@@ -154,0 +157,0 @@

@@ -63,6 +63,6 @@ /*

// compiler will add this to "source"
return global.Object({
return {
'source': source,
'status': status
});
};

@@ -120,6 +120,6 @@ };

// compiler will add this to "source"
return global.Object({
return {
'source': source,
'status': status
});
};

@@ -126,0 +126,0 @@ };

@@ -26,7 +26,7 @@ /*

var LINK_NODES = global.Object({
var LINK_NODES = {
'a': 1, 'A': 1,
'area': 1, 'AREA': 1,
'link': 1, 'LINK': 1
}),
},

@@ -126,4 +126,4 @@ root = document.documentElement,

} else {
b = ((n = match[2].match(/(-?\d+)$/)) ? global.parseInt(n[1], 10) : 0);
a = ((n = match[2].match(/(-?\d*)n/i)) ? global.parseInt(n[1], 10) : 0);
b = ((n = match[2].match(/(-?\d+)$/)) ? parseInt(n[1], 10) : 0);
a = ((n = match[2].match(/(-?\d*)n/i)) ? parseInt(n[1], 10) : 0);
if (n && n[1] == '-') a = -1;

@@ -162,6 +162,6 @@ }

return global.Object({
return {
'source': source,
'status': status
});
};

@@ -181,5 +181,5 @@ };

reTrimSpace = global.RegExp('^\\s+|\\s+$', 'g'),
reTrimSpace = RegExp('^\\s+|\\s+$', 'g'),
reSimpleNot = global.RegExp('^((?!:not)' +
reSimpleNot = RegExp('^((?!:not)' +
'(' + Tokens.prefixes + '|' + Tokens.identifier +

@@ -270,6 +270,6 @@ '|\\([^()]*\\))+|\\[' + Tokens.attributes + '\\])$');

return global.Object({
return {
'source': source,
'status': status
});
};

@@ -276,0 +276,0 @@ };

@@ -27,6 +27,6 @@ /*

HTML5PseudoClasses = global.Object({
HTML5PseudoClasses = {
'default': 4, 'indeterminate': 4, 'invalid': 4, 'valid': 4,
'optional': 4, 'required': 4, 'read-write': 4, 'read-only': 4
});
};

@@ -98,6 +98,6 @@ switch (match[1]) {

// compiler will add this to "source"
return global.Object({
return {
'source': source,
'status': status
});
};

@@ -104,0 +104,0 @@ };

@@ -8,5 +8,5 @@ /*

* Author: Diego Perini <diego.perini at gmail com>
* Version: 1.3.8
* Version: 1.3.9
* Created: 20070722
* Release: 20160613
* Release: 20161026
*

@@ -22,40 +22,17 @@ * License:

if (typeof module == 'object' && typeof exports == 'object') {
module.exports = function (browserGlobal) {
// passed global does not contain
// references to native objects
browserGlobal.console = console;
browserGlobal.parseInt = parseInt;
browserGlobal.Function = Function;
browserGlobal.Boolean = Boolean;
browserGlobal.Number = Number;
browserGlobal.RegExp = RegExp;
browserGlobal.String = String;
browserGlobal.Object = Object;
browserGlobal.Array = Array;
browserGlobal.Error = Error;
browserGlobal.Date = Date;
browserGlobal.Math = Math;
var exports = browserGlobal.Object();
factory(browserGlobal, exports);
return exports;
};
module.factory = factory;
module.exports = factory;
} else if (typeof define === 'function' && define["amd"]) {
define(factory);
} else {
factory(global,
(global.NW || (global.NW = global.Object())) &&
(global.NW.Dom || (global.NW.Dom = global.Object())));
global.NW.Dom.factory = factory;
global.NW || (global.NW = { });
global.NW.Dom = factory(global);
}
})(this, function(global, exports) {
})(this, function(global) {
var version = 'nwmatcher-1.3.8',
var version = 'nwmatcher-1.3.9',
Dom = exports,
doc = global.document,
root = doc.documentElement,
slice = global.Array.slice,
isSingleMatch,

@@ -76,82 +53,78 @@ isSingleSelect,

operators = '([~*^$|!]?={1})',
whitespace = '[\\x20\\t\\n\\r\\f]*',
combinators = '[\\x20]|[>+~](?=[^>+~])',
whitespace = '[\\x20\\t\\n\\r\\f]',
combinators = '\\x20|[>+~](?=[^>+~])',
pseudoparms = '(?:[-+]?\\d*n)?[-+]?\\d*',
skip_groups = '\\[.*\\]|\\(.*\\)|\\{.*\\}',
any_esc_chr = '\\\\.',
alphalodash = '[_a-zA-Z]',
non_asc_chr = '[^\\x00-\\x9f]',
escaped_chr = '\\\\[^\\n\\r\\f0-9a-fA-F]',
unicode_chr = '\\\\[0-9a-fA-F]{1,6}(?:\\r\\n|' + whitespace + ')?',
quotedvalue = '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"' + "|'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'",
skipgroup = '\\[.*\\]|\\(.*\\)|\\{.*\\}',
encoding = '(?:[-\\w]|[^\\x00-\\xa0]|\\\\.)',
identifier = '(?:-?[_a-zA-Z]{1}[-\\w]*|[^\\x00-\\xa0]+|\\\\.+)+',
reSplitGroup = /([^,\\()[\]]+|\[[^[\]]*\]|\[.*\]|\([^()]+\)|\(.*\)|\{[^{}]+\}|\{.*\}|\\.)+/g,
attrcheck = '(' + quotedvalue + '|' + identifier + ')',
attributes = whitespace + '(' + encoding + '*:?' + encoding + '+)' +
whitespace + '(?:' + operators + whitespace + attrcheck + ')?' + whitespace,
reTrimSpaces = RegExp('[\\n\\r\\f]|^' + whitespace + '+|' + whitespace + '+$', 'g'),
attrmatcher = attributes.replace(attrcheck, '([\\x22\\x27]*)((?:\\\\?.)*?)\\3'),
reEscapedChars = /\\([0-9a-fA-F]{1,6}[\x20\t\n\r\f]?|.)|([\x22\x27])/g,
pseudoclass = '((?:' +
pseudoparms + '|' + quotedvalue + '|' +
prefixes + '|' + encoding + '+|' +
'\\[' + attributes + '\\]|' +
'\\(.+\\)|' + whitespace + '|' +
',)+)',
standardValidator, extendedValidator, reValidator,
extensions = '.+',
attrcheck, attributes, attrmatcher, pseudoclass,
standardValidator =
'(?=[\\x20\\t\\n\\r\\f]*[^>+~(){}<>])' +
'(' +
'\\*' +
'|(?:' + prefixes + identifier + ')' +
'|' + combinators +
'|\\[' + attributes + '\\]' +
'|\\(' + pseudoclass + '\\)' +
'|\\{' + extensions + '\\}' +
'|(?:,|' + whitespace + ')' +
')+',
reOptimizeSelector, reSimpleNot, reSplitToken,
extendedValidator = standardValidator.replace(pseudoclass, '.*'),
Optimize, identifier, extensions = '.+',
reValidator = global.RegExp(standardValidator),
Patterns = {
children: RegExp('^' + whitespace + '*\\>' + whitespace + '*(.*)'),
adjacent: RegExp('^' + whitespace + '*\\+' + whitespace + '*(.*)'),
relative: RegExp('^' + whitespace + '*\\~' + whitespace + '*(.*)'),
ancestor: RegExp('^' + whitespace + '+(.*)'),
universal: RegExp('^\\*(.*)')
},
reTrimSpaces = global.RegExp('^' +
whitespace + '|' + whitespace + '$', 'g'),
Tokens = {
prefixes: prefixes,
identifier: identifier,
attributes: attributes
},
reSplitGroup = global.RegExp('(' +
'[^,\\\\()[\\]]+' +
'|\\[[^[\\]]*\\]|\\[.*\\]' +
'|\\([^()]+\\)|\\(.*\\)' +
'|\\{[^{}]+\\}|\\{.*\\}' +
'|\\\\.' +
')+', 'g'),
QUIRKS_MODE,
XML_DOCUMENT,
reSplitToken = global.RegExp('(' +
'\\[' + attributes + '\\]|' +
'\\(' + pseudoclass + '\\)|' +
'\\\\.|[^\\x20\\t\\n\\r\\f>+~])+', 'g'),
GEBTN = 'getElementsByTagName' in doc,
GEBCN = 'getElementsByClassName' in doc,
reWhiteSpace = /[\x20\t\n\r\f]+/g,
IE_LT_9 = typeof doc.addEventListener != 'function',
reOptimizeSelector = global.RegExp(identifier + '|^$'),
LINK_NODES = { a: 1, A: 1, area: 1, AREA: 1, link: 1, LINK: 1 },
ATTR_BOOLEAN = global.Object({
ATTR_BOOLEAN = {
checked: 1, disabled: 1, ismap: 1,
multiple: 1, readonly: 1, selected: 1
}),
},
ATTR_DEFAULT = global.Object({
ATTR_DEFAULT = {
value: 'defaultValue',
checked: 'defaultChecked',
selected: 'defaultSelected'
}),
},
ATTR_URIDATA = global.Object({
ATTR_URIDATA = {
action: 2, cite: 2, codebase: 2, data: 2, href: 2,
longdesc: 2, lowsrc: 2, src: 2, usemap: 2
}),
},
Selectors = global.Object(),
INSENSITIVE_MAP = {
'class': 0,
'href': 1, 'lang': 1, 'src': 1, 'style': 1, 'title': 1,
'type': 1, 'xmlns': 1, 'xml:lang': 1, 'xml:space': 1
},
Operators = global.Object({
Selectors = { },
Operators = {
'=': "n=='%m'",

@@ -163,67 +136,4 @@ '^=': "n.indexOf('%m')==0",

'$=': "n.substr(n.length-'%m'.length)=='%m'"
}),
},
Optimize = global.Object({
ID: global.RegExp('^\\*?#(' + encoding + '+)|' + skipgroup),
TAG: global.RegExp('^(' + encoding + '+)|' + skipgroup),
CLASS: global.RegExp('^\\*?\\.(' + encoding + '+$)|' + skipgroup)
}),
Patterns = global.Object({
universal: /^\*(.*)/,
id: global.RegExp('^#(' + encoding + '+)(.*)'),
tagName: global.RegExp('^(' + encoding + '+)(.*)'),
className: global.RegExp('^\\.(' + encoding + '+)(.*)'),
attribute: global.RegExp('^\\[' + attrmatcher + '\\](.*)'),
children: /^[\x20\t\n\r\f]*\>[\x20\t\n\r\f]*(.*)/,
adjacent: /^[\x20\t\n\r\f]*\+[\x20\t\n\r\f]*(.*)/,
relative: /^[\x20\t\n\r\f]*\~[\x20\t\n\r\f]*(.*)/,
ancestor: /^[\x20\t\n\r\f]+(.*)/
}),
QUIRKS_MODE,
XML_DOCUMENT,
GEBTN = 'getElementsByTagName' in doc,
GEBCN = 'getElementsByClassName' in doc,
IE_LT_9 = typeof doc.addEventListener != 'function',
INSENSITIVE_MAP = global.Object({
'class': 0,
'href': 1, 'lang': 1, 'src': 1, 'style': 1, 'title': 1,
'type': 1, 'xmlns': 1, 'xml:lang': 1, 'xml:space': 1
}),
TO_UPPER_CASE = IE_LT_9 ? '.toUpperCase()' : '',
ACCEPT_NODE = 'r[r.length]=c[k];if(f&&false===f(c[k]))break main;else continue main;',
REJECT_NODE = IE_LT_9 ? 'if(e.nodeName<"A")continue;' : '',
Config = global.Object({
CACHING: false,
SIMPLENOT: true,
UNIQUE_ID: true,
USE_HTML5: true,
VERBOSITY: true
}),
configure =
function(option) {
if (typeof option == 'string') { return Config[option] || Config; }
if (typeof option != 'object') { return false; }
for (var i in option) {
Config[i] = !!option[i];
if (i == 'SIMPLENOT') {
matchContexts = global.Object();
matchResolvers = global.Object();
selectContexts = global.Object();
selectResolvers = global.Object();
}
}
reValidator = global.RegExp(Config.SIMPLENOT ?
standardValidator : extendedValidator);
return true;
},
concatCall =

@@ -238,10 +148,2 @@ function(data, elements, callback) {

emit =
function(message) {
if (Config.VERBOSITY) { throw global.Error(message); }
if (global.console && global.console.log) {
global.console.log(message);
}
},
switchContext =

@@ -267,39 +169,54 @@ function(from, force) {

codePointToUTF16 =
function(codePoint) {
if (codePoint < 1 || codePoint > 0x10ffff ||
(codePoint > 0xd7ff && codePoint < 0xe000)) {
return '\\ufffd';
}
if (codePoint < 0x10000) {
var lowHex = '000' + codePoint.toString(16);
return '\\u' + lowHex.substr(lowHex.length - 4);
}
return '\\u' + (((codePoint - 0x10000) >> 0x0a) + 0xd800).toString(16) +
'\\u' + (((codePoint - 0x10000) % 0x400) + 0xdc00).toString(16);
},
stringFromCodePoint =
function(codePoint) {
if (codePoint < 1 || codePoint > 0x10ffff ||
(codePoint > 0xd7ff && codePoint < 0xe000)) {
return '\ufffd';
}
if (codePoint < 0x10000) {
return String.fromCharCode(codePoint);
}
return String.fromCodePoint ?
String.fromCodePoint(codePoint) :
String.fromCharCode(
((codePoint - 0x10000) >> 0x0a) + 0xd800,
((codePoint - 0x10000) % 0x400) + 0xdc00);
},
convertEscapes =
function(str) {
return str.replace(/\\([0-9a-fA-F]{1,6}\x20?|.)|([\x22\x27])/g, function(substring, p1, p2) {
var codePoint, highHex, highSurrogate, lowHex, lowSurrogate;
if (p2) {
return '\\' + p2;
}
if (/^[0-9a-fA-F]/.test(p1)) {
codePoint = parseInt(p1, 16);
if (codePoint < 0 || codePoint > 0x10ffff) {
return '\\ufffd';
return str.replace(reEscapedChars,
function(substring, p1, p2) {
return p2 ? '\\' + p2 :
/^[0-9a-fA-F]/.test(p1) ? codePointToUTF16(parseInt(p1, 16)) :
/^[\\\x22\x27]/.test(p1) ? substring :
p1;
}
);
},
if (codePoint <= 0xffff) {
lowHex = '000' + codePoint.toString(16);
return '\\u' + lowHex.substr(lowHex.length - 4);
unescapeIdentifier =
function(str) {
return str.replace(reEscapedChars,
function(substring, p1, p2) {
return p2 ? p2 :
/^[0-9a-fA-F]/.test(p1) ? stringFromCodePoint(parseInt(p1, 16)) :
/^[\\\x22\x27]/.test(p1) ? substring :
p1;
}
codePoint -= 0x10000;
highSurrogate = (codePoint >> 10) + 0xd800;
lowSurrogate = (codePoint % 0x400) + 0xdc00;
highHex = '000' + highSurrogate.toString(16);
lowHex = '000' + lowSurrogate.toString(16);
return '\\u' + highHex.substr(highHex.length - 4) +
'\\u' + lowHex.substr(lowHex.length - 4);
}
if (/^[\\\x22\x27]/.test(p1)) {
return substring;
}
return p1;
});
);
},

@@ -309,15 +226,14 @@

function(id, elements) {
var i = 0, element = null;
while ((element = elements[i])) {
var i = -1, element;
while ((element = elements[++i])) {
if (element.getAttribute('id') == id) {
break;
}
++i;
}
return element;
return element || null;
},
_byId = !('fileSize' in doc) ?
_byId = !IE_LT_9 ?
function(id, from) {
id = id.replace(/\\([^\\]{1})/g, '$1');
id = (/\\/).test(id) ? unescapeIdentifier(id) : id;
return from.getElementById && from.getElementById(id) ||

@@ -328,3 +244,3 @@ byIdRaw(id, from.getElementsByTagName('*'));

var element = null;
id = id.replace(/\\([^\\]{1})/g, '$1');
id = (/\\/).test(id) ? unescapeIdentifier(id) : id;
if (XML_DOCUMENT || from.nodeType != 9) {

@@ -349,3 +265,3 @@ return byIdRaw(id, from.getElementsByTagName('*'));

function(tag, from) {
var any = tag == '*', element = from, elements = global.Array(), next = element.firstChild;
var any = tag == '*', element = from, elements = [ ], next = element.firstChild;
any || (tag = tag.toUpperCase());

@@ -364,4 +280,7 @@ while ((element = next)) {

getAttribute =
getAttribute = !IE_LT_9 ?
function(node, attribute) {
return node.getAttribute(attribute);
} :
function(node, attribute) {
attribute = attribute.toLowerCase();

@@ -379,5 +298,5 @@ if (typeof node[attribute] == 'object') {

hasAttribute = root.hasAttribute ?
hasAttribute = !IE_LT_9 && root.hasAttribute ?
function(node, attribute) {
return node.hasAttribute(attribute);
return node.hasAttribute(attribute);
} :

@@ -390,2 +309,123 @@ function(node, attribute) {

configure =
function(option) {
if (typeof option == 'string') { return !!Config[option]; }
if (typeof option != 'object') { return Config; }
for (var i in option) {
Config[i] = !!option[i];
if (i == 'SIMPLENOT') {
matchContexts = { };
matchResolvers = { };
selectContexts = { };
selectResolvers = { };
}
}
setIdentifierSyntax();
reValidator = RegExp(Config.SIMPLENOT ?
standardValidator : extendedValidator);
return true;
},
emit =
function(message) {
if (Config.VERBOSITY) { throw Error(message); }
if (console && console.log) {
console.log(message);
}
},
Config = {
CACHING: false,
ESCAPECHR: true,
NON_ASCII: true,
SELECTOR3: true,
UNICODE16: true,
SHORTCUTS: false,
SIMPLENOT: true,
UNIQUE_ID: true,
USE_HTML5: true,
VERBOSITY: true
},
initialize =
function(doc) {
setIdentifierSyntax();
switchContext(doc, true);
},
setIdentifierSyntax =
function() {
var syntax = '', start = Config['SELECTOR3'] ? '-{2}|' : '';
Config['NON_ASCII'] && (syntax += '|' + non_asc_chr);
Config['UNICODE16'] && (syntax += '|' + unicode_chr);
Config['ESCAPECHR'] && (syntax += '|' + escaped_chr);
syntax += (Config['UNICODE16'] || Config['ESCAPECHR']) ? '' : '|' + any_esc_chr;
identifier = '-?(?:' + start + alphalodash + syntax + ')(?:-|[0-9]|' + alphalodash + syntax + ')*';
attrcheck = '(' + quotedvalue + '|' + identifier + ')';
attributes = whitespace + '*(' + identifier + ':?' + identifier + ')' +
whitespace + '*(?:' + operators + whitespace + '*' + attrcheck + ')?' + whitespace + '*';
attrmatcher = attributes.replace(attrcheck, '([\\x22\\x27]*)((?:\\\\?.)*?)\\3');
pseudoclass = '((?:' +
pseudoparms + '|' + quotedvalue + '|' +
prefixes + identifier + '|' +
'\\[' + attributes + '\\]|' +
'\\(.+\\)|' + whitespace + '*|' +
',)+)';
standardValidator =
'(?=[\\x20\\t\\n\\r\\f]*[^>+~(){}<>])' +
'(' +
'\\*' +
'|(?:' + prefixes + identifier + ')' +
'|' + combinators +
'|\\[' + attributes + '\\]' +
'|\\(' + pseudoclass + '\\)' +
'|\\{' + extensions + '\\}' +
'|(?:,|' + whitespace + '*)' +
')+';
reSimpleNot = RegExp('^(' +
'(?!:not)' +
'(' + prefixes + identifier +
'|\\([^()]*\\))+' +
'|\\[' + attributes + '\\]' +
')$');
reSplitToken = RegExp('(' +
prefixes + identifier + '|' +
'\\[' + attributes + '\\]|' +
'\\(' + pseudoclass + '\\)|' +
'\\\\.|[^\\x20\\t\\n\\r\\f>+~])+', 'g');
reOptimizeSelector = RegExp(identifier + '|^$');
Optimize = {
ID: RegExp('^\\*?#(' + identifier + ')|' + skip_groups),
TAG: RegExp('^(' + identifier + ')|' + skip_groups),
CLASS: RegExp('^\\.(' + identifier + '$)|' + skip_groups)
};
Patterns.id = RegExp('^#(' + identifier + ')(.*)');
Patterns.tagName = RegExp('^(' + identifier + ')(.*)');
Patterns.className = RegExp('^\\.(' + identifier + ')(.*)');
Patterns.attribute = RegExp('^\\[' + attrmatcher + '\\](.*)');
Tokens.identifier = identifier;
Tokens.attributes = attributes;
extendedValidator = standardValidator.replace(pseudoclass, '.*');
reValidator = RegExp(standardValidator);
},
ACCEPT_NODE = 'r[r.length]=c[k];if(f&&false===f(c[k]))break main;else continue main;',
REJECT_NODE = IE_LT_9 ? 'if(e.nodeName<"A")continue;' : '',
TO_UPPER_CASE = IE_LT_9 ? '.toUpperCase()' : '',
compile =

@@ -401,3 +441,3 @@ function(selector, source, mode) {

} else {
var i = -1, seen = global.Object(), token;
var i = -1, seen = { }, token;
while ((token = parts[++i])) {

@@ -411,8 +451,9 @@ token = token.replace(reTrimSpaces, '');

if (mode)
return global.Function('c,s,r,d,h,g,f,v',
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;');
else
return global.Function('e,s,r,d,h,g,f,v',
} else {
return Function('e,s,r,d,h,g,f,v',
'var N,n,x=0,k=e;' + source + 'return false;');
}
},

@@ -429,3 +470,3 @@

var k = 0, expr, match, name, result, status, test, type;
var k = 0, expr, match, result, status, test, type;

@@ -441,2 +482,3 @@ while (selector) {

else if ((match = selector.match(Patterns.id))) {
match[1] = (/\\/).test(match[1]) ? convertEscapes(match[1]) : match[1];
source = 'if(' + (XML_DOCUMENT ?

@@ -457,7 +499,8 @@ 's.getAttribute(e,"id")' :

else if ((match = selector.match(Patterns.className))) {
match[1] = (/\\/).test(match[1]) ? convertEscapes(match[1]) : match[1];
match[1] = QUIRKS_MODE ? match[1].toLowerCase() : match[1];
source = 'if((n=' + (XML_DOCUMENT ?
'e.getAttribute("class")' : 'e.className') +
')&&n.length&&(" "+' + (QUIRKS_MODE ? 'n.toLowerCase()' : 'n') +
'.replace(' + reWhiteSpace + '," ")+" ").indexOf(" ' +
(QUIRKS_MODE ? match[1].toLowerCase() : match[1]) + ' ")>-1' +
'.replace(/' + whitespace + '+/g," ")+" ").indexOf(" ' + match[1] + ' ")>-1' +
'){' + source + '}';

@@ -473,3 +516,3 @@ }

if (match[2] && match[4] && (test = Operators[match[2]])) {
match[4] = convertEscapes(match[4]);
match[4] = (/\\/).test(match[4]) ? convertEscapes(match[4]) : match[4];
INSENSITIVE_MAP['class'] = QUIRKS_MODE ? 1 : 0;

@@ -558,3 +601,5 @@ type = INSENSITIVE_MAP[match[1].toLowerCase()];

selector = selector.replace(reTrimSpaces, '');
selector = selector.
replace(reTrimSpaces, '').
replace(/\x00|\\$/g, '\ufffd');

@@ -608,3 +653,5 @@ Config.SHORTCUTS && (selector = Dom.shortcuts(selector, element, from));

selector = selector.replace(reTrimSpaces, '');
selector = selector.
replace(reTrimSpaces, '').
replace(/\x00|\\$/g, '\ufffd');

@@ -642,4 +689,4 @@ Config.SHORTCUTS && (selector = Dom.shortcuts(selector, from));

callback && callback(element);
elements = global.Array(element);
} else elements = global.Array();
elements = [element];
} else elements = [ ];
}

@@ -652,3 +699,3 @@ }

callback && callback(element);
elements = global.Array(element);
elements = [element];
} else if (/[>+~]/.test(selector)) {

@@ -659,3 +706,3 @@ from = element.parentNode;

}
} else elements = global.Array();
} else elements = [ ];
}

@@ -669,3 +716,3 @@

if (!XML_DOCUMENT && GEBTN && (parts = lastSlice.match(Optimize.TAG)) && (token = parts[1])) {
if ((elements = from.getElementsByTagName(token)).length === 0) return [ ];
if ((elements = from.getElementsByTagName(token)).length === 0) { return [ ]; }
selector = selector.slice(0, lastPosition) + selector.slice(lastPosition).replace(token, '*');

@@ -675,3 +722,3 @@ }

else if (!XML_DOCUMENT && GEBCN && (parts = lastSlice.match(Optimize.CLASS)) && (token = parts[1])) {
if ((elements = from.getElementsByClassName(token.replace(/\\([^\\]{1})/g, '$1'))).length === 0) return [ ];
if ((elements = from.getElementsByClassName(unescapeIdentifier(token))).length === 0) { return [ ]; }
selector = selector.slice(0, lastPosition) + selector.slice(lastPosition).replace('.' + token,

@@ -685,4 +732,3 @@ reOptimizeSelector.test(selector.charAt(selector.indexOf(token) - 1)) ? '' : '*');

if (IE_LT_9) {
elements = /^(?:applet|object)$/i.test(from.nodeName) ?
from.childNodes : from.all;
elements = /^(?:applet|object)$/i.test(from.nodeName) ? from.children : byTagRaw('*', from);
} else {

@@ -707,9 +753,9 @@ elements = from.getElementsByTagName('*');

matchContexts = global.Object(),
matchResolvers = global.Object(),
matchContexts = { },
matchResolvers = { },
selectContexts = global.Object(),
selectResolvers = global.Object(),
selectContexts = { },
selectResolvers = { },
Snapshot = global.Object({
Snapshot = {
byId: _byId,

@@ -720,56 +766,48 @@ match: match,

hasAttribute: hasAttribute
});
},
Tokens = global.Object({
prefixes: prefixes,
encoding: encoding,
operators: operators,
whitespace: whitespace,
identifier: identifier,
attributes: attributes,
combinators: combinators,
pseudoclass: pseudoclass,
pseudoparms: pseudoparms,
quotedvalue: quotedvalue
});
Dom = {
Dom.ACCEPT_NODE = ACCEPT_NODE;
ACCEPT_NODE: ACCEPT_NODE,
Dom.byId = byId;
Dom.match = match;
Dom.first = first;
Dom.select = select;
Dom.compile = compile;
Dom.configure = configure;
byId: byId,
match: match,
first: first,
select: select,
compile: compile,
configure: configure,
Dom.setCache = FN;
Dom.shortcuts = FN;
Dom.loadResults = FN;
Dom.saveResults = FN;
setCache: FN,
shortcuts: FN,
loadResults: FN,
saveResults: FN,
Dom.emit = emit;
Dom.Config = Config;
Dom.Snapshot = Snapshot;
emit: emit,
Config: Config,
Snapshot: Snapshot,
Dom.Operators = Operators;
Dom.Selectors = Selectors;
Operators: Operators,
Selectors: Selectors,
Dom.Tokens = Tokens;
Dom.Version = version;
Tokens: Tokens,
Version: version,
Dom.registerOperator =
function(symbol, resolver) {
Operators[symbol] || (Operators[symbol] = resolver);
};
registerOperator:
function(symbol, resolver) {
Operators[symbol] || (Operators[symbol] = resolver);
},
Dom.registerSelector =
function(name, rexp, func) {
Selectors[name] || (Selectors[name] = global.Object({
Expression: rexp,
Callback: func
}));
};
registerSelector:
function(name, rexp, func) {
Selectors[name] || (Selectors[name] = {
Expression: rexp,
Callback: func
});
}
switchContext(doc, true);
};
initialize(doc);
return Dom;
});

@@ -8,5 +8,5 @@ /*

* Author: Diego Perini <diego.perini at gmail com>
* Version: 1.3.8
* Version: 1.3.9
* Created: 20070722
* Release: 20160613
* Release: 20161026
*

@@ -22,35 +22,14 @@ * License:

if (typeof module == 'object' && typeof exports == 'object') {
module.exports = function (browserGlobal) {
// passed global does not contain
// references to native objects
browserGlobal.console = console;
browserGlobal.parseInt = parseInt;
browserGlobal.Function = Function;
browserGlobal.Boolean = Boolean;
browserGlobal.Number = Number;
browserGlobal.RegExp = RegExp;
browserGlobal.String = String;
browserGlobal.Object = Object;
browserGlobal.Array = Array;
browserGlobal.Error = Error;
browserGlobal.Date = Date;
browserGlobal.Math = Math;
var exports = browserGlobal.Object();
factory(browserGlobal, exports);
return exports;
};
module.factory = factory;
module.exports = factory;
} else if (typeof define === 'function' && define["amd"]) {
define(factory);
} else {
factory(global,
(global.NW || (global.NW = global.Object())) &&
(global.NW.Dom || (global.NW.Dom = global.Object())));
global.NW.Dom.factory = factory;
global.NW || (global.NW = { });
global.NW.Dom = factory(global);
}
})(this, function(global, exports) {
})(this, function(global) {
var version = 'nwmatcher-1.3.8',
var version = 'nwmatcher-1.3.9',
Dom = exports,
doc = global.document,

@@ -72,61 +51,47 @@ root = doc.documentElement,

prefixes = '[#.:]?',
operators = '([~*^$|!]?={1})',
combinators = '[\\s]|[>+~](?=[^>+~])',
whitespace = '[\\x20\\t\\n\\r\\f]',
combinators = '\\x20|[>+~](?=[^>+~])',
pseudoparms = '(?:[-+]?\\d*n)?[-+]?\\d*',
skip_groups = '\\[.*\\]|\\(.*\\)|\\{.*\\}',
any_esc_chr = '\\\\.',
alphalodash = '[_a-zA-Z]',
non_asc_chr = '[^\\x00-\\x9f]',
escaped_chr = '\\\\[^\\n\\r\\f0-9a-fA-F]',
unicode_chr = '\\\\[0-9a-fA-F]{1,6}(?:\\r\\n|' + whitespace + ')?',
quotedvalue = '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"' + "|'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'",
skipgroup = '\\[.*\\]|\\(.*\\)|\\{.*\\}',
encoding = '(?:[-\\w]|[^\\x00-\\xa0]|\\\\.)',
identifier = '(?:-?[_a-zA-Z]{1}[-\\w]*|[^\\x00-\\xa0]+|\\\\.+)+',
reSplitGroup = /([^,\\()[\]]+|\[[^[\]]*\]|\[.*\]|\([^()]+\)|\(.*\)|\{[^{}]+\}|\{.*\}|\\.)+/g,
attrcheck = '(' + quotedvalue + '|' + identifier + ')',
attributes = '\\s*(' + encoding + '*:?' + encoding + '+)\\s*(?:' + operators + '\\s*' + attrcheck + ')?\\s*',
reTrimSpaces = RegExp('[\\n\\r\\f]|^' + whitespace + '+|' + whitespace + '+$', 'g'),
attrmatcher = attributes.replace(attrcheck, '([\\x22\\x27]*)((?:\\\\?.)*?)\\3'),
reEscapedChars = /\\([0-9a-fA-F]{1,6}[\x20\t\n\r\f]?|.)|([\x22\x27])/g,
pseudoclass = '((?:' +
pseudoparms + '|' + quotedvalue + '|' +
'[#.:]?|' + encoding + '+|' +
'\\[' + attributes + '\\]|' +
'\\(.+\\)|\\s*|' +
',)+)',
standardValidator, extendedValidator, reValidator,
extensions = '.+',
attrcheck, attributes, attrmatcher, pseudoclass,
standardValidator =
'(?=\\s*[^>+~(){}<>])' +
'(' +
'\\*' +
'|(?:[#.:]?' + identifier + ')' +
'|' + combinators +
'|\\[' + attributes + '\\]' +
'|\\(' + pseudoclass + '\\)' +
'|\\{' + extensions + '\\}' +
'|(?:,|\\s*)' +
')+',
reOptimizeSelector, reSimpleNot, reSplitToken,
extendedValidator = standardValidator.replace(pseudoclass, '.*'),
Optimize, identifier, extensions = '.+',
reValidator = global.RegExp(standardValidator),
Patterns = {
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,
children: RegExp('^' + whitespace + '*\\>' + whitespace + '*(.*)'),
adjacent: RegExp('^' + whitespace + '*\\+' + whitespace + '*(.*)'),
relative: RegExp('^' + whitespace + '*\\~' + whitespace + '*(.*)'),
ancestor: RegExp('^' + whitespace + '+(.*)'),
universal: RegExp('^\\*(.*)')
},
reTrimSpaces = /^\s*|\s*$/g,
Tokens = {
prefixes: prefixes,
identifier: identifier,
attributes: attributes
},
reSimpleNot = global.RegExp('^(' +
'(?!:not)' +
'([#.:]?' +
'|' + identifier +
'|\\([^()]*\\))+' +
'|\\[' + attributes + '\\]' +
')$'),
reSplitGroup = /([^,\\()[\]]+|\[[^[\]]*\]|\[.*\]|\([^()]+\)|\(.*\)|\{[^{}]+\}|\{.*\}|\\.)+/g,
reSplitToken = global.RegExp('(' +
'\\[' + attributes + '\\]|' +
'\\(' + pseudoclass + '\\)|' +
'\\\\.|[^\\s>+~])+', 'g'),
reOptimizeSelector = global.RegExp(identifier + '|^$'),
QUIRKS_MODE,

@@ -138,24 +103,31 @@ XML_DOCUMENT,

LINK_NODES = global.Object({ a: 1, A: 1, area: 1, AREA: 1, link: 1, LINK: 1 }),
IE_LT_9 = typeof doc.addEventListener != 'function',
ATTR_BOOLEAN = global.Object({
LINK_NODES = { a: 1, A: 1, area: 1, AREA: 1, link: 1, LINK: 1 },
ATTR_BOOLEAN = {
checked: 1, disabled: 1, ismap: 1,
multiple: 1, readonly: 1, selected: 1
}),
},
ATTR_DEFAULT = global.Object({
ATTR_DEFAULT = {
value: 'defaultValue',
checked: 'defaultChecked',
selected: 'defaultSelected'
}),
},
ATTR_URIDATA = global.Object({
ATTR_URIDATA = {
action: 2, cite: 2, codebase: 2, data: 2, href: 2,
longdesc: 2, lowsrc: 2, src: 2, usemap: 2
}),
},
Selectors = global.Object({
}),
INSENSITIVE_MAP = {
'class': 0,
'href': 1, 'lang': 1, 'src': 1, 'style': 1, 'title': 1,
'type': 1, 'xmlns': 1, 'xml:lang': 1, 'xml:space': 1
},
Operators = global.Object({
Selectors = { },
Operators = {
'=': "n=='%m'",

@@ -167,24 +139,4 @@ '^=': "n.indexOf('%m')==0",

'$=': "n.substr(n.length-'%m'.length)=='%m'"
}),
},
Optimize = global.Object({
ID: global.RegExp('^\\*?#(' + encoding + '+)|' + skipgroup),
TAG: global.RegExp('^(' + encoding + '+)|' + skipgroup),
CLASS: global.RegExp('^\\*?\\.(' + encoding + '+$)|' + skipgroup)
}),
Patterns = global.Object({
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,
attribute: global.RegExp('^\\[' + attrmatcher + '\\](.*)'),
children: /^\s*\>\s*(.*)/,
adjacent: /^\s*\+\s*(.*)/,
relative: /^\s*\~\s*(.*)/,
ancestor: /^\s+(.*)/,
universal: /^\*(.*)/,
id: global.RegExp('^#(' + encoding + '+)(.*)'),
tagName: global.RegExp('^(' + encoding + '+)(.*)'),
className: global.RegExp('^\\.(' + encoding + '+)(.*)')
}),
concatCall =

@@ -219,39 +171,54 @@ function(data, elements, callback) {

codePointToUTF16 =
function(codePoint) {
if (codePoint < 1 || codePoint > 0x10ffff ||
(codePoint > 0xd7ff && codePoint < 0xe000)) {
return '\\ufffd';
}
if (codePoint < 0x10000) {
var lowHex = '000' + codePoint.toString(16);
return '\\u' + lowHex.substr(lowHex.length - 4);
}
return '\\u' + (((codePoint - 0x10000) >> 0x0a) + 0xd800).toString(16) +
'\\u' + (((codePoint - 0x10000) % 0x400) + 0xdc00).toString(16);
},
stringFromCodePoint =
function(codePoint) {
if (codePoint < 1 || codePoint > 0x10ffff ||
(codePoint > 0xd7ff && codePoint < 0xe000)) {
return '\ufffd';
}
if (codePoint < 0x10000) {
return String.fromCharCode(codePoint);
}
return String.fromCodePoint ?
String.fromCodePoint(codePoint) :
String.fromCharCode(
((codePoint - 0x10000) >> 0x0a) + 0xd800,
((codePoint - 0x10000) % 0x400) + 0xdc00);
},
convertEscapes =
function(str) {
return str.replace(/\\([0-9a-fA-F]{1,6}\x20?|.)|([\x22\x27])/g, function(substring, p1, p2) {
var codePoint, highHex, highSurrogate, lowHex, lowSurrogate;
if (p2) {
return '\\' + p2;
}
if (/^[0-9a-fA-F]/.test(p1)) {
codePoint = parseInt(p1, 16);
if (codePoint < 0 || codePoint > 0x10ffff) {
return '\\ufffd';
return str.replace(reEscapedChars,
function(substring, p1, p2) {
return p2 ? '\\' + p2 :
/^[0-9a-fA-F]/.test(p1) ? codePointToUTF16(parseInt(p1, 16)) :
/^[\\\x22\x27]/.test(p1) ? substring :
p1;
}
);
},
if (codePoint <= 0xffff) {
lowHex = '000' + codePoint.toString(16);
return '\\u' + lowHex.substr(lowHex.length - 4);
unescapeIdentifier =
function(str) {
return str.replace(reEscapedChars,
function(substring, p1, p2) {
return p2 ? p2 :
/^[0-9a-fA-F]/.test(p1) ? stringFromCodePoint(parseInt(p1, 16)) :
/^[\\\x22\x27]/.test(p1) ? substring :
p1;
}
codePoint -= 0x10000;
highSurrogate = (codePoint >> 10) + 0xd800;
lowSurrogate = (codePoint % 0x400) + 0xdc00;
highHex = '000' + highSurrogate.toString(16);
lowHex = '000' + lowSurrogate.toString(16);
return '\\u' + highHex.substr(highHex.length - 4) +
'\\u' + lowHex.substr(lowHex.length - 4);
}
if (/^[\\\x22\x27]/.test(p1)) {
return substring;
}
return p1;
});
);
},

@@ -261,3 +228,3 @@

function(id, elements) {
var i = -1, element = null;
var i = -1, element;
while ((element = elements[++i])) {

@@ -268,8 +235,8 @@ if (element.getAttribute('id') == id) {

}
return element;
return element || null;
},
_byId = !('fileSize' in doc) ?
_byId = !IE_LT_9 ?
function(id, from) {
id = id.replace(/\\([^\\]{1})/g, '$1');
id = (/\\/).test(id) ? unescapeIdentifier(id) : id;
return from.getElementById && from.getElementById(id) ||

@@ -280,3 +247,3 @@ byIdRaw(id, from.getElementsByTagName('*'));

var element = null;
id = id.replace(/\\([^\\]{1})/g, '$1');
id = (/\\/).test(id) ? unescapeIdentifier(id) : id;
if (XML_DOCUMENT || from.nodeType != 9) {

@@ -301,3 +268,3 @@ return byIdRaw(id, from.getElementsByTagName('*'));

function(tag, from) {
var any = tag == '*', element = from, elements = global.Array(), next = element.firstChild;
var any = tag == '*', element = from, elements = [ ], next = element.firstChild;
any || (tag = tag.toUpperCase());

@@ -321,6 +288,6 @@ while ((element = next)) {

function(container, element) {
return element.nodeType == 1 && container.contains(element);
return container !== element && container.contains(element);
} :
function(container, element) {
while ((element = element.parentNode) && element.nodeType == 1) {
while ((element = element.parentNode)) {
if (element === container) return true;

@@ -331,4 +298,7 @@ }

getAttribute =
getAttribute = !IE_LT_9 ?
function(node, attribute) {
return node.getAttribute(attribute);
} :
function(node, attribute) {
attribute = attribute.toLowerCase();

@@ -346,3 +316,3 @@ if (typeof node[attribute] == 'object') {

hasAttribute = root.hasAttribute ?
hasAttribute = !IE_LT_9 && root.hasAttribute ?
function(node, attribute) {

@@ -357,7 +327,2 @@ return node.hasAttribute(attribute);

isLink =
function(element) {
return element.getAttribute('href') && LINK_NODES[element.nodeName];
},
isEmpty =

@@ -373,2 +338,7 @@ function(node) {

isLink =
function(element) {
return hasAttribute(element, 'href') && LINK_NODES[element.nodeName];
},
nthElement =

@@ -394,14 +364,15 @@ function(element, last) {

function(option) {
if (typeof option == 'string') { return Config[option] || Config; }
if (typeof option != 'object') { return false; }
if (typeof option == 'string') { return !!Config[option]; }
if (typeof option != 'object') { return Config; }
for (var i in option) {
Config[i] = !!option[i];
if (i == 'SIMPLENOT') {
matchContexts = global.Object();
matchResolvers = global.Object();
selectContexts = global.Object();
selectResolvers = global.Object();
matchContexts = { };
matchResolvers = { };
selectContexts = { };
selectResolvers = { };
}
}
reValidator = global.RegExp(Config.SIMPLENOT ?
setIdentifierSyntax();
reValidator = RegExp(Config.SIMPLENOT ?
standardValidator : extendedValidator);

@@ -413,10 +384,15 @@ return true;

function(message) {
if (Config.VERBOSITY) { throw global.Error(message); }
if (global.console && global.console.log) {
global.console.log(message);
if (Config.VERBOSITY) { throw Error(message); }
if (console && console.log) {
console.log(message);
}
},
Config = global.Object({
Config = {
CACHING: false,
ESCAPECHR: true,
NON_ASCII: true,
SELECTOR3: true,
UNICODE16: true,
SHORTCUTS: false,
SIMPLENOT: true,

@@ -426,16 +402,84 @@ UNIQUE_ID: true,

VERBOSITY: true
}),
},
IE_LT_9 = typeof doc.addEventListener != 'function',
initialize =
function(doc) {
setIdentifierSyntax();
switchContext(doc, true);
},
INSENSITIVE_MAP = global.Object({
'class': 0,
'href': 1, 'lang': 1, 'src': 1, 'style': 1, 'title': 1,
'type': 1, 'xmlns': 1, 'xml:lang': 1, 'xml:space': 1
}),
setIdentifierSyntax =
function() {
TO_UPPER_CASE = IE_LT_9 ? '.toUpperCase()' : '',
var syntax = '', start = Config['SELECTOR3'] ? '-{2}|' : '';
Config['NON_ASCII'] && (syntax += '|' + non_asc_chr);
Config['UNICODE16'] && (syntax += '|' + unicode_chr);
Config['ESCAPECHR'] && (syntax += '|' + escaped_chr);
syntax += (Config['UNICODE16'] || Config['ESCAPECHR']) ? '' : '|' + any_esc_chr;
identifier = '-?(?:' + start + alphalodash + syntax + ')(?:-|[0-9]|' + alphalodash + syntax + ')*';
attrcheck = '(' + quotedvalue + '|' + identifier + ')';
attributes = whitespace + '*(' + identifier + ':?' + identifier + ')' +
whitespace + '*(?:' + operators + whitespace + '*' + attrcheck + ')?' + whitespace + '*';
attrmatcher = attributes.replace(attrcheck, '([\\x22\\x27]*)((?:\\\\?.)*?)\\3');
pseudoclass = '((?:' +
pseudoparms + '|' + quotedvalue + '|' +
prefixes + identifier + '|' +
'\\[' + attributes + '\\]|' +
'\\(.+\\)|' + whitespace + '*|' +
',)+)';
standardValidator =
'(?=[\\x20\\t\\n\\r\\f]*[^>+~(){}<>])' +
'(' +
'\\*' +
'|(?:' + prefixes + identifier + ')' +
'|' + combinators +
'|\\[' + attributes + '\\]' +
'|\\(' + pseudoclass + '\\)' +
'|\\{' + extensions + '\\}' +
'|(?:,|' + whitespace + '*)' +
')+';
reSimpleNot = RegExp('^(' +
'(?!:not)' +
'(' + prefixes + identifier +
'|\\([^()]*\\))+' +
'|\\[' + attributes + '\\]' +
')$');
reSplitToken = RegExp('(' +
prefixes + identifier + '|' +
'\\[' + attributes + '\\]|' +
'\\(' + pseudoclass + '\\)|' +
'\\\\.|[^\\x20\\t\\n\\r\\f>+~])+', 'g');
reOptimizeSelector = RegExp(identifier + '|^$');
Optimize = {
ID: RegExp('^\\*?#(' + identifier + ')|' + skip_groups),
TAG: RegExp('^(' + identifier + ')|' + skip_groups),
CLASS: RegExp('^\\.(' + identifier + '$)|' + skip_groups)
};
Patterns.id = RegExp('^#(' + identifier + ')(.*)');
Patterns.tagName = RegExp('^(' + identifier + ')(.*)');
Patterns.className = RegExp('^\\.(' + identifier + ')(.*)');
Patterns.attribute = RegExp('^\\[' + attrmatcher + '\\](.*)');
Tokens.identifier = identifier;
Tokens.attributes = attributes;
extendedValidator = standardValidator.replace(pseudoclass, '.*');
reValidator = RegExp(standardValidator);
},
ACCEPT_NODE = 'r[r.length]=c[k];if(f&&false===f(c[k]))break main;else continue main;',
REJECT_NODE = IE_LT_9 ? 'if(e.nodeName<"A")continue;' : '',
TO_UPPER_CASE = IE_LT_9 ? '.toUpperCase()' : '',

@@ -452,3 +496,3 @@ compile =

} else {
var i = -1, seen = global.Object(), token;
var i = -1, seen = { }, token;
while ((token = parts[++i])) {

@@ -463,6 +507,6 @@ token = token.replace(reTrimSpaces, '');

if (mode) {
return global.Function('c,s,r,d,h,g,f,v',
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;');
} else {
return global.Function('e,s,r,d,h,g,f,v',
return Function('e,s,r,d,h,g,f,v',
'var N,n,x=0,k=e;' + source + 'return false;');

@@ -481,3 +525,3 @@ }

var a, b, n, k = 0, expr, match, name, result, status, test, type;
var a, b, n, k = 0, expr, match, result, status, test, type;

@@ -493,2 +537,3 @@ while (selector) {

else if ((match = selector.match(Patterns.id))) {
match[1] = (/\\/).test(match[1]) ? convertEscapes(match[1]) : match[1];
source = 'if(' + (XML_DOCUMENT ?

@@ -509,7 +554,8 @@ 's.getAttribute(e,"id")' :

else if ((match = selector.match(Patterns.className))) {
match[1] = (/\\/).test(match[1]) ? convertEscapes(match[1]) : match[1];
match[1] = QUIRKS_MODE ? match[1].toLowerCase() : match[1];
source = 'if((n=' + (XML_DOCUMENT ?
'e.getAttribute("class")' : 'e.className') +
')&&n.length&&(" "+' + (QUIRKS_MODE ? 'n.toLowerCase()' : 'n') +
'.replace(/\\s+/g," ")+" ").indexOf(" ' +
(QUIRKS_MODE ? match[1].toLowerCase() : match[1]) + ' ")>-1' +
'.replace(/' + whitespace + '+/g," ")+" ").indexOf(" ' + match[1] + ' ")>-1' +
'){' + source + '}';

@@ -525,3 +571,3 @@ }

if (match[2] && match[4] && (test = Operators[match[2]])) {
match[4] = convertEscapes(match[4]);
match[4] = (/\\/).test(match[4]) ? convertEscapes(match[4]) : match[4];
INSENSITIVE_MAP['class'] = QUIRKS_MODE ? 1 : 0;

@@ -583,4 +629,4 @@ type = INSENSITIVE_MAP[match[1].toLowerCase()];

} else {
b = ((n = match[2].match(/(-?\d+)$/)) ? global.parseInt(n[1], 10) : 0);
a = ((n = match[2].match(/(-?\d*)n/i)) ? global.parseInt(n[1], 10) : 0);
b = ((n = match[2].match(/(-?\d+)$/)) ? parseInt(n[1], 10) : 0);
a = ((n = match[2].match(/(-?\d*)n/i)) ? parseInt(n[1], 10) : 0);
if (n && n[1] == '-') a = -1;

@@ -731,3 +777,5 @@ }

selector = selector.replace(reTrimSpaces, '');
selector = selector.
replace(reTrimSpaces, '').
replace(/\x00|\\$/g, '\ufffd');

@@ -781,3 +829,5 @@ Config.SHORTCUTS && (selector = Dom.shortcuts(selector, element, from));

selector = selector.replace(reTrimSpaces, '');
selector = selector.
replace(reTrimSpaces, '').
replace(/\x00|\\$/g, '\ufffd');

@@ -815,4 +865,4 @@ Config.SHORTCUTS && (selector = Dom.shortcuts(selector, from));

callback && callback(element);
elements = global.Array(element);
} else elements = global.Array();
elements = [element];
} else elements = [ ];
}

@@ -825,3 +875,3 @@ }

callback && callback(element);
elements = global.Array(element);
elements = [element];
} else if (/[>+~]/.test(selector)) {

@@ -832,3 +882,3 @@ from = element.parentNode;

}
} else elements = global.Array();
} else elements = [ ];
}

@@ -847,3 +897,3 @@

else if (!XML_DOCUMENT && GEBCN && (parts = lastSlice.match(Optimize.CLASS)) && (token = parts[1])) {
if ((elements = from.getElementsByClassName(token.replace(/\\([^\\]{1})/g, '$1'))).length === 0) { return [ ]; }
if ((elements = from.getElementsByClassName(unescapeIdentifier(token))).length === 0) { return [ ]; }
selector = selector.slice(0, lastPosition) + selector.slice(lastPosition).replace('.' + token,

@@ -857,3 +907,3 @@ reOptimizeSelector.test(selector.charAt(selector.indexOf(token) - 1)) ? '' : '*');

if (IE_LT_9) {
elements = /^(?:applet|object)$/i.test(from.nodeName) ? from.childNodes : from.all;
elements = /^(?:applet|object)$/i.test(from.nodeName) ? from.children : byTagRaw('*', from);
} else {

@@ -878,9 +928,9 @@ elements = from.getElementsByTagName('*');

matchContexts = global.Object(),
matchResolvers = global.Object(),
matchContexts = { },
matchResolvers = { },
selectContexts = global.Object(),
selectResolvers = global.Object(),
selectContexts = { },
selectResolvers = { },
Snapshot = global.Object({
Snapshot = {
byId: _byId,

@@ -896,45 +946,51 @@ match: match,

hasAttribute: hasAttribute
});
},
Dom.ACCEPT_NODE = ACCEPT_NODE;
Dom = {
Dom.byId = byId;
Dom.match = match;
Dom.first = first;
Dom.select = select;
Dom.compile = compile;
Dom.contains = contains;
Dom.configure = configure;
Dom.getAttribute = getAttribute;
Dom.hasAttribute = hasAttribute;
ACCEPT_NODE: ACCEPT_NODE,
Dom.setCache = FN;
Dom.shortcuts = FN;
Dom.loadResults = FN;
Dom.saveResults = FN;
byId: byId,
match: match,
first: first,
select: select,
compile: compile,
contains: contains,
configure: configure,
getAttribute: getAttribute,
hasAttribute: hasAttribute,
Dom.emit = emit;
Dom.Config = Config;
Dom.Snapshot = Snapshot;
setCache: FN,
shortcuts: FN,
loadResults: FN,
saveResults: FN,
Dom.Operators = Operators;
Dom.Selectors = Selectors;
emit: emit,
Config: Config,
Snapshot: Snapshot,
Dom.Version = version;
Operators: Operators,
Selectors: Selectors,
Dom.registerOperator =
function(symbol, resolver) {
Operators[symbol] || (Operators[symbol] = resolver);
};
Tokens: Tokens,
Version: version,
Dom.registerSelector =
function(name, rexp, func) {
Selectors[name] || (Selectors[name] = global.Object({
Expression: rexp,
Callback: func
}));
};
registerOperator:
function(symbol, resolver) {
Operators[symbol] || (Operators[symbol] = resolver);
},
switchContext(doc, true);
registerSelector:
function(name, rexp, func) {
Selectors[name] || (Selectors[name] = {
Expression: rexp,
Callback: func
});
}
};
initialize(doc);
return Dom;
});

@@ -8,5 +8,5 @@ /*

* Author: Diego Perini <diego.perini at gmail com>
* Version: 1.3.8
* Version: 1.3.9
* Created: 20070722
* Release: 20160613
* Release: 20161026
*

@@ -22,39 +22,14 @@ * License:

if (typeof module == 'object' && typeof exports == 'object') {
// in a Node.js environment, the nwmatcher functions will operate on
// the passed "browserGlobal" and will be returned in an object
module.exports = function (browserGlobal) {
// passed global does not contain
// references to native objects
browserGlobal.console = console;
browserGlobal.parseInt = parseInt;
browserGlobal.Function = Function;
browserGlobal.Boolean = Boolean;
browserGlobal.Number = Number;
browserGlobal.RegExp = RegExp;
browserGlobal.String = String;
browserGlobal.Object = Object;
browserGlobal.Array = Array;
browserGlobal.Error = Error;
browserGlobal.Date = Date;
browserGlobal.Math = Math;
var exports = browserGlobal.Object();
factory(browserGlobal, exports);
return exports;
};
module.factory = factory;
module.exports = factory;
} else if (typeof define === 'function' && define["amd"]) {
define(factory);
} else {
// in a browser environment, the nwmatcher functions will operate on
// the "global" loading them and be attached to "global.NW.Dom"
factory(global,
(global.NW || (global.NW = global.Object())) &&
(global.NW.Dom || (global.NW.Dom = global.Object())));
global.NW.Dom.factory = factory;
global.NW || (global.NW = { });
global.NW.Dom = factory(global);
}
})(this, function(global, exports) {
})(this, function(global) {
var version = 'nwmatcher-1.3.8',
var version = 'nwmatcher-1.3.9',
Dom = exports,
// processing context & root element

@@ -65,4 +40,3 @@ doc = global.document,

// save utility methods references
slice = global.Array.prototype.slice,
string = global.Object.prototype.toString,
slice = [ ].slice,

@@ -91,6 +65,6 @@ // persist previous parsed data

// accepted whitespace characters
whitespace = '[\\x20\\t\\n\\r\\f]*',
whitespace = '[\\x20\\t\\n\\r\\f]',
// 4 combinators F E, F>E, F+E, F~E
combinators = '[\\x20]|[>+~](?=[^>+~])',
combinators = '\\x20|[>+~](?=[^>+~])',

@@ -100,112 +74,76 @@ // an+b format params for pseudo-classes

// CSS quoted string values
quotedvalue = '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"' + "|'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'",
// skip round brackets groups
skipround = '\\([^()]+\\)|\\(.*\\)',
// skip curly brackets groups
skipcurly = '\\{[^{}]+\\}|\\{.*\\}',
// skip square brackets groups
skipsquare = '\\[[^[\\]]*\\]|\\[.*\\]',
// skip [ ], ( ), { } brackets groups
skipgroup = '\\[.*\\]|\\(.*\\)|\\{.*\\}',
skip_groups = '\\[.*\\]|\\(.*\\)|\\{.*\\}',
// http://www.w3.org/TR/css3-syntax/#characters
// unicode/ISO 10646 characters 161 and higher
// NOTE: Safari 2.0.x crashes with escaped (\\)
// Unicode ranges in regular expressions so we
// use a negated character range class instead
encoding = '(?:[-\\w]|[^\\x00-\\xa0]|\\\\.)',
// any escaped char
any_esc_chr = '\\\\.',
// alpha chars & low dash
alphalodash = '[_a-zA-Z]',
// non-ascii chars (utf-8)
non_asc_chr = '[^\\x00-\\x9f]',
// escape sequences in strings
escaped_chr = '\\\\[^\\n\\r\\f0-9a-fA-F]',
// Unicode chars including trailing whitespace
unicode_chr = '\\\\[0-9a-fA-F]{1,6}(?:\\r\\n|' + whitespace + ')?',
// CSS identifier syntax
identifier = '(?:-?[_a-zA-Z]{1}[-\\w]*|[^\\x00-\\xa0]+|\\\\.+)+',
// CSS quoted string values
quotedvalue = '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"' + "|'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'",
// build attribute string
attrcheck = '(' + quotedvalue + '|' + identifier + ')',
attributes = whitespace + '(' + encoding + '*:?' + encoding + '+)' +
whitespace + '(?:' + operators + whitespace + attrcheck + ')?' + whitespace,
attrmatcher = attributes.replace(attrcheck, '([\\x22\\x27]*)((?:\\\\?.)*?)\\3'),
// regular expression used to skip single/nested brackets groups (round, square, curly)
// used to split comma groups excluding commas inside quotes '' "" or brackets () [] {}
reSplitGroup = /([^,\\()[\]]+|\[[^[\]]*\]|\[.*\]|\([^()]+\)|\(.*\)|\{[^{}]+\}|\{.*\}|\\.)+/g,
// build pseudoclass string
pseudoclass = '((?:' +
// an+b parameters or quoted string
pseudoparms + '|' + quotedvalue + '|' +
// id, class, pseudo-class selector
prefixes + '|' + encoding + '+|' +
// nested HTML attribute selector
'\\[' + attributes + '\\]|' +
// nested pseudo-class selector
'\\(.+\\)|' + whitespace + '|' +
// nested pseudos/separators
',)+)',
// regular expression to trim extra leading/trailing whitespace in selector strings
// whitespace is any combination of these 5 character [\x20\t\n\r\f]
// http://www.w3.org/TR/css3-selectors/#selector-syntax
reTrimSpaces = RegExp('[\\n\\r\\f]|^' + whitespace + '+|' + whitespace + '+$', 'g'),
// placeholder for extensions
extensions = '.+',
// regular expression used in convertEscapes and unescapeIdentifier
reEscapedChars = /\\([0-9a-fA-F]{1,6}[\x20\t\n\r\f]?|.)|([\x22\x27])/g,
// CSS3: syntax scanner and
// one pass validation only
// using regular expression
standardValidator =
// discard start
'(?=[\\x20\\t\\n\\r\\f]*[^>+~(){}<>])' +
// open match group
'(' +
//universal selector
'\\*' +
// id/class/tag/pseudo-class identifier
'|(?:' + prefixes + identifier + ')' +
// combinator selector
'|' + combinators +
// HTML attribute selector
'|\\[' + attributes + '\\]' +
// pseudo-classes parameters
'|\\(' + pseudoclass + '\\)' +
// dom properties selector (extension)
'|\\{' + extensions + '\\}' +
// selector group separator (comma)
'|(?:,|' + whitespace + ')' +
// close match group
')+',
// for in excess whitespace removal
reWhiteSpace = /[\x20\t\n\r\f]+/g,
// validator for complex selectors in ':not()' pseudo-classes
extendedValidator = standardValidator.replace(pseudoclass, '.*'),
standardValidator, extendedValidator, reValidator,
// validator for standard selectors as default
reValidator = new global.RegExp(standardValidator),
attrcheck, attributes, attrmatcher, pseudoclass,
// whitespace is any combination of these 5 character [\x20\t\n\r\f]
// http://www.w3.org/TR/css3-selectors/#selector-syntax
reTrimSpaces = new global.RegExp('^' +
whitespace + '|' + whitespace + '$', 'g'),
reOptimizeSelector, reSimpleNot, reSplitToken,
// only allow simple selectors nested in ':not()' pseudo-classes
reSimpleNot = new global.RegExp('^(' +
'(?!:not)' +
'(' + prefixes +
'|' + identifier +
'|\\([^()]*\\))+' +
'|\\[' + attributes + '\\]' +
')$'),
Optimize, reClass, reSimpleSelector,
// split comma groups, exclude commas from
// quotes '' "" and from brackets () [] {}
reSplitGroup = new global.RegExp('(' +
'[^,\\\\()[\\]]+' +
'|' + skipsquare +
'|' + skipround +
'|' + skipcurly +
'|\\\\.' +
')+', 'g'),
// http://www.w3.org/TR/css3-syntax/#characters
// unicode/ISO 10646 characters \xA0 and higher
// NOTE: Safari 2.0.x crashes with escaped (\\)
// Unicode ranges in regular expressions so we
// use a negated character range class instead
// now assigned at runtime from config options
identifier,
// split last, right most, selector group token
reSplitToken = new global.RegExp('(' +
'\\[' + attributes + '\\]|' +
'\\(' + pseudoclass + '\\)|' +
'\\\\.|[^\\x20\\t\\r\\n\\f>+~])+', 'g'),
// placeholder for extensions
extensions = '.+',
// for in excess whitespace removal
reWhiteSpace = /[\x20\t\n\r\f]+/g,
// precompiled Regular Expressions
Patterns = {
// structural pseudo-classes and child selectors
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,
// 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,
// E > F
children: RegExp('^' + whitespace + '*\\>' + whitespace + '*(.*)'),
// E + F
adjacent: RegExp('^' + whitespace + '*\\+' + whitespace + '*(.*)'),
// E ~ F
relative: RegExp('^' + whitespace + '*\\~' + whitespace + '*(.*)'),
// E F
ancestor: RegExp('^' + whitespace + '+(.*)'),
// all
universal: RegExp('^\\*(.*)')
},
reOptimizeSelector = new global.RegExp(identifier + '|^$'),
Tokens = {
prefixes: prefixes,
identifier: identifier,
attributes: attributes
},

@@ -217,3 +155,3 @@ /*----------------------------- FEATURE TESTING ----------------------------*/

var re = / \w+\(/,
isnative = String(Object.prototype.toString).replace(re, ' (');
isnative = String(({ }).toString).replace(re, ' (');
return function(method) {

@@ -259,3 +197,3 @@ return method && typeof method != 'string' &&

(function() {
var isBuggy = true, x = 'x' + global.String(+new global.Date),
var isBuggy = true, x = 'x' + String(+new Date),
a = doc.createElementNS ? 'a' : '<a name="' + x + '">';

@@ -335,6 +273,7 @@ (a = doc.createElement(a)).name = x;

// detect Opera browser
OPERA = /opera/i.test(string.call(global.opera)),
OPERA = typeof global.opera != 'undefined' &&
(/opera/i).test(({ }).toString.call(global.opera)),
// skip simple selector optimizations for Opera >= 11
OPERA_QSAPI = OPERA && global.parseFloat(global.opera.version()) >= 11,
OPERA_QSAPI = OPERA && parseFloat(global.opera.version()) >= 11,

@@ -344,3 +283,3 @@ // check Selector API implementations

(function() {
var pattern = new global.Array(), context, element,
var pattern = [ ], context, element,

@@ -413,3 +352,3 @@ expect = function(selector, element, n) {

return pattern.length ?
new global.RegExp(pattern.join('|')) :
RegExp(pattern.join('|')) :
{ 'test': function() { return false; } };

@@ -420,39 +359,30 @@

// matches class selectors
RE_CLASS = new global.RegExp('(?:\\[[\\x20\\t\\n\\r\\f]*class\\b|\\.' + identifier + ')'),
/*----------------------------- LOOKUP OBJECTS -----------------------------*/
// matches simple id, tag & class selectors
RE_SIMPLE_SELECTOR = new global.RegExp(
BUGGY_GEBTN && BUGGY_GEBCN || OPERA ?
'^#?-?[_a-zA-Z]{1}' + encoding + '*$' : BUGGY_GEBTN ?
'^[.#]?-?[_a-zA-Z]{1}' + encoding + '*$' : BUGGY_GEBCN ?
'^(?:\\*|#-?[_a-zA-Z]{1}' + encoding + '*)$' :
'^(?:\\*|[.#]?-?[_a-zA-Z]{1}' + encoding + '*)$'),
IE_LT_9 = typeof doc.addEventListener != 'function',
/*----------------------------- LOOKUP OBJECTS -----------------------------*/
LINK_NODES = { 'a': 1, 'A': 1, 'area': 1, 'AREA': 1, 'link': 1, 'LINK': 1 },
LINK_NODES = new global.Object({ 'a': 1, 'A': 1, 'area': 1, 'AREA': 1, 'link': 1, 'LINK': 1 }),
// boolean attributes should return attribute name instead of true/false
ATTR_BOOLEAN = new global.Object({
ATTR_BOOLEAN = {
'checked': 1, 'disabled': 1, 'ismap': 1,
'multiple': 1, 'readonly': 1, 'selected': 1
}),
},
// dynamic attributes that needs to be checked against original HTML value
ATTR_DEFAULT = new global.Object({
ATTR_DEFAULT = {
'value': 'defaultValue',
'checked': 'defaultChecked',
'selected': 'defaultSelected'
}),
},
// attributes referencing URI data values need special treatment in IE
ATTR_URIDATA = new global.Object({
ATTR_URIDATA = {
'action': 2, 'cite': 2, 'codebase': 2, 'data': 2, 'href': 2,
'longdesc': 2, 'lowsrc': 2, 'src': 2, 'usemap': 2
}),
},
// HTML 5 draft specifications
// http://www.whatwg.org/specs/web-apps/current-work/#selectors
HTML_TABLE = new global.Object({
HTML_TABLE = {
// class attribute must be treated case-insensitive in HTML quirks mode

@@ -470,7 +400,7 @@ // initialized by default to Standard Mode (case-sensitive),

'text': 1, 'type': 1, 'valign': 1, 'valuetype': 1, 'vlink': 1
}),
},
// the following attributes must be treated case-insensitive in XHTML mode
// Niels Leenheer http://rakaz.nl/item/css_selector_bugs_case_sensitivity
XHTML_TABLE = new global.Object({
XHTML_TABLE = {
'accept': 1, 'accept-charset': 1, 'alink': 1, 'axis': 1,

@@ -481,3 +411,3 @@ 'bgcolor': 1, 'charset': 1, 'codetype': 1, 'color': 1,

'rev': 1, 'target': 1, 'text': 1, 'type': 1, 'vlink': 1
}),
},

@@ -487,3 +417,3 @@ /*-------------------------- REGULAR EXPRESSIONS ---------------------------*/

// placeholder to add functionalities
Selectors = new global.Object({
Selectors = {
// as a simple example this will check

@@ -500,6 +430,6 @@ // for chars not in standard ascii table

// checks and only if none of them worked
}),
},
// attribute operators
Operators = new global.Object({
Operators = {
'=': "n=='%m'",

@@ -511,37 +441,4 @@ '^=': "n.indexOf('%m')==0",

'$=': "n.substr(n.length-'%m'.length)=='%m'"
}),
},
// optimization expressions
Optimize = new global.Object({
ID: new global.RegExp('^\\*?#(' + encoding + '+)|' + skipgroup),
TAG: new global.RegExp('^(' + encoding + '+)|' + skipgroup),
CLASS: new global.RegExp('^\\*?\\.(' + encoding + '+$)|' + skipgroup)
}),
// precompiled Regular Expressions
Patterns = new global.Object({
// structural pseudo-classes and child selectors
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,
// 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,
// element attribute matcher
attribute: new global.RegExp('^\\[' + attrmatcher + '\\](.*)'),
// E > F
children: /^[\x20\t\n\r\f]*\>[\x20\t\n\r\f]*(.*)/,
// E + F
adjacent: /^[\x20\t\n\r\f]*\+[\x20\t\n\r\f]*(.*)/,
// E ~ F
relative: /^[\x20\t\n\r\f]*\~[\x20\t\n\r\f]*(.*)/,
// E F
ancestor: /^[\x20\t\n\r\f]+(.*)/,
// all
universal: /^\*(.*)/,
// id
id: new global.RegExp('^#(' + encoding + '+)(.*)'),
// tag
tagName: new global.RegExp('^(' + encoding + '+)(.*)'),
// class
className: new global.RegExp('^\\.(' + encoding + '+)(.*)')
}),
/*------------------------------ UTIL METHODS ------------------------------*/

@@ -553,4 +450,4 @@

var i = -1, element;
if (!data.length && global.Array.slice)
return global.Array.slice(elements);
if (!data.length && Array.slice)
return Array.slice(elements);
while ((element = elements[++i]))

@@ -624,49 +521,72 @@ data[data.length] = element;

// convert a CSS string or identifier containing escape sequence to a
// javascript string with javascript escape sequences
// convert single codepoint to UTF-16 encoding
codePointToUTF16 =
function(codePoint) {
// out of range, use replacement character
if (codePoint < 1 || codePoint > 0x10ffff ||
(codePoint > 0xd7ff && codePoint < 0xe000)) {
return '\\ufffd';
}
// javascript strings are UTF-16 encoded
if (codePoint < 0x10000) {
var lowHex = '000' + codePoint.toString(16);
return '\\u' + lowHex.substr(lowHex.length - 4);
}
// supplementary high + low surrogates
return '\\u' + (((codePoint - 0x10000) >> 0x0a) + 0xd800).toString(16) +
'\\u' + (((codePoint - 0x10000) % 0x400) + 0xdc00).toString(16);
},
// convert single codepoint to string
stringFromCodePoint =
function(codePoint) {
// out of range, use replacement character
if (codePoint < 1 || codePoint > 0x10ffff ||
(codePoint > 0xd7ff && codePoint < 0xe000)) {
return '\ufffd';
}
if (codePoint < 0x10000) {
return String.fromCharCode(codePoint);
}
return String.fromCodePoint ?
String.fromCodePoint(codePoint) :
String.fromCharCode(
((codePoint - 0x10000) >> 0x0a) + 0xd800,
((codePoint - 0x10000) % 0x400) + 0xdc00);
},
// convert escape sequence in a CSS string or identifier
// to javascript string with javascript escape sequences
convertEscapes =
function(str) {
return str.replace(/\\([0-9a-fA-F]{1,6}\x20?|.)|([\x22\x27])/g, function(substring, p1, p2) {
var codePoint, highHex, highSurrogate, lowHex, lowSurrogate;
if (p2) {
// unescaped " or '
return '\\' + p2;
}
if (/^[0-9a-fA-F]/.test(p1)) {
// \1f23
codePoint = parseInt(p1, 16);
if (codePoint < 0 || codePoint > 0x10ffff) {
// the replacement character
return '\\ufffd';
return str.replace(reEscapedChars,
function(substring, p1, p2) {
// unescaped " or '
return p2 ? '\\' + p2 :
// javascript strings are UTF-16 encoded
/^[0-9a-fA-F]/.test(p1) ? codePointToUTF16(parseInt(p1, 16)) :
// \' \"
/^[\\\x22\x27]/.test(p1) ? substring :
// \g \h \. \# etc
p1;
}
);
},
// javascript strings are in UTF-16
if (codePoint <= 0xffff) {
// Basic
lowHex = '000' + codePoint.toString(16);
return '\\u' + lowHex.substr(lowHex.length - 4);
// convert escape sequence in a CSS string or identifier
// to javascript string with characters representations
unescapeIdentifier =
function(str) {
return str.replace(reEscapedChars,
function(substring, p1, p2) {
// unescaped " or '
return p2 ? p2 :
// javascript strings are UTF-16 encoded
/^[0-9a-fA-F]/.test(p1) ? stringFromCodePoint(parseInt(p1, 16)) :
// \' \"
/^[\\\x22\x27]/.test(p1) ? substring :
// \g \h \. \# etc
p1;
}
// Supplementary
codePoint -= 0x10000;
highSurrogate = (codePoint >> 10) + 0xd800;
lowSurrogate = (codePoint % 0x400) + 0xdc00;
highHex = '000' + highSurrogate.toString(16);
lowHex = '000' + lowSurrogate.toString(16);
return '\\u' + highHex.substr(highHex.length - 4) +
'\\u' + lowHex.substr(lowHex.length - 4);
}
if (/^[\\\x22\x27]/.test(p1)) {
// \' \"
return substring;
}
// \g \h \. \# etc
return p1;
});
);
},

@@ -680,3 +600,3 @@

function(id, elements) {
var i = -1, element = null;
var i = -1, element;
while ((element = elements[++i])) {

@@ -687,3 +607,3 @@ if (element.getAttribute('id') == id) {

}
return element;
return element || null;
},

@@ -695,3 +615,3 @@

function(id, from) {
id = id.replace(/\\([^\\]{1})/g, '$1');
id = (/\\/).test(id) ? unescapeIdentifier(id) : id;
return from.getElementById && from.getElementById(id) ||

@@ -702,3 +622,3 @@ byIdRaw(id, from.getElementsByTagName('*'));

var element = null;
id = id.replace(/\\([^\\]{1})/g, '$1');
id = (/\\/).test(id) ? unescapeIdentifier(id) : id;
if (XML_DOCUMENT || from.nodeType != 9) {

@@ -727,3 +647,3 @@ return byIdRaw(id, from.getElementsByTagName('*'));

function(tag, from) {
var any = tag == '*', element = from, elements = new global.Array(), next = element.firstChild;
var any = tag == '*', element = from, elements = [ ], next = element.firstChild;
any || (tag = tag.toUpperCase());

@@ -750,8 +670,10 @@ while ((element = next)) {

function(tag, from) {
var i = -1, j = i, data = new global.Array(),
element, elements = from.getElementsByTagName(tag);
var i = -1, j = i, data = [ ], element,
elements = XML_DOCUMENT || from.nodeType == 11 ?
byTagRaw(tag, from) : from.getElementsByTagName(tag);
if (tag == '*') {
while ((element = elements[++i])) {
if (element.nodeName > '@')
if (element.nodeName > '@') {
data[++j] = element;
}
}

@@ -786,4 +708,4 @@ } else {

function(name, from) {
var i = -1, j = i, data = new global.Array(), element, elements = _byTag('*', from), n;
name = ' ' + (QUIRKS_MODE ? name.toLowerCase() : name).replace(/\\([^\\]{1})/g, '$1') + ' ';
var i = -1, j = i, data = [ ], element, elements = _byTag('*', from), n;
name = ' ' + (QUIRKS_MODE ? name.toLowerCase() : name) + ' ';
while ((element = elements[++i])) {

@@ -803,4 +725,6 @@ n = XML_DOCUMENT ? element.getAttribute('class') : element.className;

function(name, from) {
name = QUIRKS_MODE ? name.toLowerCase() : name;
name = (/\\/).test(name) ? unescapeIdentifier(name) : name;
return (BUGGY_GEBCN || BUGGY_QUIRKS_GEBCN || XML_DOCUMENT || !from.getElementsByClassName) ?
byClassRaw(name, from) : slice.call(from.getElementsByClassName(name.replace(/\\([^\\]{1})/g, '$1')), 0);
byClassRaw(name, from) : slice.call(from.getElementsByClassName(name));
},

@@ -835,3 +759,3 @@

// @return string
getAttribute = !BUGGY_GET_ATTRIBUTE ?
getAttribute = !BUGGY_GET_ATTRIBUTE && !IE_LT_9 ?
function(node, attribute) {

@@ -858,3 +782,3 @@ return node.getAttribute(attribute);

// @return boolean
hasAttribute = !BUGGY_HAS_ATTRIBUTE ?
hasAttribute = !BUGGY_HAS_ATTRIBUTE && !IE_LT_9 ?
function(node, attribute) {

@@ -918,11 +842,11 @@ return XML_DOCUMENT ?

function(option) {
if (typeof option == 'string') { return Config[option] || Config; }
if (typeof option != 'object') { return false; }
if (typeof option == 'string') { return !!Config[option]; }
if (typeof option != 'object') { return Config; }
for (var i in option) {
Config[i] = !!option[i];
if (i == 'SIMPLENOT') {
matchContexts = new global.Object();
matchResolvers = new global.Object();
selectContexts = new global.Object();
selectResolvers = new global.Object();
matchContexts = { };
matchResolvers = { };
selectContexts = { };
selectResolvers = { };
if (!Config[i]) { Config['USE_QSAPI'] = false; }

@@ -933,3 +857,4 @@ } else if (i == 'USE_QSAPI') {

}
reValidator = new global.RegExp(Config.SIMPLENOT ?
setIdentifierSyntax();
reValidator = RegExp(Config.SIMPLENOT ?
standardValidator : extendedValidator);

@@ -942,9 +867,9 @@ return true;

function(message) {
if (Config.VERBOSITY) { throw new global.Error(message); }
if (global.console && global.console.log) {
global.console.log(message);
if (Config.VERBOSITY) { throw Error(message); }
if (console && console.log) {
console.log(message);
}
},
Config = new global.Object({
Config = {

@@ -954,2 +879,14 @@ // used to enable/disable caching of result sets

// used to enable/disable CSS escaped identifiers
ESCAPECHR: true,
// add non-ascii (utf-8) to the identifier syntax RE
NON_ASCII: true,
// switch between CSS2 and CSS3 identifier syntax RE
SELECTOR3: true,
// add Unicode (utf-16) to the identifier syntax RE
UNICODE16: true,
// by default do not add missing left/right context

@@ -977,6 +914,121 @@ // to selector string shortcuts like "+div" or "ul>"

}),
},
/*---------------------------- COMPILER METHODS ----------------------------*/
// init REs and context
initialize =
function(doc) {
setIdentifierSyntax();
switchContext(doc, true);
},
// set/reset default identifier syntax
// based on user configuration options
// rebuild the validator and other REs
setIdentifierSyntax =
function() {
var syntax = '', start = Config['SELECTOR3'] ? '-{2}|' : '';
Config['NON_ASCII'] && (syntax += '|' + non_asc_chr);
Config['UNICODE16'] && (syntax += '|' + unicode_chr);
Config['ESCAPECHR'] && (syntax += '|' + escaped_chr);
syntax += (Config['UNICODE16'] || Config['ESCAPECHR']) ? '' : '|' + any_esc_chr;
identifier = '-?(?:' + start + alphalodash + syntax + ')(?:-|[0-9]|' + alphalodash + syntax + ')*';
// build attribute string
attrcheck = '(' + quotedvalue + '|' + identifier + ')';
attributes = whitespace + '*(' + identifier + ':?' + identifier + ')' +
whitespace + '*(?:' + operators + whitespace + '*' + attrcheck + ')?' + whitespace + '*';
attrmatcher = attributes.replace(attrcheck, '([\\x22\\x27]*)((?:\\\\?.)*?)\\3');
// build pseudoclass string
pseudoclass = '((?:' +
// an+b parameters or quoted string
pseudoparms + '|' + quotedvalue + '|' +
// id, class, pseudo-class selector
prefixes + identifier + '|' +
// nested HTML attribute selector
'\\[' + attributes + '\\]|' +
// nested pseudo-class selector
'\\(.+\\)|' + whitespace + '*|' +
// nested pseudos/separators
',)+)';
// CSS3: syntax scanner and
// one pass validation only
// using regular expression
standardValidator =
// discard start
'(?=[\\x20\\t\\n\\r\\f]*[^>+~(){}<>])' +
// open match group
'(' +
//universal selector
'\\*' +
// id/class/tag/pseudo-class identifier
'|(?:' + prefixes + identifier + ')' +
// combinator selector
'|' + combinators +
// HTML attribute selector
'|\\[' + attributes + '\\]' +
// pseudo-classes parameters
'|\\(' + pseudoclass + '\\)' +
// dom properties selector (extension)
'|\\{' + extensions + '\\}' +
// selector group separator (comma)
'|(?:,|' + whitespace + '*)' +
// close match group
')+';
// only allow simple selectors nested in ':not()' pseudo-classes
reSimpleNot = RegExp('^(' +
'(?!:not)' +
'(' + prefixes + identifier +
'|\\([^()]*\\))+' +
'|\\[' + attributes + '\\]' +
')$');
// split last, right most, selector group token
reSplitToken = RegExp('(' +
prefixes + identifier + '|' +
'\\[' + attributes + '\\]|' +
'\\(' + pseudoclass + '\\)|' +
'\\\\.|[^\\x20\\t\\n\\r\\f>+~])+', 'g');
reOptimizeSelector = RegExp(identifier + '|^$');
reSimpleSelector = RegExp(
BUGGY_GEBTN && BUGGY_GEBCN || OPERA ?
'^#?' + identifier + '$' : BUGGY_GEBTN ?
'^[.#]?' + identifier + '$' : BUGGY_GEBCN ?
'^(?:\\*|#' + identifier + ')$' :
'^(?:\\*|[.#]?' + identifier + ')$');
// matches class selectors
reClass = RegExp('(?:\\[[\\x20\\t\\n\\r\\f]*class\\b|\\.' + identifier + ')');
Optimize = {
ID: RegExp('^\\*?#(' + identifier + ')|' + skip_groups),
TAG: RegExp('^(' + identifier + ')|' + skip_groups),
CLASS: RegExp('^\\.(' + identifier + '$)|' + skip_groups)
};
Patterns.id = RegExp('^#(' + identifier + ')(.*)');
Patterns.tagName = RegExp('^(' + identifier + ')(.*)');
Patterns.className = RegExp('^\\.(' + identifier + ')(.*)');
Patterns.attribute = RegExp('^\\[' + attrmatcher + '\\](.*)');
Tokens.identifier = identifier;
Tokens.attributes = attributes;
// validator for complex selectors in ':not()' pseudo-classes
extendedValidator = standardValidator.replace(pseudoclass, '.*');
// validator for standard selectors as default
reValidator = RegExp(standardValidator);
},
// code string reused to build compiled functions

@@ -1000,3 +1052,3 @@ ACCEPT_NODE = 'r[r.length]=c[k];if(f&&false===f(c[k]))break main;else continue main;',

// for each selector in the group
var i = -1, seen = new global.Object(), token;
var i = -1, seen = { }, token;
while ((token = parts[++i])) {

@@ -1014,7 +1066,7 @@ token = token.replace(reTrimSpaces, '');

// for select method
return new global.Function('c,s,r,d,h,g,f,v',
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;');
} else {
// for match method
return new global.Function('e,s,r,d,h,g,f,v',
return Function('e,s,r,d,h,g,f,v',
'var N,n,x=0,k=e;' + source + 'return false;');

@@ -1055,2 +1107,3 @@ }

// prototype selector unit need this method to recover bad HTML forms
match[1] = (/\\/).test(match[1]) ? convertEscapes(match[1]) : match[1];
source = 'if(' + (XML_DOCUMENT ?

@@ -1080,7 +1133,8 @@ 's.getAttribute(e,"id")' :

// and notes at the bottom; explicitly non-normative in this specification.
match[1] = (/\\/).test(match[1]) ? convertEscapes(match[1]) : match[1];
match[1] = QUIRKS_MODE ? match[1].toLowerCase() : match[1];
source = 'if((n=' + (XML_DOCUMENT ?
's.getAttribute(e,"class")' : 'e.className') +
')&&n.length&&(" "+' + (QUIRKS_MODE ? 'n.toLowerCase()' : 'n') +
'.replace(' + reWhiteSpace + '," ")+" ").indexOf(" ' +
(QUIRKS_MODE ? match[1].toLowerCase() : match[1]) + ' ")>-1' +
'.replace(/' + whitespace + '+/g," ")+" ").indexOf(" ' + match[1] + ' ")>-1' +
'){' + source + '}';

@@ -1107,3 +1161,3 @@ }

if (match[2] && match[4] && (test = Operators[match[2]])) {
match[4] = convertEscapes(match[4]);
match[4] = (/\\/).test(match[4]) ? convertEscapes(match[4]) : match[4];
// case treatment depends on document

@@ -1193,4 +1247,4 @@ HTML_TABLE['class'] = QUIRKS_MODE ? 1 : 0;

// assumes correct "an+b" format, "b" before "a" to keep "n" values
b = ((n = match[2].match(/(-?\d+)$/)) ? global.parseInt(n[1], 10) : 0);
a = ((n = match[2].match(/(-?\d*)n/i)) ? global.parseInt(n[1], 10) : 0);
b = ((n = match[2].match(/(-?\d+)$/)) ? parseInt(n[1], 10) : 0);
a = ((n = match[2].match(/(-?\d*)n/i)) ? parseInt(n[1], 10) : 0);
if (n && n[1] == '-') a = -1;

@@ -1405,3 +1459,8 @@ }

selector = selector.replace(reTrimSpaces, '');
// normalize the selector string, remove [\n\r\f]
// whitespace, replace codepoints 0 with '\ufffd'
// trim non-relevant leading/trailing whitespaces
selector = selector.
replace(reTrimSpaces, '').
replace(/\x00|\\$/g, '\ufffd');

@@ -1429,3 +1488,3 @@ Config.SHORTCUTS && (selector = Dom.shortcuts(selector, element, from));

return matchResolvers[selector](element, Snapshot, [ ], doc, root, from, callback, new global.Object());
return matchResolvers[selector](element, Snapshot, [ ], doc, root, from, callback, { });
},

@@ -1467,3 +1526,10 @@

if (!OPERA_QSAPI && RE_SIMPLE_SELECTOR.test(selector)) {
// normalize the selector string, remove [\n\r\f]
// whitespace, replace codepoints 0 with '\ufffd'
// trim non-relevant leading/trailing whitespaces
selector = selector.
replace(reTrimSpaces, '').
replace(/\x00|\\$/g, '\ufffd');
if (!OPERA_QSAPI && reSimpleSelector.test(selector)) {
switch (selector.charAt(0)) {

@@ -1485,3 +1551,3 @@ case '#':

else if (!XML_DOCUMENT && Config.USE_QSAPI &&
!(BUGGY_QUIRKS_QSAPI && RE_CLASS.test(selector)) &&
!(BUGGY_QUIRKS_QSAPI && reClass.test(selector)) &&
!RE_BUGGY_QSAPI.test(selector)) {

@@ -1500,4 +1566,2 @@ try {

selector = selector.replace(reTrimSpaces, '');
Config.SHORTCUTS && (selector = Dom.shortcuts(selector, from));

@@ -1543,4 +1607,4 @@

callback && callback(element);
elements = new global.Array(element);
} else elements = new global.Array();
elements = [element];
} else elements = [ ];
}

@@ -1554,3 +1618,3 @@ }

callback && callback(element);
elements = new global.Array(element);
elements = [element];
} else if (/[>+~]/.test(selector)) {

@@ -1561,3 +1625,3 @@ from = element.parentNode;

}
} else elements = new global.Array();
} else elements = [ ];
}

@@ -1577,7 +1641,4 @@

if ((elements = _byClass(token, from)).length === 0) { return [ ]; }
if (reOptimizeSelector.test(selector.charAt(selector.indexOf(token) - 1))) {
selector = selector.slice(0, lastPosition) + selector.slice(lastPosition).replace('.' + token, '');
} else {
selector = selector.slice(0, lastPosition) + selector.slice(lastPosition).replace('.' + token, '*');
}
selector = selector.slice(0, lastPosition) + selector.slice(lastPosition).replace('.' + token,
reOptimizeSelector.test(selector.charAt(selector.indexOf(token) - 1)) ? '' : '*');
}

@@ -1587,11 +1648,8 @@

if ((elements = _byClass(token, from)).length === 0) { return [ ]; }
for (i = 0, els = new global.Array(); elements.length > i; ++i) {
for (i = 0, els = [ ]; elements.length > i; ++i) {
els = concatList(els, elements[i].getElementsByTagName('*'));
}
elements = els;
if (reOptimizeSelector.test(selector.charAt(selector.indexOf(token) - 1))) {
selector = selector.slice(0, lastPosition) + selector.slice(lastPosition).replace('.' + token, '');
} else {
selector = selector.slice(0, lastPosition) + selector.slice(lastPosition).replace('.' + token, '*');
}
selector = selector.slice(0, lastPosition) + selector.slice(lastPosition).replace('.' + token,
reOptimizeSelector.test(selector.charAt(selector.indexOf(token) - 1)) ? '' : '*');
}

@@ -1607,3 +1665,7 @@

if (!elements) {
elements = /^(?:applet|object)$/i.test(from.nodeName) ? from.childNodes : _byTag('*', from);
if (IE_LT_9) {
elements = /^(?:applet|object)$/i.test(from.nodeName) ? from.children : byTagRaw('*', from);
} else {
elements = from.getElementsByTagName('*');
}
}

@@ -1618,3 +1680,3 @@ // end of prefiltering pass

elements = selectResolvers[selector](elements, Snapshot, [ ], doc, root, from, callback, new global.Object());
elements = selectResolvers[selector](elements, Snapshot, [ ], doc, root, from, callback, { });

@@ -1632,11 +1694,11 @@ Config.CACHING && Dom.saveResults(original, from, doc, elements);

// compiled match functions returning booleans
matchContexts = new global.Object(),
matchResolvers = new global.Object(),
matchContexts = { },
matchResolvers = { },
// compiled select functions returning collections
selectContexts = new global.Object(),
selectResolvers = new global.Object(),
selectContexts = { },
selectResolvers = { },
// used to pass methods to compiled functions
Snapshot = new global.Object({
Snapshot = {

@@ -1665,115 +1727,107 @@ // element indexing methods

match: match
}),
},
Tokens = new global.Object({
prefixes: prefixes,
encoding: encoding,
operators: operators,
whitespace: whitespace,
identifier: identifier,
attributes: attributes,
combinators: combinators,
pseudoclass: pseudoclass,
pseudoparms: pseudoparms,
quotedvalue: quotedvalue
});
/*------------------------------- PUBLIC API -------------------------------*/
// code referenced by extensions
Dom.ACCEPT_NODE = ACCEPT_NODE;
Dom = {
// retrieve element by id attr
Dom.byId = byId;
ACCEPT_NODE: ACCEPT_NODE,
// retrieve elements by tag name
Dom.byTag = byTag;
// retrieve element by id attr
byId: byId,
// retrieve elements by name attr
Dom.byName = byName;
// retrieve elements by tag name
byTag: byTag,
// retrieve elements by class name
Dom.byClass = byClass;
// retrieve elements by name attr
byName: byName,
// read the value of the attribute
// as was in the original HTML code
Dom.getAttribute = getAttribute;
// retrieve elements by class name
byClass: byClass,
// check for the attribute presence
// as was in the original HTML code
Dom.hasAttribute = hasAttribute;
// read the value of the attribute
// as was in the original HTML code
getAttribute: getAttribute,
// element match selector, return boolean true/false
Dom.match = match;
// check for the attribute presence
// as was in the original HTML code
hasAttribute: hasAttribute,
// first element match only, return element or null
Dom.first = first;
// element match selector, return boolean true/false
match: match,
// elements matching selector, starting from element
Dom.select = select;
// first element match only, return element or null
first: first,
// compile selector into ad-hoc javascript resolver
Dom.compile = compile;
// elements matching selector, starting from element
select: select,
// check that two elements are ancestor/descendant
Dom.contains = contains;
// compile selector into ad-hoc javascript resolver
compile: compile,
// handle selector engine configuration settings
Dom.configure = configure;
// check that two elements are ancestor/descendant
contains: contains,
// initialize caching for each document
Dom.setCache = FN;
// handle selector engine configuration settings
configure: configure,
// load previously collected result set
Dom.loadResults = FN;
// initialize caching for each document
setCache: FN,
// save previously collected result set
Dom.saveResults = FN;
// load previously collected result set
loadResults: FN,
// handle missing context in selector strings
Dom.shortcuts = FN;
// save previously collected result set
saveResults: FN,
// log resolvers errors/warnings
Dom.emit = emit;
// handle missing context in selector strings
shortcuts: FN,
// options enabing specific engine functionality
Dom.Config = Config;
// log resolvers errors/warnings
emit: emit,
// pass methods references to compiled resolvers
Dom.Snapshot = Snapshot;
// options enabing specific engine functionality
Config: Config,
// operators descriptor
// for attribute operators extensions
Dom.Operators = Operators;
// pass methods references to compiled resolvers
Snapshot: Snapshot,
// selectors descriptor
// for pseudo-class selectors extensions
Dom.Selectors = Selectors;
// operators descriptor
// for attribute operators extensions
Operators: Operators,
// export string patterns
Dom.Tokens = Tokens;
// selectors descriptor
// for pseudo-class selectors extensions
Selectors: Selectors,
// export version string
Dom.Version = version;
// export validators REs
Tokens: Tokens,
// add or overwrite user defined operators
Dom.registerOperator =
function(symbol, resolver) {
Operators[symbol] || (Operators[symbol] = resolver);
};
// export version string
Version: version,
// add selector patterns for user defined callbacks
Dom.registerSelector =
function(name, rexp, func) {
Selectors[name] || (Selectors[name] = new global.Object({
Expression: rexp,
Callback: func
}));
};
// add or overwrite user defined operators
registerOperator:
function(symbol, resolver) {
Operators[symbol] || (Operators[symbol] = resolver);
},
// add selector patterns for user defined callbacks
registerSelector:
function(name, rexp, func) {
Selectors[name] || (Selectors[name] = {
Expression: rexp,
Callback: func
});
}
};
/*---------------------------------- INIT ----------------------------------*/
// init context specific variables
switchContext(doc, true);
initialize(doc);
return Dom;
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc