diff --git a/unexpected-dom.js b/unexpected-dom.js index 9371b1b3..2315615c 100644 --- a/unexpected-dom.js +++ b/unexpected-dom.js @@ -277,7 +277,7 @@ module.exports = { }, inspect: function (document, depth, output, inspect) { for (var i = 0 ; i < document.childNodes.length ; i += 1) { - output.append(inspect(document.childNodes[i], depth - 1)); + output.append(inspect(document.childNodes[i])); } }, diff: function (actual, expected, output, diff, inspect, equal) { @@ -325,43 +325,47 @@ module.exports = { var elementName = element.nodeName.toLowerCase(); var startTag = stringifyStartTag(element); - var inspectedChildren = []; - if (elementName === 'script') { - var type = element.getAttribute('type'); - if (!type || /javascript/.test(type)) { - type = 'javascript'; - } - inspectedChildren.push(output.clone().code(element.textContent, type)); - } else if (elementName === 'style') { - inspectedChildren.push(output.clone().code(element.textContent, element.getAttribute('type') || 'text/css')); - } else { - for (var i = 0 ; i < element.childNodes.length ; i += 1) { - inspectedChildren.push(inspect(element.childNodes[i])); - } - } - - var width = 0; - var multipleLines = inspectedChildren.some(function (o) { - var size = o.size(); - width += size.width; - return width > 50 || o.height > 1; - }); - output.code(startTag, 'html'); if (element.childNodes.length > 0) { - if (multipleLines) { - output.nl().indentLines(); + if (depth === 1) { + output.text('...'); + } else { + var inspectedChildren = []; + if (elementName === 'script') { + var type = element.getAttribute('type'); + if (!type || /javascript/.test(type)) { + type = 'javascript'; + } + inspectedChildren.push(output.clone().code(element.textContent, type)); + } else if (elementName === 'style') { + inspectedChildren.push(output.clone().code(element.textContent, element.getAttribute('type') || 'text/css')); + } else { + for (var i = 0 ; i < element.childNodes.length ; i += 1) { + inspectedChildren.push(inspect(element.childNodes[i])); + } + } - inspectedChildren.forEach(function (inspectedChild, index) { - output.i().block(inspectedChild).nl(); + var width = 0; + var multipleLines = inspectedChildren.some(function (o) { + var size = o.size(); + width += size.width; + return width > 50 || o.height > 1; }); - output.outdentLines(); - } else { - inspectedChildren.forEach(function (inspectedChild, index) { - output.append(inspectedChild); - }); + if (multipleLines) { + output.nl().indentLines(); + + inspectedChildren.forEach(function (inspectedChild, index) { + output.i().block(inspectedChild).nl(); + }); + + output.outdentLines(); + } else { + inspectedChildren.forEach(function (inspectedChild, index) { + output.append(inspectedChild); + }); + } } } output.code(stringifyEndTag(element), 'html'); @@ -788,7 +792,7 @@ module.exports = function arrayChanges(actual, expected, equal, similar) { return false; }; - var itemsDiff = arrayDiff(actual, expected, function (a, b) { + var itemsDiff = arrayDiff([].concat(actual), [].concat(expected), function (a, b) { return equal(a, b) || similar(a, b); }); @@ -814,7 +818,7 @@ module.exports = function arrayChanges(actual, expected, equal, similar) { function updateRemoveTable() { removedItems = 0; - actual.forEach(function (_, index) { + Array.prototype.forEach.call(actual, function (_, index) { removedItems += removesByIndex[index] || 0; removeTable[index] = removedItems; }); @@ -1791,4 +1795,4 @@ module.exports = { },{"../3rdparty/prism":4}]},{},[1])(1) }); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyaWZ5L25vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJsaWIvaW5kZXguanMiLCJub2RlX21vZHVsZXMvYXJyYXktY2hhbmdlcy9saWIvYXJyYXlDaGFuZ2VzLmpzIiwibm9kZV9tb2R1bGVzL2FycmF5LWNoYW5nZXMvbm9kZV9tb2R1bGVzL2FycmF5ZGlmZi9pbmRleC5qcyIsIm5vZGVfbW9kdWxlcy9tYWdpY3Blbi1wcmlzbS8zcmRwYXJ0eS9wcmlzbS5qcyIsIm5vZGVfbW9kdWxlcy9tYWdpY3Blbi1wcmlzbS9saWIvbWFnaWNQZW5QcmlzbS5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtBQ0FBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQT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IHtcbiAgICAgICAgICBmb3IgKHZhciBpID0gMCA7IGkgPCBlbGVtZW50LmNoaWxkTm9kZXMubGVuZ3RoIDsgaSArPSAxKSB7XG4gICAgICAgICAgICBpbnNwZWN0ZWRDaGlsZHJlbi5wdXNoKGluc3BlY3QoZWxlbWVudC5jaGlsZE5vZGVzW2ldKSk7XG4gICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgdmFyIHdpZHRoID0gMDtcbiAgICAgICAgdmFyIG11bHRpcGxlTGluZXMgPSBpbnNwZWN0ZWRDaGlsZHJlbi5zb21lKGZ1bmN0aW9uIChvKSB7XG4gICAgICAgICAgdmFyIHNpemUgPSBvLnNpemUoKTtcbiAgICAgICAgICB3aWR0aCArPSBzaXplLndpZHRoO1xuICAgICAgICAgIHJldHVybiB3aWR0aCA+IDUwIHx8IG8uaGVpZ2h0ID4gMTtcbiAgICAgICAgfSk7XG5cbiAgICAgICAgb3V0cHV0LmNvZGUoc3RhcnRUYWcsICdodG1sJyk7XG4gICAgICAgIGlmIChlbGVtZW50LmNoaWxkTm9kZXMubGVuZ3RoID4gMCkge1xuXG4gICAgICAgICAgaWYgKG11bHRpcGxlTGluZXMpIHtcbiAgICAgICAgICAgIG91dHB1dC5ubCgpLmluZGVudExpbmVzKCk7XG5cbiAgICAgICAgICAgIGluc3BlY3RlZENoaWxkcmVuLmZvckVhY2goZnVuY3Rpb24gKGluc3BlY3RlZENoaWxkLCBpbmRleCkge1xuICAgICAgICAgICAgICBvdXRwdXQuaSgpLmJsb2NrKGluc3BlY3RlZENoaWxkKS5ubCgpO1xuICAgICAgICAgICAgfSk7XG5cbiAgICAgICAgICAgIG91dHB1dC5vdXRkZW50TGluZXMoKTtcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaW5zcGVjdGVkQ2hpbGRyZW4uZm9yRWFjaChmdW5jdGlvbiAoaW5zcGVjdGVkQ2hpbGQsIGluZGV4KSB7XG4gICAgICAgICAgICAgIG91dHB1dC5h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G4gICAgICAgIH0pO1xuICAgICAgfVxuXG4gICAgICByZXR1cm4gZXhwZWN0LnByb21pc2UuYWxsKHByb21pc2VCeUtleSkuY2F1Z2h0KGZ1bmN0aW9uICgpIHtcbiAgICAgICAgcmV0dXJuIGV4cGVjdC5wcm9taXNlLnNldHRsZShwcm9taXNlQnlLZXkpLnRoZW4oZnVuY3Rpb24gKCkge1xuICAgICAgICAgIGV4cGVjdC5mYWlsKHtcbiAgICAgICAgICAgIGRpZmY6IGZ1bmN0aW9uIChvdXRwdXQsIGRpZmYsIGluc3BlY3QsIGVxdWFsKSB7XG4gICAgICAgICAgICAgIG91dHB1dC5ibG9jayhmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAgICAgdmFyIG91dHB1dCA9IHRoaXM7XG4gICAgICAgICAgICAgICAgb3V0cHV0XG4gICAgICAgICAgICAgICAgICAucHJpc21QdW5jdHVhdGlvbignPCcpXG4gICAgICAgICAgICAgICAgICAucHJpc21UYWcoaXNIdG1sID8gc3ViamVjdC5ub2RlTmFtZS50b0xvd2VyQ2FzZSgpIDogc3ViamVjdC5ub2RlTmFtZSk7XG4gICAgICAgICAgICAgICAgdmFyIGNhbkNvbnRpbnVlTGluZSA9IHRydWU7XG4gICAgICAgICAgICAgICAgaWYgKHByb21pc2VCeUtleS5uYW1lLmlzUmVqZWN0ZWQoKSkge1xuICAgICAgICAgICAgICAgICAgdmFyIG5hbWVFcnJvciA9IHByb21pc2VCeUtleS5uYW1lLnJlYXNvbigpO1xuICAgICAgICAgICAgICAgICAgb3V0cHV0LnNwKCkuYW5ub3RhdGlvbkJsb2NrKGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpc1xuICAgICAgICAgICAgICAgICAgICAgIC5lcnJvcigobmFtZUVycm9yICYmIG5hbWVFcnJvci5sYWJlbCkgfHwgJ3Nob3VsZCBzYXRpc2Z5JykgLy8gdjg6IGVyci5nZXRMYWJlbCgpXG4gICAgICAgICAgICAgICAgICAgICAgLnNwKClcbiAgICAgICAgICAgICAgICAgICAgICAuYXBwZW5kKGluc3BlY3QodmFsdWUubmFtZSkpO1xuICAgICAgICAgICAgICAgICAgfSkubmwoKTtcbiAgICAgICAgICAgICAgICAgIGNhbkNvbnRpbnVlTGluZSA9IGZhbHNlO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBPYmplY3Qua2V5cyhhdHRycykuZm9yRWFjaChmdW5jdGlvbiAoYXR0cmlidXRlTmFtZSkge1xuICAgICAgICAgICAgICAgICAgdmFyIHByb21pc2UgPSBwcm9taXNlQnlLZXkuYXR0cmlidXRlc1thdHRyaWJ1dGVOYW1lXTtcbiAgICAgICAgICAgICAgICAgIG91dHB1dC5zcChjYW5Db250aW51ZUxpbmUgPyAxIDogMiArIHN1YmplY3Qubm9kZU5hbWUubGVuZ3RoKTtcbiAgICAgICAgICAgICAgICAgIHdyaXRlQXR0cmlidXRlVG9NYWdpY1BlbihvdXRwdXQsIGF0dHJpYnV0ZU5hbWUsIGF0dHJzW2F0dHJpYnV0ZU5hbWVdLCBpc0h0bWwpO1xuICAgICAgICAgICAgICAgICAgaWYgKChwcm9taXNlICYmIHByb21pc2UuaXNGdWxmaWxsZWQoKSkgfHwgKCFwcm9taXNlICYmICghb25seUF0dHJpYnV0ZXMgfHwgZXhwZWN0ZWRBdHRyaWJ1dGVOYW1lcy5pbmRleE9mKGF0dHJpYnV0ZU5hbWUpICE9PSAtMSkpKSB7XG4gICAgICAgICAgICAgICAgICAgIGNhbkNvbnRpbnVlTGluZSA9IHRydWU7XG4gICAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBvdXRwdXRcbiAgICAgICAgICAgICAgICAgICAgICAuc3AoKVxuICAgICAgICAgICAgICAgICAgICAgIC5hbm5vdGF0aW9uQmxvY2soZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHByb21pc2UpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5hcHBlbmQocHJvbWlzZS5yZWFzb24oKS5vdXRwdXQpOyAvLyB2ODogZ2V0RXJyb3JNZXNzYWdlXG4gICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBvbmx5QXR0cmlidXRlcyA9PT0gdHJ1ZVxuICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLmVycm9yKCdzaG91bGQgYmUgcmVtb3ZlZCcpO1xuICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICAgIH0pXG4gICAgICAgICAgICAgICAgICAgICAgLm5sKCk7XG4gICAgICAgICAgICAgICAgICAgIGNhbkNvbnRpbnVlTGluZSA9IGZhbHNlO1xuICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICAgIGV4cGVjdGVkQXR0cmlidXRlTmFtZXMuZm9yRWFjaChmdW5jdGlvbiAoYXR0cmlidXRlTmFtZSkge1xuICAgICAgICAgICAgICAgICAgaWYgKCFzdWJqZWN0Lmhhc0F0dHJpYnV0ZShhdHRyaWJ1dGVOYW1lKSkge1xuICAgICAgICAgICAgICAgICAgICB2YXIgcHJvbWlzZSA9IHByb21pc2VCeUtleS5hdHRyaWJ1dGVzW2F0dHJpYnV0ZU5hbWVdO1xuICAgICAgICAgICAgICAgICAgICBpZiAoIXByb21pc2UgfHwgcHJvbWlzZS5pc1JlamVjdGVkKCkpIHtcbiAgICAgICAgICAgICAgICAgICAgICB2YXIgZXJyID0gcHJvbWlzZSAmJiBwcm9taXNlLnJlYXNvbigpO1xuICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFxuICAgICAgICAgICAgICAgICAgICAgICAgLm5sKClcbiAgICAgICAgICAgICAgICAgICAgICAgIC5zcCgyICsgc3ViamVjdC5ub2RlTmFtZS5sZW5ndGgpXG4gICAgICAgICAgICAgICAgICAgICAgICAuYW5ub3RhdGlvbkJsb2NrKGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpc1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIC5lcnJvcignbWlzc2luZycpXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgLnNwKClcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAucHJpc21BdHRyTmFtZShhdHRyaWJ1dGVOYW1lLCAnaHRtbCcpO1xuICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoZXhwZWN0ZWRWYWx1ZUJ5QXR0cmlidXRlTmFtZVthdHRyaWJ1dGVOYW1lXSAhPT0gdHJ1ZSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXNcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLnNwKClcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLmVycm9yKChlcnIgJiYgZXJyLmxhYmVsKSB8fCAnc2hvdWxkIHNhdGlzZnknKSAvLyB2ODogZXJyLmdldExhYmVsKClcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLnNwKClcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLmFwcGVuZChpbnNwZWN0KGV4cGVjdGVkVmFsdWVCeUF0dHJpYnV0ZU5hbWVbYXR0cmlidXRlTmFtZV0pKTtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgICAgICAgICAgICAgIC5ubCgpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIGNhbkNvbnRpbnVlTGluZSA9IGZhbHNlO1xuICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICAgIG91dHB1dC5wcmlzbVB1bmN0dWF0aW9uKCc+Jyk7XG4gICAgICAgICAgICAgICAgdmFyIGNoaWxkcmVuRXJyb3IgPSBwcm9taXNlQnlLZXkuY2hpbGRyZW4uaXNSZWplY3RlZCgpICYmIHByb21pc2VCeUtleS5jaGlsZHJlbi5yZWFzb24oKTtcbiAgICAgICAgICAgICAgICB2YXIgY2hpbGRyZW5EaWZmID0gY2hpbGRyZW5FcnJvciAmJiBjaGlsZHJlbkVycm9yLmNyZWF0ZURpZmYgJiYgY2hpbGRyZW5FcnJvci5jcmVhdGVEaWZmKG91dHB1dC5jbG9uZSgpLCBkaWZmLCBpbnNwZWN0LCBlcXVhbCk7XG4gICAgICAgICAgICAgICAgaWYgKGNoaWxkcmVuRXJyb3IpIHtcbiAgICAgICAgICAgICAgICAgIG91dHB1dFxuICAgICAgICAgICAgICAgICAgICAubmwoKVxuICAgICAgICAgICAgICAgICAgICAuaW5kZW50TGluZXMoKVxuICAgICAgICAgICAgICAgICAgICAuaSgpLmJsb2NrKGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgICAgICAgICAgICBmb3IgKHZhciBpID0gMCA7IGkgPCBzdWJqZWN0LmNoaWxkTm9kZXMubGVuZ3RoIDsgaSArPSAxKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLmFwcGVuZChpbnNwZWN0KHN1YmplY3QuY2hpbGROb2Rlc1tpXSkpLm5sKCk7XG4gICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgICAgICAgIGlmIChjaGlsZHJlbkVycm9yKSB7XG4gICAgICAgICAgICAgICAgICAgIG91dHB1dC5zcCgpLmFubm90YXRpb25CbG9jayhmdW5jdGlvbiAoKSB7IC8vIHY4OiBjaGlsZHJlbkVycm9yLmdldEVycm9yTWVzc2FnZSgpXG4gICAgICAgICAgICAgICAgICAgICAgdGhpcy5hcHBlbmQoY2hpbGRyZW5FcnJvci5vdXRwdXQpO1xuICAgICAgICAgICAgICAgICAgICAgIGlmIChjaGlsZHJlbkRpZmYgJiYgY2hpbGRyZW5EaWZmLmRpZmYpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMubmwoMikuYXBwZW5kKGNoaWxkcmVuRGlmZi5kaWZmKTtcbiAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgb3V0cHV0Lm5sKCk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgIGZvciAodmFyIGkgPSAwIDsgaSA8IHN1YmplY3QuY2hpbGROb2Rlcy5sZW5ndGggOyBpICs9IDEpIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5hcHBlbmQoaW5zcGVjdChzdWJqZWN0LmNoaWxkTm9kZXNbaV0pKTtcbiAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgb3V0cHV0LmNvZGUoc3RyaW5naWZ5RW5kVGFnKHN1YmplY3QpLCAnaHRtbCcpO1xuICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgICAgcmV0dXJuIHtcbiAgICAgICAgICAgICAgICBpbmxpbmU6IHRydWUsXG4gICAgICAgICAgICAgICAgZGlmZjogb3V0cHV0XG4gICAgICAgICAgICAgIH07XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfSk7XG4gICAgICAgIH0pO1xuICAgICAgfSk7XG4gICAgfSk7XG5cbiAgICBleHBlY3QuYWRkQXNzZXJ0aW9uKCdET01FbGVtZW50JywgJ3RvIFtvbmx5XSBoYXZlIChhdHRyaWJ1dGV8YXR0cmlidXRlcyknLCBmdW5jdGlvbiAoZXhwZWN0LCBzdWJqZWN0LCB2YWx1ZSkge1xuICAgICAgaWYgKHR5cGVvZiB2YWx1ZSA9PT0gJ3N0cmluZycpIHtcbiAgICAgICAgaWYgKGFyZ3VtZW50cy5sZW5ndGggPiAzKSB7XG4gICAgICAgICAgdmFsdWUgPSBBcnJheS5wcm90b3R5cGUuc2xpY2UuY2FsbChhcmd1b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sVHlwZSA9PT0gJ3N0cmluZycpICYmICFzaW1pbGFyKGFjdHVhbFtpXSwgZXhwZWN0ZWRbaV0pKSB8fFxuICAgICAgICAgICAgICAgIChhY3R1YWxUeXBlICE9PSAnb2JqZWN0JyAmJiBhY3R1YWxUeXBlICE9PSAnc3RyaW5nJyAmJiAhZXF1YWwoYWN0dWFsW2ldLCBleHBlY3RlZFtpXSkpXG4gICAgICAgICkge1xuICAgICAgICAgICAgYyArPSAxO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgaWYgKGMgPD0gY29uZmxpY3RzKSB7XG4gICAgICAgIG11dGF0ZWRBcnJheSA9IFtdO1xuICAgICAgICB2YXIgajtcbiAgICAgICAgZm9yIChqID0gMDsgaiA8IE1hdGgubWluKGFjdHVhbC5sZW5ndGgsIGV4cGVjdGVkLmxlbmd0aCk7IGogKz0gMSkge1xuICAgICAgICAgICAgbXV0YXRlZEFycmF5LnB1c2goe1xuICAgICAgICAgICAgICAgIHR5cGU6ICdzaW1pbGFyJyxcbiAgICAgICAgICAgICAgICB2YWx1ZTogYWN0dWFsW2pdLFxuICAgICAgICAgICAgICAgIGV4cGVjdGVkOiBleHBlY3RlZFtqXVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH1cblxuICAgICAgICBpZiAoYWN0dWFsLmxlbmd0aCA8IGV4cGVjdGVkLmxlbmd0aCkge1xuICAgICAgICAgICAgZm9yICg7IGogPCBNYXRoLm1heChhY3R1YWwubGVuZ3RoLCBleHBlY3RlZC5sZW5ndGgpOyBqICs9IDEpIHtcbiAgICAgICAgICAgICAgICBtdXRhdGVkQXJyYXkucHVzaCh7XG4gICAgICAgICAgICAgICAgICAgIHR5cGU6ICdpbnNlcnQnLFxuICAgICAgICAgICAgICAgICAgICB2YWx1ZTogZXhwZWN0ZWRbal1cbiAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGZvciAoOyBqIDwgTWF0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AgICAgICAgICAgIHRva2VuLmZvckVhY2goZnVuY3Rpb24gKHN1YlRva2VuKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBwcmludFRva2VucyhzdWJUb2tlbiwgcGFyZW50U3R5bGUpO1xuICAgICAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiB0b2tlbiA9PT0gJ3N0cmluZycpIHtcbiAgICAgICAgICAgICAgICAgICAgdmFyIHVwcGVyQ2FtZWxDYXNlZFBhcmVudFN0eWxlID0gdXBwZXJDYW1lbENhc2UocGFyZW50U3R5bGUpO1xuICAgICAgICAgICAgICAgICAgICB0b2tlbiA9IHRva2VuLnJlcGxhY2UoLyZsdDsvZywgJzwnKTtcbiAgICAgICAgICAgICAgICAgICAgaWYgKHRoYXRbJ3ByaXNtJyArIGNhcGl0YWxpemVkTGFuZ3VhZ2UgKyB1cHBlckNhbWVsQ2FzZWRQYXJlbnRTdHlsZV0pIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoYXRbJ3ByaXNtJyArIGNhcGl0YWxpemVkTGFuZ3VhZ2UgKyB1cHBlckNhbWVsQ2FzZWRQYXJlbnRTdHlsZV0odG9rZW4pO1xuICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHRoYXRbJ3ByaXNtJyArIHVwcGVyQ2FtZWxDYXNlZFBhcmVudFN0eWxlXSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhhdFsncHJpc20nICsgdXBwZXJDYW1lbENhc2VkUGFyZW50U3R5bGVdKHRva2VuKTtcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoYXQudGV4dCh0b2tlbik7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBwcmludFRva2Vucyh0b2tlbi5jb250ZW50LCB0b2tlbi50eXBlKTtcbiA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gJ3RleHQvY3NzJykpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAgOyBpIDwgZWxlbWVudC5jaGlsZE5vZGVzLmxlbmd0aCA7IGkgKz0gMSkge1xuICAgICAgICAgICAgICAgIGluc3BlY3RlZENoaWxkcmVuLnB1c2goaW5zcGVjdChlbGVtZW50LmNoaWxkTm9kZXNbaV0pKTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICB2YXIgd2lkdGggPSAwO1xuICAgICAgICAgICAgdmFyIG11bHRpcGxlTGluZXMgPSBpbnNwZWN0ZWRDaGlsZHJlbi5zb21lKGZ1bmN0aW9uIChvKSB7XG4gICAgICAgICAgICAgIHZhciBzaXplID0gby5zaXplKCk7XG4gICAgICAgICAgICAgIHdpZHRoICs9IHNpemUud2lkdGg7XG4gICAgICAgICAgICAgIHJldHVybiB3aWR0aCA+IDUwIHx8IG8uaGVpZ2h0ID4gMTtcbiAgICAgICAgICAgIH0pO1xuXG4gICAgICAgICAgICBpZiAobXVsdGlwbGVMaW5lcykge1xuICAgICAgICAgICAgICBvdXRwdXQubmwoKS5pbmRlbnRMaW5lcygpO1xuXG4gICAgICAgICAgICAgIGluc3BlY3RlZENoaWxkcmVuLmZvckVhY2goZnVuY3Rpb24gKGluc3BlY3RlZENoaWxkLCBpbmRleCkge1xuICAgICAgICAgICAgICAgIG91dHB1dC5pKCkuYmxvY2soaW5zcGVjdGVkQ2hpbGQpLm5sKCk7XG4gICAgICAgICAgICAgIH0pO1xuXG4gICAgICAgICAgICAgIG91dHB1dC5vdXRkZW50TGluZXMoKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgIGluc3BlY3RlZENoaWxkcmVuLmZvckVhY2goZnVuY3Rpb24gKGluc3BlY3RlZENoaWxkLCBpbmRleCkge1xuICAgICAgICAgICAgICAgIG91dHB1dC5hcHBlbmQoaW5zcGVjdGVk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gIH1cbiAgICAgICAgfSk7XG4gICAgICB9XG5cbiAgICAgIHJldHVybiBleHBlY3QucHJvbWlzZS5hbGwocHJvbWlzZUJ5S2V5KS5jYXVnaHQoZnVuY3Rpb24gKCkge1xuICAgICAgICByZXR1cm4gZXhwZWN0LnByb21pc2Uuc2V0dGxlKHByb21pc2VCeUtleSkudGhlbihmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgZXhwZWN0LmZhaWwoe1xuICAgICAgICAgICAgZGlmZjogZnVuY3Rpb24gKG91dHB1dCwgZGlmZiwgaW5zcGVjdCwgZXF1YWwpIHtcbiAgICAgICAgICAgICAgb3V0cHV0LmJsb2NrKGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgICAgICB2YXIgb3V0cHV0ID0gdGhpcztcbiAgICAgICAgICAgICAgICBvdXRwdXRcbiAgICAgICAgICAgICAgICAgIC5wcmlzbVB1bmN0dWF0aW9uKCc8JylcbiAgICAgICAgICAgICAgICAgIC5wcmlzbVRhZyhpc0h0bWwgPyBzdWJqZWN0Lm5vZGVOYW1lLnRvTG93ZXJDYXNlKCkgOiBzdWJqZWN0Lm5vZGVOYW1lKTtcbiAgICAgICAgICAgICAgICB2YXIgY2FuQ29udGludWVMaW5lID0gdHJ1ZTtcbiAgICAgICAgICAgICAgICBpZiAocHJvbWlzZUJ5S2V5Lm5hbWUuaXNSZWplY3RlZCgpKSB7XG4gICAgICAgICAgICAgICAgICB2YXIgbmFtZUVycm9yID0gcHJvbWlzZUJ5S2V5Lm5hbWUucmVhc29uKCk7XG4gICAgICAgICAgICAgICAgICBvdXRwdXQuc3AoKS5hbm5vdGF0aW9uQmxvY2soZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICAgICAgICB0aGlzXG4gICAgICAgICAgICAgICAgICAgICAgLmVycm9yKChuYW1lRXJyb3IgJiYgbmFtZUVycm9yLmxhYmVsKSB8fCAnc2hvdWxkIHNhdGlzZnknKSAvLyB2ODogZXJyLmdldExhYmVsKClcbiAgICAgICAgICAgICAgICAgICAgICAuc3AoKVxuICAgICAgICAgICAgICAgICAgICAgIC5hcHBlbmQoaW5zcGVjdCh2YWx1ZS5uYW1lKSk7XG4gICAgICAgICAgICAgICAgICB9KS5ubCgpO1xuICAgICAgICAgICAgICAgICAgY2FuQ29udGludWVMaW5lID0gZmFsc2U7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIE9iamVjdC5rZXlzKGF0dHJzKS5mb3JFYWNoKGZ1bmN0aW9uIChhdHRyaWJ1dGVOYW1lKSB7XG4gICAgICAgICAgICAgICAgICB2YXIgcHJvbWlzZSA9IHByb21pc2VCeUtleS5hdHRyaWJ1dGVzW2F0dHJpYnV0ZU5hbWVdO1xuICAgICAgICAgICAgICAgICAgb3V0cHV0LnNwKGNhbkNvbnRpbnVlTGluZSA/IDEgOiAyICsgc3ViamVjdC5ub2RlTmFtZS5sZW5ndGgpO1xuICAgICAgICAgICAgICAgICAgd3JpdGVBdHRyaWJ1dGVUb01hZ2ljUGVuKG91dHB1dCwgYXR0cmlidXRlTmFtZSwgYXR0cnNbYXR0cmlidXRlTmFtZV0sIGlzSHRtbCk7XG4gICAgICAgICAgICAgICAgICBpZiAoKHByb21pc2UgJiYgcHJvbWlzZS5pc0Z1bGZpbGxlZCgpKSB8fCAoIXByb21pc2UgJiYgKCFvbmx5QXR0cmlidXRlcyB8fCBleHBlY3RlZEF0dHJpYnV0ZU5hbWVzLmluZGV4T2YoYXR0cmlidXRlTmFtZSkgIT09IC0xKSkpIHtcbiAgICAgICAgICAgICAgICAgICAgY2FuQ29udGludWVMaW5lID0gdHJ1ZTtcbiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIG91dHB1dFxuICAgICAgICAgICAgICAgICAgICAgIC5zcCgpXG4gICAgICAgICAgICAgICAgICAgICAgLmFubm90YXRpb25CbG9jayhmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAocHJvbWlzZSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLmFwcGVuZChwcm9taXNlLnJlYXNvbigpLm91dHB1dCk7IC8vIHY4OiBnZXRFcnJvck1lc3NhZ2VcbiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgIC8vIG9ubHlBdHRyaWJ1dGVzID09PSB0cnVlXG4gICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuZXJyb3IoJ3Nob3VsZCBiZSByZW1vdmVkJyk7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgICAgICAgICAgICAubmwoKTtcbiAgICAgICAgICAgICAgICAgICAgY2FuQ29udGludWVMaW5lID0gZmFsc2U7XG4gICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgZXhwZWN0ZWRBdHRyaWJ1dGVOYW1lcy5mb3JFYWNoKGZ1bmN0aW9uIChhdHRyaWJ1dGVOYW1lKSB7XG4gICAgICAgICAgICAgICAgICBpZiAoIXN1YmplY3QuaGFzQXR0cmlidXRlKGF0dHJpYnV0ZU5hbWUpKSB7XG4gICAgICAgICAgICAgICAgICAgIHZhciBwcm9taXNlID0gcHJvbWlzZUJ5S2V5LmF0dHJpYnV0ZXNbYXR0cmlidXRlTmFtZV07XG4gICAgICAgICAgICAgICAgICAgIGlmICghcHJvbWlzZSB8fCBwcm9taXNlLmlzUmVqZWN0ZWQoKSkge1xuICAgICAgICAgICAgICAgICAgICAgIHZhciBlcnIgPSBwcm9taXNlICYmIHByb21pc2UucmVhc29uKCk7XG4gICAgICAgICAgICAgICAgICAgICAgb3V0cHV0XG4gICAgICAgICAgICAgICAgICAgICAgICAubmwoKVxuICAgICAgICAgICAgICAgICAgICAgICAgLnNwKDIgKyBzdWJqZWN0Lm5vZGVOYW1lLmxlbmd0aClcbiAgICAgICAgICAgICAgICAgICAgICAgIC5hbm5vdGF0aW9uQmxvY2soZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgLmVycm9yKCdtaXNzaW5nJylcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAuc3AoKVxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIC5wcmlzbUF0dHJOYW1lKGF0dHJpYnV0ZU5hbWUsICdodG1sJyk7XG4gICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChleHBlY3RlZFZhbHVlQnlBdHRyaWJ1dGVOYW1lW2F0dHJpYnV0ZU5hbWVdICE9PSB0cnVlKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpc1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAuc3AoKVxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAuZXJyb3IoKGVyciAmJiBlcnIubGFiZWwpIHx8ICdzaG91bGQgc2F0aXNmeScpIC8vIHY4OiBlcnIuZ2V0TGFiZWwoKVxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAuc3AoKVxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAuYXBwZW5kKGluc3BlY3QoZXhwZWN0ZWRWYWx1ZUJ5QXR0cmlidXRlTmFtZVthdHRyaWJ1dGVOYW1lXSkpO1xuICAgICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgICAgICB9KVxuICAgICAgICAgICAgICAgICAgICAgICAgLm5sKCk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgY2FuQ29udGludWVMaW5lID0gZmFsc2U7XG4gICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgb3V0cHV0LnByaXNtUHVuY3R1YXRpb24oJz4nKTtcbiAgICAgICAgICAgICAgICB2YXIgY2hpbGRyZW5FcnJvciA9IHByb21pc2VCeUtleS5jaGlsZHJlbi5pc1JlamVjdGVkKCkgJiYgcHJvbWlzZUJ5S2V5LmNoaWxkcmVuLnJlYXNvbigpO1xuICAgICAgICAgICAgICAgIHZhciBjaGlsZHJlbkRpZmYgPSBjaGlsZHJlbkVycm9yICYmIGNoaWxkcmVuRXJyb3IuY3JlYXRlRGlmZiAmJiBjaGlsZHJlbkVycm9yLmNyZWF0ZURpZmYob3V0cHV0LmNsb25lKCksIGRpZmYsIGluc3BlY3QsIGVxdWFsKTtcbiAgICAgICAgICAgICAgICBpZiAoY2hpbGRyZW5FcnJvcikge1xuICAgICAgICAgICAgICAgICAgb3V0cHV0XG4gICAgICAgICAgICAgICAgICAgIC5ubCgpXG4gICAgICAgICAgICAgICAgICAgIC5pbmRlbnRMaW5lcygpXG4gICAgICAgICAgICAgICAgICAgIC5pKCkuYmxvY2soZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICAgICAgICAgIGZvciAodmFyIGkgPSAwIDsgaSA8IHN1YmplY3QuY2hpbGROb2Rlcy5sZW5ndGggOyBpICs9IDEpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuYXBwZW5kKGluc3BlY3Qoc3ViamVjdC5jaGlsZE5vZGVzW2ldKSkubmwoKTtcbiAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICAgICAgaWYgKGNoaWxkcmVuRXJyb3IpIHtcbiAgICAgICAgICAgICAgICAgICAgb3V0cHV0LnNwKCkuYW5ub3RhdGlvbkJsb2NrKGZ1bmN0aW9uICgpIHsgLy8gdjg6IGNoaWxkcmVuRXJyb3IuZ2V0RXJyb3JNZXNzYWdlKClcbiAgICAgICAgICAgICAgICAgICAgICB0aGlzLmFwcGVuZChjaGlsZHJlbkVycm9yLm91dHB1dCk7XG4gICAgICAgICAgICAgICAgICAgICAgaWYgKGNoaWxkcmVuRGlmZiAmJiBjaGlsZHJlbkRpZmYuZGlmZikge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5ubCgyKS5hcHBlbmQoY2hpbGRyZW5EaWZmLmRpZmYpO1xuICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICBvdXRwdXQubmwoKTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAgOyBpIDwgc3ViamVjdC5jaGlsZE5vZGVzLmxlbmd0aCA7IGkgKz0gMSkge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLmFwcGVuZChpbnNwZWN0KHN1YmplY3QuY2hpbGROb2Rlc1tpXSkpO1xuICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBvdXRwdXQuY29kZShzdHJpbmdpZnlFbmRUYWcoc3ViamVjdCksICdodG1sJyk7XG4gICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgICAgIGlubGluZTogdHJ1ZSxcbiAgICAgICAgICAgICAgICBkaWZmOiBvdXRwdXRcbiAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9KTtcbiAgICAgICAgfSk7XG4gICAgICB9KTtcbiAgICB9KTtcblxuICAgIGV4cGVjdC5hZGRBc3NlcnRpb24oJ0RPTUVsZW1lbnQnLCAndG8gW29ubHldIGhhdmUgKGF0dHJpYnV0ZXxhdHRyaWJ1dGVzKScsIGZ1bmN0aW9uIChleHBlY3QsIHN1YmplY3QsIHZhbHVlKSB7XG4gICAgICBpZiAodHlwZW9mIHZhbHVlID09PSAnc3RyaW5nJykge1xuICAgICAgICBpZiAoYXJndW1lbnRzLmxlbmd0aCA+IDMpIHtcbiAgICAgICAgICB2YWx1ZSA9IEFycmF5LnByb3RvdHlwZS5zb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UVudGl0eTogJ3ByaXNtT3BlcmF0b3InLFxuICAgICAgICBwcmlzbVVybDogJ3ByaXNtT3BlcmF0b3InLFxuICAgICAgICBwcmlzbUNzc1N0cmluZzogJ3ByaXNtT3BlcmF0b3InLFxuXG4gICAgICAgIHByaXNtS2V5d29yZDogJyMwN2EnLFxuICAgICAgICBwcmlzbUF0cnVsZTogJ3ByaXNtS2V5d29yZCcsXG4gICAgICAgIHByaXNtQXR0clZhbHVlOiAncHJpc21LZXl3b3JkJyxcblxuICAgICAgICBwcmlzbUZ1bmN0aW9uOiAnI0RENEE2OCcsXG5cbiAgICAgICAgcHJpc21SZWdleDogJyNlOTAnLFxuICAgICAgICBwcmlzbUltcG9ydGFudDogWycjZTkwJywgJ2JvbGQnXVxuICAgIH0sXG4gICAgbGFuZ3VhZ2VNYXBwaW5nID0ge1xuICAgICAgICAndGV4dC9odG1sJzogJ21hcmt1cCcsXG4gICAgICAgICdhcHBsaWNhdGlvbi94bWwnOiAnbWFya3VwJyxcbiAgICAgICAgJ3RleHQveG1sJzogJ21hcmt1cCcsXG4gICAgICAgICdhcHBsaWNhdGlvbi9qc29uJzogJ2phdmFzY3JpcHQnLFxuICAgICAgICAndGV4dC9qYXZhc2NyaXB0JzogJ2phdmFzY3JpcHQnLFxuICAgICAgICAnYXBwbGljYXRpb24vamF2YXNjcmlwdCc6ICdqYXZhc2NyaXB0JyxcbiAgICAgICAgJ3RleHQvY3NzJzogJ2NzcycsXG4gICAgICAgIGh0bWw6ICdtYXJrdXAnLFxuICAgICAgICB4bWw6ICdtYXJrdXAnLFxuICAgICAgICBjOiAnY2xpa2UnLFxuICAgICAgICAnYysrJzogJ2NsaWtlJyxcbiAgICAgICAgJ2NwcCc6ICdjbGlrZScsXG4gICAgICAgICdjIyc6ICdjbGlrZScsXG4gICAgICAgIGphdmE6ICdjbGlrZSdcbiAgICB9O1xuXG5mdW5jdGlvbiB1cHBlckNhbWVsQ2FzZShzdHIpIHtcbiAgICByZXR1cm4gc3Ry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LCBwYXJlbnRTdHlsZSkge1xuICAgICAgICAgICAgICAgIGlmIChBcnJheS5pc0FycmF5KHRva2VuKSkge1xuICAgICAgICAgICAgICAgICAgICB0b2tlbi5mb3JFYWNoKGZ1bmN0aW9uIChzdWJUb2tlbikge1xuICAgICAgICAgICAgICAgICAgICAgICAgcHJpbnRUb2tlbnMoc3ViVG9rZW4sIHBhcmVudFN0eWxlKTtcbiAgICAgICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgdG9rZW4gPT09ICdzdHJpbmcnKSB7XG4gICAgICAgICAgICAgICAgICAgIHZhciB1cHBlckNhbWVsQ2FzZWRQYXJlbnRTdHlsZSA9IHVwcGVyQ2FtZWxDYXNlKHBhcmVudFN0eWxlKTtcbiAgICAgICAgICAgICAgICAgICAgdG9rZW4gPSB0b2tlbi5yZXBsYWNlKC8mbHQ7L2csICc8Jyk7XG4gICAgICAgICAgICAgICAgICAgIGlmICh0aGF0WydwcmlzbScgKyBjYXBpdGFsaXplZExhbmd1YWdlICsgdXBwZXJDYW1lbENhc2VkUGFyZW50U3R5bGVdKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGF0WydwcmlzbScgKyBjYXBpdGFsaXplZExhbmd1YWdlICsgdXBwZXJDYW1lbENhc2VkUGFyZW50U3R5bGVdKHRva2VuKTtcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmICh0aGF0WydwcmlzbScgKyB1cHBlckNhbWVsQ2FzZWRQYXJlbnRTdHlsZV0pIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoYXRbJ3ByaXNtJyArIHVwcGVyQ2FtZWxDYXNlZFBhcmVudFN0eWxlXSh0b2tlbik7XG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGF0LnRleHQodG9rZW4pO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgcHJpbnRUb2tlbnModG9rZW4uY29udGVudCwgdG9rZW4udHlwZSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcHJpbnRUb2tlbnMocHJpc20udG9rZW5pemUoc291cmNlVGV4dCwgcHJpc20ubGFuZ3VhZ2VzW2xhbmd1YWdlXSksICd0ZXh0Jyk7XG4gICAgICAgIH0sIHRydWUpO1xuICAgIH1cbn07XG4iXX0= diff --git a/unexpected-dom.min.js b/unexpected-dom.min.js index 108ed7eb..abf36a64 100644 --- a/unexpected-dom.min.js +++ b/unexpected-dom.min.js @@ -1,3 +1,3 @@ -(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}(g.unexpected||(g.unexpected={})).dom=f()}})(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o"}}function diffNodeLists(actual,expected,output,diff,inspect,equal){var changes=arrayChanges(Array.prototype.slice.call(actual),Array.prototype.slice.call(expected),equal,function(a,b){return a.nodeType===1&&b.nodeType===1&&a.nodeName===b.nodeName});changes.forEach(function(diffItem,index){output.i().block(function(){var type=diffItem.type;if(type==="insert"){this.annotationBlock(function(){this.error("missing ").block(inspect(diffItem.value))})}else if(type==="remove"){this.block(inspect(diffItem.value).sp().error("// should be removed"))}else if(type==="equal"){this.block(inspect(diffItem.value))}else{var valueDiff=diff(diffItem.value,diffItem.expected);if(valueDiff&&valueDiff.inline){this.block(valueDiff.diff)}else if(valueDiff){this.block(inspect(diffItem.value).sp()).annotationBlock(function(){this.shouldEqualError(diffItem.expected,inspect).nl().append(valueDiff.diff)})}else{this.block(inspect(diffItem.value).sp()).annotationBlock(function(){this.shouldEqualError(diffItem.expected,inspect)})}}}).nl(index-1},equal:function(a,b){return a.nodeValue===b.nodeValue},inspect:function(element,depth,output){return output.code(element.nodeName+' "'+element.nodeValue+'"',"prism-string")}});expect.addType({name:"DOMComment",base:"DOMNode",identify:function(obj){return obj&&typeof obj.nodeType==="number"&&obj.nodeType===8},equal:function(a,b){return a.nodeValue===b.nodeValue},inspect:function(element,depth,output){return output.code("","html")},diff:function(actual,expected,output,diff,inspect,equal){var d=diff("","");d.inline=true;return d}});expect.addType({name:"DOMTextNode",base:"DOMNode",identify:function(obj){return obj&&typeof obj.nodeType==="number"&&obj.nodeType===3},equal:function(a,b){return a.nodeValue.trim()===b.nodeValue.trim()},inspect:function(element,depth,output){return output.code(entitify(element.nodeValue.trim()),"html")},diff:function(actual,expected,output,diff,inspect,equal){var d=diff(actual.nodeValue,expected.nodeValue);d.inline=true;return d}});expect.addType({name:"DOMNodeList",base:"array-like",prefix:function(output){return output.text("NodeList[")},suffix:function(output){return output.text("]")},delimiter:function(output){return output.text("delimiter")},identify:function(obj){return obj&&typeof obj.length==="number"&&typeof obj.toString==="function"&&typeof obj.item==="function"&&obj.toString().indexOf("NodeList")!==-1}});expect.addType({name:"HTMLDocType",base:"DOMNode",identify:function(obj){return obj&&typeof obj.nodeType==="number"&&obj.nodeType===10&&"publicId"in obj},inspect:function(doctype,depth,output,inspect){output.code("","html")},equal:function(a,b){return a.toString()===b.toString()},diff:function(actual,expected,output,diff){var d=diff("","");d.inline=true;return d}});expect.addType({name:"DOMDocument",base:"DOMNode",identify:function(obj){return obj&&typeof obj.nodeType==="number"&&obj.nodeType===9&&obj.documentElement&&obj.implementation},inspect:function(document,depth,output,inspect){for(var i=0;i',"xml");for(var i=0;i50||o.height>1});output.code(startTag,"html");if(element.childNodes.length>0){if(multipleLines){output.nl().indentLines();inspectedChildren.forEach(function(inspectedChild,index){output.i().block(inspectedChild).nl()});output.outdentLines()}else{inspectedChildren.forEach(function(inspectedChild,index){output.append(inspectedChild)})}}output.code(stringifyEndTag(element),"html");return output},diffLimit:512,diff:function(actual,expected,output,diff,inspect,equal){var isHtml=actual.ownerDocument.contentType==="text/html";var result={diff:output,inline:true};if(Math.max(actual.length,expected.length)>this.diffLimit){result.diff.jsComment("Diff suppressed due to size > "+this.diffLimit);return result}var emptyElements=actual.childNodes.length===0&&expected.childNodes.length===0;var conflictingElement=actual.nodeName.toLowerCase()!==expected.nodeName.toLowerCase()||!equal(getAttributes(actual),getAttributes(expected));if(conflictingElement){var canContinueLine=true;output.prismPunctuation("<").prismTag(actual.nodeName.toLowerCase());if(actual.nodeName.toLowerCase()!==expected.nodeName.toLowerCase()){output.sp().annotationBlock(function(){this.error("should be").sp().prismTag(expected.nodeName.toLowerCase())}).nl();canContinueLine=false}var actualAttributes=getAttributes(actual);var expectedAttributes=getAttributes(expected);Object.keys(actualAttributes).forEach(function(attributeName){output.sp(canContinueLine?1:2+actual.nodeName.length);writeAttributeToMagicPen(output,attributeName,actualAttributes[attributeName],isHtml);if(attributeName in expectedAttributes){if(actualAttributes[attributeName]===expectedAttributes[attributeName]){canContinueLine=true}else{output.sp().annotationBlock(function(){this.error("should equal").sp().append(inspect(entitify(expectedAttributes[attributeName])))}).nl();canContinueLine=false}delete expectedAttributes[attributeName]}else{output.sp().annotationBlock(function(){this.error("should be removed")}).nl();canContinueLine=false}});Object.keys(expectedAttributes).forEach(function(attributeName){output.sp(canContinueLine?1:2+actual.nodeName.length);output.annotationBlock(function(){this.error("missing").sp();writeAttributeToMagicPen(this,attributeName,expectedAttributes[attributeName],isHtml)}).nl();canContinueLine=false});output.prismPunctuation(">")}else{output.code(stringifyStartTag(actual),"html")}if(!emptyElements){output.nl().indentLines();diffNodeLists(actual.childNodes,expected.childNodes,output,diff,inspect,equal);output.nl().outdentLines()}output.code(stringifyEndTag(actual),"html");return result}});expect.addAssertion("DOMElement","to [only] have (class|classes)",function(expect,subject,value){var flags=this.flags;if(flags.only){return expect(subject,"to have attributes",{"class":function(className){var actualClasses=getClassNamesFromAttributeValue(className);if(typeof value==="string"){value=getClassNamesFromAttributeValue(value)}if(flags.only){return topLevelExpect(actualClasses.sort(),"to equal",value.sort())}else{return topLevelExpect.apply(topLevelExpect,[actualClasses,"to contain"].concat(value))}}})}else{return expect(subject,"to have attributes",{"class":value})}});expect.addAssertion("DOMTextNode","to satisfy",function(expect,subject,value){return expect(subject.nodeValue,"to satisfy",value)});expect.addAssertion("DOMElement","to satisfy",function(expect,subject,value){var isHtml=subject.ownerDocument.contentType==="text/html";if(value&&typeof value==="object"){var unsupportedOptions=Object.keys(value).filter(function(key){return key!=="attributes"&&key!=="name"&&key!=="children"&&key!=="onlyAttributes"});if(unsupportedOptions.length>0){throw new Error("Unsupported option"+(unsupportedOptions.length===1?"":"s")+": "+unsupportedOptions.join(", "))}}var promiseByKey={name:expect.promise(function(){if(value&&typeof value.name!=="undefined"){return topLevelExpect(isHtml?subject.nodeName.toLowerCase():subject.nodeName,"to satisfy",value.name)}}),children:expect.promise(function(){if(typeof value.children!=="undefined"){return topLevelExpect(subject.childNodes,"to satisfy",value.children)}}),attributes:{}};var onlyAttributes=value&&value.onlyAttributes;var attrs=getAttributes(subject);var expectedAttributes=value&&value.attributes;var expectedAttributeNames=[];if(typeof expectedAttributes!=="undefined"){if(typeof expectedAttributes==="string"){expectedAttributes=[expectedAttributes]}var expectedValueByAttributeName={};if(Array.isArray(expectedAttributes)){expectedAttributes.forEach(function(attributeName){expectedValueByAttributeName[attributeName]=true})}else if(expectedAttributes&&typeof expectedAttributes==="object"){expectedValueByAttributeName=expectedAttributes}Object.keys(expectedValueByAttributeName).forEach(function(attributeName){expectedAttributeNames.push(attributeName)});expectedAttributeNames.forEach(function(attributeName){var attributeValue=subject.getAttribute(attributeName);var expectedAttributeValue=expectedValueByAttributeName[attributeName];promiseByKey.attributes[attributeName]=expect.promise(function(){if(attributeName==="class"&&(typeof expectedAttributeValue==="string"||Array.isArray(expectedAttributeValue))){var actualClasses=getClassNamesFromAttributeValue(attributeValue);var expectedClasses=expectedAttributeValue;if(typeof expectedClasses==="string"){expectedClasses=getClassNamesFromAttributeValue(expectedAttributeValue)}if(onlyAttributes){return topLevelExpect(actualClasses.sort(),"to equal",expectedClasses.sort())}else{return topLevelExpect.apply(topLevelExpect,[actualClasses,"to contain"].concat(expectedClasses))}}else if(attributeName==="style"){var expectedStyleObj;if(typeof expectedValueByAttributeName.style==="string"){expectedStyleObj=styleStringToObject(expectedValueByAttributeName.style)}else{expectedStyleObj=expectedValueByAttributeName.style}if(onlyAttributes){return topLevelExpect(attrs.style,"to exhaustively satisfy",expectedStyleObj)}else{return topLevelExpect(attrs.style,"to satisfy",expectedStyleObj)}}else if(expectedAttributeValue===true){expect(subject.hasAttribute(attributeName),"to be true")}else{return topLevelExpect(attributeValue,"to satisfy",expectedAttributeValue)}})});promiseByKey.attributePresence=expect.promise(function(){var attributeNamesExpectedToBeDefined=[];expectedAttributeNames.forEach(function(attributeName){if(typeof expectedValueByAttributeName[attributeName]==="undefined"){expect(attrs,"not to have key",attributeName)}else{attributeNamesExpectedToBeDefined.push(attributeName);expect(attrs,"to have key",attributeName)}});if(onlyAttributes){expect(Object.keys(attrs).sort(),"to equal",attributeNamesExpectedToBeDefined.sort())}})}return expect.promise.all(promiseByKey).caught(function(){return expect.promise.settle(promiseByKey).then(function(){expect.fail({diff:function(output,diff,inspect,equal){output.block(function(){var output=this;output.prismPunctuation("<").prismTag(isHtml?subject.nodeName.toLowerCase():subject.nodeName);var canContinueLine=true;if(promiseByKey.name.isRejected()){var nameError=promiseByKey.name.reason();output.sp().annotationBlock(function(){this.error(nameError&&nameError.label||"should satisfy").sp().append(inspect(value.name))}).nl();canContinueLine=false}Object.keys(attrs).forEach(function(attributeName){var promise=promiseByKey.attributes[attributeName];output.sp(canContinueLine?1:2+subject.nodeName.length);writeAttributeToMagicPen(output,attributeName,attrs[attributeName],isHtml);if(promise&&promise.isFulfilled()||!promise&&(!onlyAttributes||expectedAttributeNames.indexOf(attributeName)!==-1)){canContinueLine=true}else{output.sp().annotationBlock(function(){if(promise){this.append(promise.reason().output)}else{this.error("should be removed")}}).nl();canContinueLine=false}});expectedAttributeNames.forEach(function(attributeName){if(!subject.hasAttribute(attributeName)){var promise=promiseByKey.attributes[attributeName];if(!promise||promise.isRejected()){var err=promise&&promise.reason();output.nl().sp(2+subject.nodeName.length).annotationBlock(function(){this.error("missing").sp().prismAttrName(attributeName,"html");if(expectedValueByAttributeName[attributeName]!==true){this.sp().error(err&&err.label||"should satisfy").sp().append(inspect(expectedValueByAttributeName[attributeName]))}}).nl()}canContinueLine=false}});output.prismPunctuation(">");var childrenError=promiseByKey.children.isRejected()&&promiseByKey.children.reason();var childrenDiff=childrenError&&childrenError.createDiff&&childrenError.createDiff(output.clone(),diff,inspect,equal);if(childrenError){output.nl().indentLines().i().block(function(){for(var i=0;i3){value=Array.prototype.slice.call(arguments,2)}}else if(!value||typeof value!=="object"){throw new Error("to have attributes: Argument must be a string, an array, or an object")}return expect(subject,"to satisfy",{attributes:value,onlyAttributes:this.flags.only})});expect.addAssertion("DOMElement","to have [no] (child|children)",function(expect,subject,query,cmp){if(this.flags.no){this.errorMode="nested";return expect(Array.prototype.slice.call(subject.childNodes),"to be an empty array")}else{var children=Array.prototype.slice.call(subject.querySelectorAll(query));throw children}});expect.addAssertion("DOMElement","to have text",function(expect,subject,value){return expect(subject.textContent,"to satisfy",value)});expect.addAssertion(["DOMDocument","DOMElement"],"queried for [first]",function(expect,subject,value){var queryResult;this.errorMode="nested";if(this.flags.first){queryResult=subject.querySelector(value);if(!queryResult){expect.fail(function(output){output.error("The selector").sp().jsString(value).sp().error("yielded no results")})}}else{queryResult=subject.querySelectorAll(value);if(queryResult.length===0){expect.fail(function(output){output.error("The selector").sp().jsString(value).sp().error("yielded no results")})}}return this.shift(expect,queryResult,1)});expect.addAssertion(["DOMDocument","DOMElement"],"to contain no elements matching",function(expect,subject,value){return expect(subject.querySelectorAll(value),"to satisfy",[])});expect.addAssertion("string","when parsed as (html|HTML)",function(expect,subject){this.errorMode="nested";var htmlDocument;if(typeof DOMParser!=="undefined"){htmlDocument=(new DOMParser).parseFromString(subject,"text/html")}else if(typeof document!=="undefined"&&document.implementation&&document.implementation.createHTMLDocument){htmlDocument=document.implementation.createHTMLDocument("");htmlDocument.open();htmlDocument.write(subject);htmlDocument.close()}else{try{htmlDocument=require("jsdom").jsdom(subject)}catch(err){throw new Error("The assertion `"+this.testDescription+"` was run outside a browser, but could not find the `jsdom` module. Please npm install jsdom to make this work.")}}return this.shift(expect,htmlDocument,0)});expect.addAssertion("string","when parsed as (xml|XML)",function(expect,subject){this.errorMode="nested";var xmlDocument;if(typeof DOMParser!=="undefined"){xmlDocument=(new DOMParser).parseFromString(subject,"text/xml")}else{try{xmlDocument=require("jsdom").jsdom(subject,{parsingMode:"xml"})}catch(err){throw new Error("The assertion `"+this.testDescription+"` was outside a browser (or in a browser without DOMParser), but could not find the `jsdom` module. Please npm install jsdom to make this work.")}}return this.shift(expect,xmlDocument,0)})}}},{"array-changes":2,jsdom:"jsdom","magicpen-prism":5}],2:[function(require,module,exports){var arrayDiff=require("arraydiff");function extend(target){for(var i=1;i0){mutatedArray[mutatedArray.length-1].last=true}similar=similar||function(a,b){return false};var itemsDiff=arrayDiff(actual,expected,function(a,b){return equal(a,b)||similar(a,b)});var removeTable=[];function offsetIndex(index){return index+(removeTable[index-1]||0)}var removes=itemsDiff.filter(function(diffItem){return diffItem.type==="remove"});var removesByIndex={};var removedItems=0;removes.forEach(function(diffItem){var removeIndex=removedItems+diffItem.index;mutatedArray.slice(removeIndex,diffItem.howMany+removeIndex).forEach(function(v){v.type="remove"});removedItems+=diffItem.howMany;removesByIndex[diffItem.index]=removedItems});function updateRemoveTable(){removedItems=0;actual.forEach(function(_,index){removedItems+=removesByIndex[index]||0;removeTable[index]=removedItems})}updateRemoveTable();var moves=itemsDiff.filter(function(diffItem){return diffItem.type==="move"});var movedItems=0;moves.forEach(function(diffItem){var moveFromIndex=offsetIndex(diffItem.from);var removed=mutatedArray.slice(moveFromIndex,diffItem.howMany+moveFromIndex);var added=removed.map(function(v){return extend({},v,{last:false,type:"insert"})});removed.forEach(function(v){v.type="remove"});Array.prototype.splice.apply(mutatedArray,[offsetIndex(diffItem.to),0].concat(added));movedItems+=diffItem.howMany;removesByIndex[diffItem.from]=movedItems;updateRemoveTable()});var inserts=itemsDiff.filter(function(diffItem){return diffItem.type==="insert"});inserts.forEach(function(diffItem){var added=new Array(diffItem.values.length);for(var i=0;i0){mutatedArray[mutatedArray.length-1].last=true}}mutatedArray.forEach(function(diffItem){if(diffItem.type==="similar"&&equal(diffItem.value,diffItem.expected)){diffItem.type="equal"}});return mutatedArray}},{arraydiff:3}],3:[function(require,module,exports){module.exports=arrayDiff;arrayDiff.InsertDiff=InsertDiff;arrayDiff.RemoveDiff=RemoveDiff;arrayDiff.MoveDiff=MoveDiff;function InsertDiff(index,values){this.index=index;this.values=values}InsertDiff.prototype.type="insert";InsertDiff.prototype.toJSON=function(){return{type:this.type,index:this.index,values:this.values}};function RemoveDiff(index,howMany){this.index=index;this.howMany=howMany}RemoveDiff.prototype.type="remove";RemoveDiff.prototype.toJSON=function(){return{type:this.type,index:this.index,howMany:this.howMany}};function MoveDiff(from,to,howMany){this.from=from;this.to=to;this.howMany=howMany}MoveDiff.prototype.type="move";MoveDiff.prototype.toJSON=function(){return{type:this.type,from:this.from,to:this.to,howMany:this.howMany}};function strictEqual(a,b){return a===b}function arrayDiff(before,after,equalFn){if(!equalFn)equalFn=strictEqual;var beforeLength=before.length;var afterLength=after.length;var moves=[];var beforeMarked={};var afterMarked={};for(var beforeIndex=0;beforeIndex=remove.index)move.from-=remove.howMany}}for(i=insertsLength;i--;){var insert=inserts[i];var howMany=insert.values.length;for(j=movesLength;j--;){var move=moves[j];if(move.to>=insert.index)move.to-=howMany}}for(i=movesLength;i-->1;){var move=moves[i];if(move.to===move.from)continue;for(j=i;j--;){var earlier=moves[j];if(earlier.to>=move.to)earlier.to-=move.howMany;if(earlier.to>=move.from)earlier.to+=move.howMany}}var outputMoves=[];for(i=0;i=move.from)later.from-=move.howMany;if(later.from>=move.to)later.from+=move.howMany}}return removes.concat(outputMoves,inserts)}},{}],4:[function(require,module,exports){var self=typeof window!=="undefined"?window:{};var Prism=function(){var lang=/\blang(?:uage)?-(?!\*)(\w+)\b/i;var _=self.Prism={util:{type:function(o){return Object.prototype.toString.call(o).match(/\[object (\w+)\]/)[1]},clone:function(o){var type=_.util.type(o);switch(type){case"Object":var clone={};for(var key in o){if(o.hasOwnProperty(key)){clone[key]=_.util.clone(o[key])}}return clone;case"Array":return o.slice()}return o}},languages:{extend:function(id,redef){var lang=_.util.clone(_.languages[id]);for(var key in redef){lang[key]=redef[key]}return lang},insertBefore:function(inside,before,insert,root){root=root||_.languages;var grammar=root[inside];var ret={};for(var token in grammar){if(grammar.hasOwnProperty(token)){if(token==before){for(var newToken in insert){if(insert.hasOwnProperty(newToken)){ret[newToken]=insert[newToken]}}}ret[token]=grammar[token]}}return root[inside]=ret},DFS:function(o,callback){for(var i in o){callback.call(o,i,o[i]);if(_.util.type(o)==="Object"){_.languages.DFS(o[i],callback)}}}},highlightAll:function(async,callback){var elements=document.querySelectorAll('code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code');for(var i=0,element;element=elements[i++];){_.highlightElement(element,async===true,callback)}},highlightElement:function(element,async,callback){var language,grammar,parent=element;while(parent&&!lang.test(parent.className)){parent=parent.parentNode}if(parent){language=(parent.className.match(lang)||[,""])[1];grammar=_.languages[language]}if(!grammar){return}element.className=element.className.replace(lang,"").replace(/\s+/g," ")+" language-"+language;parent=element.parentNode;if(/pre/i.test(parent.nodeName)){parent.className=parent.className.replace(lang,"").replace(/\s+/g," ")+" language-"+language}var code=element.textContent;if(!code){return}code=code.replace(/&/g,"&").replace(/text.length){break tokenloop}if(str instanceof Token){continue}pattern.lastIndex=0;var match=pattern.exec(str);if(match){if(lookbehind){lookbehindLength=match[1].length}var from=match.index-1+lookbehindLength,match=match[0].slice(lookbehindLength),len=match.length,to=from+len,before=str.slice(0,from+1),after=str.slice(to+1);var args=[i,1];if(before){args.push(before)}var wrapped=new Token(token,inside?_.tokenize(match,inside):match);args.push(wrapped);if(after){args.push(after); +(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}(g.unexpected||(g.unexpected={})).dom=f()}})(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o"}}function diffNodeLists(actual,expected,output,diff,inspect,equal){var changes=arrayChanges(Array.prototype.slice.call(actual),Array.prototype.slice.call(expected),equal,function(a,b){return a.nodeType===1&&b.nodeType===1&&a.nodeName===b.nodeName});changes.forEach(function(diffItem,index){output.i().block(function(){var type=diffItem.type;if(type==="insert"){this.annotationBlock(function(){this.error("missing ").block(inspect(diffItem.value))})}else if(type==="remove"){this.block(inspect(diffItem.value).sp().error("// should be removed"))}else if(type==="equal"){this.block(inspect(diffItem.value))}else{var valueDiff=diff(diffItem.value,diffItem.expected);if(valueDiff&&valueDiff.inline){this.block(valueDiff.diff)}else if(valueDiff){this.block(inspect(diffItem.value).sp()).annotationBlock(function(){this.shouldEqualError(diffItem.expected,inspect).nl().append(valueDiff.diff)})}else{this.block(inspect(diffItem.value).sp()).annotationBlock(function(){this.shouldEqualError(diffItem.expected,inspect)})}}}).nl(index-1},equal:function(a,b){return a.nodeValue===b.nodeValue},inspect:function(element,depth,output){return output.code(element.nodeName+' "'+element.nodeValue+'"',"prism-string")}});expect.addType({name:"DOMComment",base:"DOMNode",identify:function(obj){return obj&&typeof obj.nodeType==="number"&&obj.nodeType===8},equal:function(a,b){return a.nodeValue===b.nodeValue},inspect:function(element,depth,output){return output.code("","html")},diff:function(actual,expected,output,diff,inspect,equal){var d=diff("","");d.inline=true;return d}});expect.addType({name:"DOMTextNode",base:"DOMNode",identify:function(obj){return obj&&typeof obj.nodeType==="number"&&obj.nodeType===3},equal:function(a,b){return a.nodeValue.trim()===b.nodeValue.trim()},inspect:function(element,depth,output){return output.code(entitify(element.nodeValue.trim()),"html")},diff:function(actual,expected,output,diff,inspect,equal){var d=diff(actual.nodeValue,expected.nodeValue);d.inline=true;return d}});expect.addType({name:"DOMNodeList",base:"array-like",prefix:function(output){return output.text("NodeList[")},suffix:function(output){return output.text("]")},delimiter:function(output){return output.text("delimiter")},identify:function(obj){return obj&&typeof obj.length==="number"&&typeof obj.toString==="function"&&typeof obj.item==="function"&&obj.toString().indexOf("NodeList")!==-1}});expect.addType({name:"HTMLDocType",base:"DOMNode",identify:function(obj){return obj&&typeof obj.nodeType==="number"&&obj.nodeType===10&&"publicId"in obj},inspect:function(doctype,depth,output,inspect){output.code("","html")},equal:function(a,b){return a.toString()===b.toString()},diff:function(actual,expected,output,diff){var d=diff("","");d.inline=true;return d}});expect.addType({name:"DOMDocument",base:"DOMNode",identify:function(obj){return obj&&typeof obj.nodeType==="number"&&obj.nodeType===9&&obj.documentElement&&obj.implementation},inspect:function(document,depth,output,inspect){for(var i=0;i',"xml");for(var i=0;i0){if(depth===1){output.text("...")}else{var inspectedChildren=[];if(elementName==="script"){var type=element.getAttribute("type");if(!type||/javascript/.test(type)){type="javascript"}inspectedChildren.push(output.clone().code(element.textContent,type))}else if(elementName==="style"){inspectedChildren.push(output.clone().code(element.textContent,element.getAttribute("type")||"text/css"))}else{for(var i=0;i50||o.height>1});if(multipleLines){output.nl().indentLines();inspectedChildren.forEach(function(inspectedChild,index){output.i().block(inspectedChild).nl()});output.outdentLines()}else{inspectedChildren.forEach(function(inspectedChild,index){output.append(inspectedChild)})}}}output.code(stringifyEndTag(element),"html");return output},diffLimit:512,diff:function(actual,expected,output,diff,inspect,equal){var isHtml=actual.ownerDocument.contentType==="text/html";var result={diff:output,inline:true};if(Math.max(actual.length,expected.length)>this.diffLimit){result.diff.jsComment("Diff suppressed due to size > "+this.diffLimit);return result}var emptyElements=actual.childNodes.length===0&&expected.childNodes.length===0;var conflictingElement=actual.nodeName.toLowerCase()!==expected.nodeName.toLowerCase()||!equal(getAttributes(actual),getAttributes(expected));if(conflictingElement){var canContinueLine=true;output.prismPunctuation("<").prismTag(actual.nodeName.toLowerCase());if(actual.nodeName.toLowerCase()!==expected.nodeName.toLowerCase()){output.sp().annotationBlock(function(){this.error("should be").sp().prismTag(expected.nodeName.toLowerCase())}).nl();canContinueLine=false}var actualAttributes=getAttributes(actual);var expectedAttributes=getAttributes(expected);Object.keys(actualAttributes).forEach(function(attributeName){output.sp(canContinueLine?1:2+actual.nodeName.length);writeAttributeToMagicPen(output,attributeName,actualAttributes[attributeName],isHtml);if(attributeName in expectedAttributes){if(actualAttributes[attributeName]===expectedAttributes[attributeName]){canContinueLine=true}else{output.sp().annotationBlock(function(){this.error("should equal").sp().append(inspect(entitify(expectedAttributes[attributeName])))}).nl();canContinueLine=false}delete expectedAttributes[attributeName]}else{output.sp().annotationBlock(function(){this.error("should be removed")}).nl();canContinueLine=false}});Object.keys(expectedAttributes).forEach(function(attributeName){output.sp(canContinueLine?1:2+actual.nodeName.length);output.annotationBlock(function(){this.error("missing").sp();writeAttributeToMagicPen(this,attributeName,expectedAttributes[attributeName],isHtml)}).nl();canContinueLine=false});output.prismPunctuation(">")}else{output.code(stringifyStartTag(actual),"html")}if(!emptyElements){output.nl().indentLines();diffNodeLists(actual.childNodes,expected.childNodes,output,diff,inspect,equal);output.nl().outdentLines()}output.code(stringifyEndTag(actual),"html");return result}});expect.addAssertion("DOMElement","to [only] have (class|classes)",function(expect,subject,value){var flags=this.flags;if(flags.only){return expect(subject,"to have attributes",{"class":function(className){var actualClasses=getClassNamesFromAttributeValue(className);if(typeof value==="string"){value=getClassNamesFromAttributeValue(value)}if(flags.only){return topLevelExpect(actualClasses.sort(),"to equal",value.sort())}else{return topLevelExpect.apply(topLevelExpect,[actualClasses,"to contain"].concat(value))}}})}else{return expect(subject,"to have attributes",{"class":value})}});expect.addAssertion("DOMTextNode","to satisfy",function(expect,subject,value){return expect(subject.nodeValue,"to satisfy",value)});expect.addAssertion("DOMElement","to satisfy",function(expect,subject,value){var isHtml=subject.ownerDocument.contentType==="text/html";if(value&&typeof value==="object"){var unsupportedOptions=Object.keys(value).filter(function(key){return key!=="attributes"&&key!=="name"&&key!=="children"&&key!=="onlyAttributes"});if(unsupportedOptions.length>0){throw new Error("Unsupported option"+(unsupportedOptions.length===1?"":"s")+": "+unsupportedOptions.join(", "))}}var promiseByKey={name:expect.promise(function(){if(value&&typeof value.name!=="undefined"){return topLevelExpect(isHtml?subject.nodeName.toLowerCase():subject.nodeName,"to satisfy",value.name)}}),children:expect.promise(function(){if(typeof value.children!=="undefined"){return topLevelExpect(subject.childNodes,"to satisfy",value.children)}}),attributes:{}};var onlyAttributes=value&&value.onlyAttributes;var attrs=getAttributes(subject);var expectedAttributes=value&&value.attributes;var expectedAttributeNames=[];if(typeof expectedAttributes!=="undefined"){if(typeof expectedAttributes==="string"){expectedAttributes=[expectedAttributes]}var expectedValueByAttributeName={};if(Array.isArray(expectedAttributes)){expectedAttributes.forEach(function(attributeName){expectedValueByAttributeName[attributeName]=true})}else if(expectedAttributes&&typeof expectedAttributes==="object"){expectedValueByAttributeName=expectedAttributes}Object.keys(expectedValueByAttributeName).forEach(function(attributeName){expectedAttributeNames.push(attributeName)});expectedAttributeNames.forEach(function(attributeName){var attributeValue=subject.getAttribute(attributeName);var expectedAttributeValue=expectedValueByAttributeName[attributeName];promiseByKey.attributes[attributeName]=expect.promise(function(){if(attributeName==="class"&&(typeof expectedAttributeValue==="string"||Array.isArray(expectedAttributeValue))){var actualClasses=getClassNamesFromAttributeValue(attributeValue);var expectedClasses=expectedAttributeValue;if(typeof expectedClasses==="string"){expectedClasses=getClassNamesFromAttributeValue(expectedAttributeValue)}if(onlyAttributes){return topLevelExpect(actualClasses.sort(),"to equal",expectedClasses.sort())}else{return topLevelExpect.apply(topLevelExpect,[actualClasses,"to contain"].concat(expectedClasses))}}else if(attributeName==="style"){var expectedStyleObj;if(typeof expectedValueByAttributeName.style==="string"){expectedStyleObj=styleStringToObject(expectedValueByAttributeName.style)}else{expectedStyleObj=expectedValueByAttributeName.style}if(onlyAttributes){return topLevelExpect(attrs.style,"to exhaustively satisfy",expectedStyleObj)}else{return topLevelExpect(attrs.style,"to satisfy",expectedStyleObj)}}else if(expectedAttributeValue===true){expect(subject.hasAttribute(attributeName),"to be true")}else{return topLevelExpect(attributeValue,"to satisfy",expectedAttributeValue)}})});promiseByKey.attributePresence=expect.promise(function(){var attributeNamesExpectedToBeDefined=[];expectedAttributeNames.forEach(function(attributeName){if(typeof expectedValueByAttributeName[attributeName]==="undefined"){expect(attrs,"not to have key",attributeName)}else{attributeNamesExpectedToBeDefined.push(attributeName);expect(attrs,"to have key",attributeName)}});if(onlyAttributes){expect(Object.keys(attrs).sort(),"to equal",attributeNamesExpectedToBeDefined.sort())}})}return expect.promise.all(promiseByKey).caught(function(){return expect.promise.settle(promiseByKey).then(function(){expect.fail({diff:function(output,diff,inspect,equal){output.block(function(){var output=this;output.prismPunctuation("<").prismTag(isHtml?subject.nodeName.toLowerCase():subject.nodeName);var canContinueLine=true;if(promiseByKey.name.isRejected()){var nameError=promiseByKey.name.reason();output.sp().annotationBlock(function(){this.error(nameError&&nameError.label||"should satisfy").sp().append(inspect(value.name))}).nl();canContinueLine=false}Object.keys(attrs).forEach(function(attributeName){var promise=promiseByKey.attributes[attributeName];output.sp(canContinueLine?1:2+subject.nodeName.length);writeAttributeToMagicPen(output,attributeName,attrs[attributeName],isHtml);if(promise&&promise.isFulfilled()||!promise&&(!onlyAttributes||expectedAttributeNames.indexOf(attributeName)!==-1)){canContinueLine=true}else{output.sp().annotationBlock(function(){if(promise){this.append(promise.reason().output)}else{this.error("should be removed")}}).nl();canContinueLine=false}});expectedAttributeNames.forEach(function(attributeName){if(!subject.hasAttribute(attributeName)){var promise=promiseByKey.attributes[attributeName];if(!promise||promise.isRejected()){var err=promise&&promise.reason();output.nl().sp(2+subject.nodeName.length).annotationBlock(function(){this.error("missing").sp().prismAttrName(attributeName,"html");if(expectedValueByAttributeName[attributeName]!==true){this.sp().error(err&&err.label||"should satisfy").sp().append(inspect(expectedValueByAttributeName[attributeName]))}}).nl()}canContinueLine=false}});output.prismPunctuation(">");var childrenError=promiseByKey.children.isRejected()&&promiseByKey.children.reason();var childrenDiff=childrenError&&childrenError.createDiff&&childrenError.createDiff(output.clone(),diff,inspect,equal);if(childrenError){output.nl().indentLines().i().block(function(){for(var i=0;i3){value=Array.prototype.slice.call(arguments,2)}}else if(!value||typeof value!=="object"){throw new Error("to have attributes: Argument must be a string, an array, or an object")}return expect(subject,"to satisfy",{attributes:value,onlyAttributes:this.flags.only})});expect.addAssertion("DOMElement","to have [no] (child|children)",function(expect,subject,query,cmp){if(this.flags.no){this.errorMode="nested";return expect(Array.prototype.slice.call(subject.childNodes),"to be an empty array")}else{var children=Array.prototype.slice.call(subject.querySelectorAll(query));throw children}});expect.addAssertion("DOMElement","to have text",function(expect,subject,value){return expect(subject.textContent,"to satisfy",value)});expect.addAssertion(["DOMDocument","DOMElement"],"queried for [first]",function(expect,subject,value){var queryResult;this.errorMode="nested";if(this.flags.first){queryResult=subject.querySelector(value);if(!queryResult){expect.fail(function(output){output.error("The selector").sp().jsString(value).sp().error("yielded no results")})}}else{queryResult=subject.querySelectorAll(value);if(queryResult.length===0){expect.fail(function(output){output.error("The selector").sp().jsString(value).sp().error("yielded no results")})}}return this.shift(expect,queryResult,1)});expect.addAssertion(["DOMDocument","DOMElement"],"to contain no elements matching",function(expect,subject,value){return expect(subject.querySelectorAll(value),"to satisfy",[])});expect.addAssertion("string","when parsed as (html|HTML)",function(expect,subject){this.errorMode="nested";var htmlDocument;if(typeof DOMParser!=="undefined"){htmlDocument=(new DOMParser).parseFromString(subject,"text/html")}else if(typeof document!=="undefined"&&document.implementation&&document.implementation.createHTMLDocument){htmlDocument=document.implementation.createHTMLDocument("");htmlDocument.open();htmlDocument.write(subject);htmlDocument.close()}else{try{htmlDocument=require("jsdom").jsdom(subject)}catch(err){throw new Error("The assertion `"+this.testDescription+"` was run outside a browser, but could not find the `jsdom` module. Please npm install jsdom to make this work.")}}return this.shift(expect,htmlDocument,0)});expect.addAssertion("string","when parsed as (xml|XML)",function(expect,subject){this.errorMode="nested";var xmlDocument;if(typeof DOMParser!=="undefined"){xmlDocument=(new DOMParser).parseFromString(subject,"text/xml")}else{try{xmlDocument=require("jsdom").jsdom(subject,{parsingMode:"xml"})}catch(err){throw new Error("The assertion `"+this.testDescription+"` was outside a browser (or in a browser without DOMParser), but could not find the `jsdom` module. Please npm install jsdom to make this work.")}}return this.shift(expect,xmlDocument,0)})}}},{"array-changes":2,jsdom:"jsdom","magicpen-prism":5}],2:[function(require,module,exports){var arrayDiff=require("arraydiff");function extend(target){for(var i=1;i0){mutatedArray[mutatedArray.length-1].last=true}similar=similar||function(a,b){return false};var itemsDiff=arrayDiff([].concat(actual),[].concat(expected),function(a,b){return equal(a,b)||similar(a,b)});var removeTable=[];function offsetIndex(index){return index+(removeTable[index-1]||0)}var removes=itemsDiff.filter(function(diffItem){return diffItem.type==="remove"});var removesByIndex={};var removedItems=0;removes.forEach(function(diffItem){var removeIndex=removedItems+diffItem.index;mutatedArray.slice(removeIndex,diffItem.howMany+removeIndex).forEach(function(v){v.type="remove"});removedItems+=diffItem.howMany;removesByIndex[diffItem.index]=removedItems});function updateRemoveTable(){removedItems=0;Array.prototype.forEach.call(actual,function(_,index){removedItems+=removesByIndex[index]||0;removeTable[index]=removedItems})}updateRemoveTable();var moves=itemsDiff.filter(function(diffItem){return diffItem.type==="move"});var movedItems=0;moves.forEach(function(diffItem){var moveFromIndex=offsetIndex(diffItem.from);var removed=mutatedArray.slice(moveFromIndex,diffItem.howMany+moveFromIndex);var added=removed.map(function(v){return extend({},v,{last:false,type:"insert"})});removed.forEach(function(v){v.type="remove"});Array.prototype.splice.apply(mutatedArray,[offsetIndex(diffItem.to),0].concat(added));movedItems+=diffItem.howMany;removesByIndex[diffItem.from]=movedItems;updateRemoveTable()});var inserts=itemsDiff.filter(function(diffItem){return diffItem.type==="insert"});inserts.forEach(function(diffItem){var added=new Array(diffItem.values.length);for(var i=0;i0){mutatedArray[mutatedArray.length-1].last=true}}mutatedArray.forEach(function(diffItem){if(diffItem.type==="similar"&&equal(diffItem.value,diffItem.expected)){diffItem.type="equal"}});return mutatedArray}},{arraydiff:3}],3:[function(require,module,exports){module.exports=arrayDiff;arrayDiff.InsertDiff=InsertDiff;arrayDiff.RemoveDiff=RemoveDiff;arrayDiff.MoveDiff=MoveDiff;function InsertDiff(index,values){this.index=index;this.values=values}InsertDiff.prototype.type="insert";InsertDiff.prototype.toJSON=function(){return{type:this.type,index:this.index,values:this.values}};function RemoveDiff(index,howMany){this.index=index;this.howMany=howMany}RemoveDiff.prototype.type="remove";RemoveDiff.prototype.toJSON=function(){return{type:this.type,index:this.index,howMany:this.howMany}};function MoveDiff(from,to,howMany){this.from=from;this.to=to;this.howMany=howMany}MoveDiff.prototype.type="move";MoveDiff.prototype.toJSON=function(){return{type:this.type,from:this.from,to:this.to,howMany:this.howMany}};function strictEqual(a,b){return a===b}function arrayDiff(before,after,equalFn){if(!equalFn)equalFn=strictEqual;var beforeLength=before.length;var afterLength=after.length;var moves=[];var beforeMarked={};var afterMarked={};for(var beforeIndex=0;beforeIndex=remove.index)move.from-=remove.howMany}}for(i=insertsLength;i--;){var insert=inserts[i];var howMany=insert.values.length;for(j=movesLength;j--;){var move=moves[j];if(move.to>=insert.index)move.to-=howMany}}for(i=movesLength;i-->1;){var move=moves[i];if(move.to===move.from)continue;for(j=i;j--;){var earlier=moves[j];if(earlier.to>=move.to)earlier.to-=move.howMany;if(earlier.to>=move.from)earlier.to+=move.howMany}}var outputMoves=[];for(i=0;i=move.from)later.from-=move.howMany;if(later.from>=move.to)later.from+=move.howMany}}return removes.concat(outputMoves,inserts)}},{}],4:[function(require,module,exports){var self=typeof window!=="undefined"?window:{};var Prism=function(){var lang=/\blang(?:uage)?-(?!\*)(\w+)\b/i;var _=self.Prism={util:{type:function(o){return Object.prototype.toString.call(o).match(/\[object (\w+)\]/)[1]},clone:function(o){var type=_.util.type(o);switch(type){case"Object":var clone={};for(var key in o){if(o.hasOwnProperty(key)){clone[key]=_.util.clone(o[key])}}return clone;case"Array":return o.slice()}return o}},languages:{extend:function(id,redef){var lang=_.util.clone(_.languages[id]);for(var key in redef){lang[key]=redef[key]}return lang},insertBefore:function(inside,before,insert,root){root=root||_.languages;var grammar=root[inside];var ret={};for(var token in grammar){if(grammar.hasOwnProperty(token)){if(token==before){for(var newToken in insert){if(insert.hasOwnProperty(newToken)){ret[newToken]=insert[newToken]}}}ret[token]=grammar[token]}}return root[inside]=ret},DFS:function(o,callback){for(var i in o){callback.call(o,i,o[i]);if(_.util.type(o)==="Object"){_.languages.DFS(o[i],callback)}}}},highlightAll:function(async,callback){var elements=document.querySelectorAll('code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code');for(var i=0,element;element=elements[i++];){_.highlightElement(element,async===true,callback)}},highlightElement:function(element,async,callback){var language,grammar,parent=element;while(parent&&!lang.test(parent.className)){parent=parent.parentNode}if(parent){language=(parent.className.match(lang)||[,""])[1];grammar=_.languages[language]}if(!grammar){return}element.className=element.className.replace(lang,"").replace(/\s+/g," ")+" language-"+language;parent=element.parentNode;if(/pre/i.test(parent.nodeName)){parent.className=parent.className.replace(lang,"").replace(/\s+/g," ")+" language-"+language}var code=element.textContent;if(!code){return}code=code.replace(/&/g,"&").replace(/text.length){break tokenloop}if(str instanceof Token){continue}pattern.lastIndex=0;var match=pattern.exec(str);if(match){if(lookbehind){lookbehindLength=match[1].length}var from=match.index-1+lookbehindLength,match=match[0].slice(lookbehindLength),len=match.length,to=from+len,before=str.slice(0,from+1),after=str.slice(to+1);var args=[i,1];if(before){args.push(before)}var wrapped=new Token(token,inside?_.tokenize(match,inside):match); -}Array.prototype.splice.apply(strarr,args)}}}return strarr},hooks:{all:{},add:function(name,callback){var hooks=_.hooks.all;hooks[name]=hooks[name]||[];hooks[name].push(callback)},run:function(name,env){var callbacks=_.hooks.all[name];if(!callbacks||!callbacks.length){return}for(var i=0,callback;callback=callbacks[i++];){callback(env)}}}};var Token=_.Token=function(type,content){this.type=type;this.content=content};Token.stringify=function(o,language,parent){if(typeof o=="string"){return o}if(Object.prototype.toString.call(o)=="[object Array]"){return o.map(function(element){return Token.stringify(element,language,o)}).join("")}var env={type:o.type,content:Token.stringify(o.content,language,parent),tag:"span",classes:["token",o.type],attributes:{},language:language,parent:parent};if(env.type=="comment"){env.attributes["spellcheck"]="true"}_.hooks.run("wrap",env);var attributes="";for(var name in env.attributes){attributes+=name+'="'+(env.attributes[name]||"")+'"'}return"<"+env.tag+' class="'+env.classes.join(" ")+'" '+attributes+">"+env.content+""};if(!self.document){if(!self.addEventListener){return self.Prism}self.addEventListener("message",function(evt){var message=JSON.parse(evt.data),lang=message.language,code=message.code;self.postMessage(JSON.stringify(_.tokenize(code,_.languages[lang])));self.close()},false);return self.Prism}var script=document.getElementsByTagName("script");script=script[script.length-1];if(script){_.filename=script.src;if(document.addEventListener&&!script.hasAttribute("data-manual")){document.addEventListener("DOMContentLoaded",_.highlightAll)}}return self.Prism}();if(typeof module!=="undefined"&&module.exports){module.exports=Prism}Prism.languages.markup={comment:/<!--[\w\W]*?-->/g,prolog:/<\?.+?\?>/,doctype:/<!DOCTYPE.+?>/,cdata:/<!\[CDATA\[[\w\W]*?]]>/i,tag:{pattern:/<\/?[\w:-]+\s*(?:\s+[\w:-]+(?:=(?:("|')(\\?[\w\W])*?\1|[^\s'">=]+))?\s*)*\/?>/gi,inside:{tag:{pattern:/^<\/?[\w:-]+/i,inside:{punctuation:/^<\/?/,namespace:/^[\w-]+?:/}},"attr-value":{pattern:/=(?:('|")[\w\W]*?(\1)|[^\s>]+)/gi,inside:{punctuation:/=|>|"/g}},punctuation:/\/?>/g,"attr-name":{pattern:/[\w:-]+/g,inside:{namespace:/^[\w-]+?:/}}}},entity:/&#?[\da-z]{1,8};/gi};Prism.hooks.add("wrap",function(env){if(env.type==="entity"){env.attributes["title"]=env.content.replace(/&/,"&")}});Prism.languages.css={comment:/\/\*[\w\W]*?\*\//g,atrule:{pattern:/@[\w-]+?.*?(;|(?=\s*{))/gi,inside:{punctuation:/[;:]/g}},url:/url\((["']?).*?\1\)/gi,selector:/[^\{\}\s][^\{\};]*(?=\s*\{)/g,property:/(\b|\B)[\w-]+(?=\s*:)/gi,string:/("|')(\\?.)*?\1/g,important:/\B!important\b/gi,ignore:/&(lt|gt|amp);/gi,punctuation:/[\{\};:]/g};if(Prism.languages.markup){Prism.languages.insertBefore("markup","tag",{style:{pattern:/(<|<)style[\w\W]*?(>|>)[\w\W]*?(<|<)\/style(>|>)/gi,inside:{tag:{pattern:/(<|<)style[\w\W]*?(>|>)|(<|<)\/style(>|>)/gi,inside:Prism.languages.markup.tag.inside},rest:Prism.languages.css}}})}Prism.languages.clike={comment:{pattern:/(^|[^\\])(\/\*[\w\W]*?\*\/|(^|[^:])\/\/.*?(\r?\n|$))/g,lookbehind:true},string:/("|')(\\?.)*?\1/g,"class-name":{pattern:/((?:(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[a-z0-9_\.\\]+/gi,lookbehind:true,inside:{punctuation:/(\.|\\)/}},keyword:/\b(if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/g,"boolean":/\b(true|false)\b/g,"function":{pattern:/[a-z0-9_]+\(/gi,inside:{punctuation:/\(/}},number:/\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?)\b/g,operator:/[-+]{1,2}|!|<=?|>=?|={1,3}|(&){1,2}|\|?\||\?|\*|\/|\~|\^|\%/g,ignore:/&(lt|gt|amp);/gi,punctuation:/[{}[\];(),.:]/g};Prism.languages.javascript=Prism.languages.extend("clike",{keyword:/\b(var|let|if|else|while|do|for|return|in|instanceof|function|get|set|new|with|typeof|try|throw|catch|finally|null|break|continue|this)\b/g,number:/\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?|NaN|-?Infinity)\b/g});Prism.languages.insertBefore("javascript","keyword",{regex:{pattern:/(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/g,lookbehind:true}});if(Prism.languages.markup){Prism.languages.insertBefore("markup","tag",{script:{pattern:/(<|<)script[\w\W]*?(>|>)[\w\W]*?(<|<)\/script(>|>)/gi,inside:{tag:{pattern:/(<|<)script[\w\W]*?(>|>)|(<|<)\/script(>|>)/gi,inside:Prism.languages.markup.tag.inside},rest:Prism.languages.javascript}}})}(function(){if(!self.Prism||!self.document||!document.querySelector){return}var Extensions={js:"javascript",html:"markup",svg:"markup"};Array.prototype.slice.call(document.querySelectorAll("pre[data-src]")).forEach(function(pre){var src=pre.getAttribute("data-src");var extension=(src.match(/\.(\w+)$/)||[,""])[1];var language=Extensions[extension]||extension;var code=document.createElement("code");code.className="language-"+language;pre.textContent="";code.textContent="Loading…";pre.appendChild(code);var xhr=new XMLHttpRequest;xhr.open("GET",src,true);xhr.onreadystatechange=function(){if(xhr.readyState==4){if(xhr.status<400&&xhr.responseText){code.textContent=xhr.responseText;Prism.highlightElement(code)}else if(xhr.status>=400){code.textContent="✖ Error "+xhr.status+" while fetching file: "+xhr.statusText}else{code.textContent="✖ Error: File does not exist or is empty"}}};xhr.send(null)})})()},{}],5:[function(require,module,exports){var prism=require("../3rdparty/prism"),defaultTheme={prismComment:"#708090",prismProlog:"prismComment",prismDoctype:"prismComment",prismCdata:"prismComment",prismPunctuation:"#999",prismSymbol:"#905",prismProperty:"prismSymbol",prismTag:"prismSymbol",prismBoolean:"prismSymbol",prismNumber:"prismSymbol",prismConstant:"prismSymbol",prismDeleted:"prismSymbol",prismString:"#690",prismSelector:"prismString",prismAttrName:"prismString",prismChar:"prismString",prismBuiltin:"prismString",prismInserted:"prismString",prismOperator:"#a67f59",prismVariable:"prismOperator",prismEntity:"prismOperator",prismUrl:"prismOperator",prismCssString:"prismOperator",prismKeyword:"#07a",prismAtrule:"prismKeyword",prismAttrValue:"prismKeyword",prismFunction:"#DD4A68",prismRegex:"#e90",prismImportant:["#e90","bold"]},languageMapping={"text/html":"markup","application/xml":"markup","text/xml":"markup","application/json":"javascript","text/javascript":"javascript","application/javascript":"javascript","text/css":"css",html:"markup",xml:"markup",c:"clike","c++":"clike",cpp:"clike","c#":"clike",java:"clike"};function upperCamelCase(str){return str.replace(/(?:^|-)([a-z])/g,function($0,ch){return ch.toUpperCase()})}module.exports={name:"magicpen-prism",installInto:function(magicPen){magicPen.installTheme(defaultTheme);magicPen.addStyle("code",function(sourceText,language){if(language in languageMapping){language=languageMapping[language]}else if(/\+xml\b/.test(language)){language="markup"}if(!(language in prism.languages)){return this.text(sourceText)}sourceText=sourceText.replace(/"+env.content+""};if(!self.document){if(!self.addEventListener){return self.Prism}self.addEventListener("message",function(evt){var message=JSON.parse(evt.data),lang=message.language,code=message.code;self.postMessage(JSON.stringify(_.tokenize(code,_.languages[lang])));self.close()},false);return self.Prism}var script=document.getElementsByTagName("script");script=script[script.length-1];if(script){_.filename=script.src;if(document.addEventListener&&!script.hasAttribute("data-manual")){document.addEventListener("DOMContentLoaded",_.highlightAll)}}return self.Prism}();if(typeof module!=="undefined"&&module.exports){module.exports=Prism}Prism.languages.markup={comment:/<!--[\w\W]*?-->/g,prolog:/<\?.+?\?>/,doctype:/<!DOCTYPE.+?>/,cdata:/<!\[CDATA\[[\w\W]*?]]>/i,tag:{pattern:/<\/?[\w:-]+\s*(?:\s+[\w:-]+(?:=(?:("|')(\\?[\w\W])*?\1|[^\s'">=]+))?\s*)*\/?>/gi,inside:{tag:{pattern:/^<\/?[\w:-]+/i,inside:{punctuation:/^<\/?/,namespace:/^[\w-]+?:/}},"attr-value":{pattern:/=(?:('|")[\w\W]*?(\1)|[^\s>]+)/gi,inside:{punctuation:/=|>|"/g}},punctuation:/\/?>/g,"attr-name":{pattern:/[\w:-]+/g,inside:{namespace:/^[\w-]+?:/}}}},entity:/&#?[\da-z]{1,8};/gi};Prism.hooks.add("wrap",function(env){if(env.type==="entity"){env.attributes["title"]=env.content.replace(/&/,"&")}});Prism.languages.css={comment:/\/\*[\w\W]*?\*\//g,atrule:{pattern:/@[\w-]+?.*?(;|(?=\s*{))/gi,inside:{punctuation:/[;:]/g}},url:/url\((["']?).*?\1\)/gi,selector:/[^\{\}\s][^\{\};]*(?=\s*\{)/g,property:/(\b|\B)[\w-]+(?=\s*:)/gi,string:/("|')(\\?.)*?\1/g,important:/\B!important\b/gi,ignore:/&(lt|gt|amp);/gi,punctuation:/[\{\};:]/g};if(Prism.languages.markup){Prism.languages.insertBefore("markup","tag",{style:{pattern:/(<|<)style[\w\W]*?(>|>)[\w\W]*?(<|<)\/style(>|>)/gi,inside:{tag:{pattern:/(<|<)style[\w\W]*?(>|>)|(<|<)\/style(>|>)/gi,inside:Prism.languages.markup.tag.inside},rest:Prism.languages.css}}})}Prism.languages.clike={comment:{pattern:/(^|[^\\])(\/\*[\w\W]*?\*\/|(^|[^:])\/\/.*?(\r?\n|$))/g,lookbehind:true},string:/("|')(\\?.)*?\1/g,"class-name":{pattern:/((?:(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[a-z0-9_\.\\]+/gi,lookbehind:true,inside:{punctuation:/(\.|\\)/}},keyword:/\b(if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/g,"boolean":/\b(true|false)\b/g,"function":{pattern:/[a-z0-9_]+\(/gi,inside:{punctuation:/\(/}},number:/\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?)\b/g,operator:/[-+]{1,2}|!|<=?|>=?|={1,3}|(&){1,2}|\|?\||\?|\*|\/|\~|\^|\%/g,ignore:/&(lt|gt|amp);/gi,punctuation:/[{}[\];(),.:]/g};Prism.languages.javascript=Prism.languages.extend("clike",{keyword:/\b(var|let|if|else|while|do|for|return|in|instanceof|function|get|set|new|with|typeof|try|throw|catch|finally|null|break|continue|this)\b/g,number:/\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?|NaN|-?Infinity)\b/g});Prism.languages.insertBefore("javascript","keyword",{regex:{pattern:/(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/g,lookbehind:true}});if(Prism.languages.markup){Prism.languages.insertBefore("markup","tag",{script:{pattern:/(<|<)script[\w\W]*?(>|>)[\w\W]*?(<|<)\/script(>|>)/gi,inside:{tag:{pattern:/(<|<)script[\w\W]*?(>|>)|(<|<)\/script(>|>)/gi,inside:Prism.languages.markup.tag.inside},rest:Prism.languages.javascript}}})}(function(){if(!self.Prism||!self.document||!document.querySelector){return}var Extensions={js:"javascript",html:"markup",svg:"markup"};Array.prototype.slice.call(document.querySelectorAll("pre[data-src]")).forEach(function(pre){var src=pre.getAttribute("data-src");var extension=(src.match(/\.(\w+)$/)||[,""])[1];var language=Extensions[extension]||extension;var code=document.createElement("code");code.className="language-"+language;pre.textContent="";code.textContent="Loading…";pre.appendChild(code);var xhr=new XMLHttpRequest;xhr.open("GET",src,true);xhr.onreadystatechange=function(){if(xhr.readyState==4){if(xhr.status<400&&xhr.responseText){code.textContent=xhr.responseText;Prism.highlightElement(code)}else if(xhr.status>=400){code.textContent="✖ Error "+xhr.status+" while fetching file: "+xhr.statusText}else{code.textContent="✖ Error: File does not exist or is empty"}}};xhr.send(null)})})()},{}],5:[function(require,module,exports){var prism=require("../3rdparty/prism"),defaultTheme={prismComment:"#708090",prismProlog:"prismComment",prismDoctype:"prismComment",prismCdata:"prismComment",prismPunctuation:"#999",prismSymbol:"#905",prismProperty:"prismSymbol",prismTag:"prismSymbol",prismBoolean:"prismSymbol",prismNumber:"prismSymbol",prismConstant:"prismSymbol",prismDeleted:"prismSymbol",prismString:"#690",prismSelector:"prismString",prismAttrName:"prismString",prismChar:"prismString",prismBuiltin:"prismString",prismInserted:"prismString",prismOperator:"#a67f59",prismVariable:"prismOperator",prismEntity:"prismOperator",prismUrl:"prismOperator",prismCssString:"prismOperator",prismKeyword:"#07a",prismAtrule:"prismKeyword",prismAttrValue:"prismKeyword",prismFunction:"#DD4A68",prismRegex:"#e90",prismImportant:["#e90","bold"]},languageMapping={"text/html":"markup","application/xml":"markup","text/xml":"markup","application/json":"javascript","text/javascript":"javascript","application/javascript":"javascript","text/css":"css",html:"markup",xml:"markup",c:"clike","c++":"clike",cpp:"clike","c#":"clike",java:"clike"};function upperCamelCase(str){return str.replace(/(?:^|-)([a-z])/g,function($0,ch){return ch.toUpperCase()})}module.exports={name:"magicpen-prism",installInto:function(magicPen){magicPen.installTheme(defaultTheme);magicPen.addStyle("code",function(sourceText,language){if(language in languageMapping){language=languageMapping[language]}else if(/\+xml\b/.test(language)){language="markup"}if(!(language in prism.languages)){return this.text(sourceText)}sourceText=sourceText.replace(/