From a3c5a6f1ae071efce9591f8753e4b25a0929e52e Mon Sep 17 00:00:00 2001 From: Tanner Linsley Date: Mon, 28 Mar 2016 23:28:40 -0500 Subject: [PATCH] Default null value option for changeMap --- package.json | 2 +- src/postAggregation.js | 13 +++++++------ universe.js | 15 ++++++++------- universe.min.js | 4 ++-- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 94e2c03..b9ae755 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "universe", - "version": "0.6.1", + "version": "0.6.2", "description": "The fastest way to query and explore multivariate datasets", "main": "src/universe.js", "directories": { diff --git a/src/postAggregation.js b/src/postAggregation.js index 2fd8de9..bf6c1e6 100644 --- a/src/postAggregation.js +++ b/src/postAggregation.js @@ -80,7 +80,8 @@ module.exports = function(service) { query.data = obj } - function changeMap(query, parent, aggObj) { + function changeMap(query, parent, aggObj, defaultNull) { + defaultNull = _.isUndefined(defaultNull) ? 0 : defaultNull query.data = cloneIfLocked(parent) _.recurseObject(aggObj, function(val, key, path) { @@ -96,14 +97,14 @@ module.exports = function(service) { fromStartPath.push(key + 'ChangeFromStart') fromEndPath.push(key + 'ChangeFromEnd') - var start = _.get(query.data[0].value, path) - var end = _.get(query.data[query.data.length - 1].value, path) + var start = _.get(query.data[0].value, path, defaultNull) + var end = _.get(query.data[query.data.length - 1].value, path, defaultNull) _.forEach(query.data, function(record, i) { var previous = query.data[i - 1] || query.data[0] - _.set(query.data[i].value, changePath, _.get(record.value, path) - (previous ? _.get(previous.value, path) : 0)) - _.set(query.data[i].value, fromStartPath, _.get(record.value, path) - start) - _.set(query.data[i].value, fromEndPath, _.get(record.value, path) - end) + _.set(query.data[i].value, changePath, _.get(record.value, path, defaultNull) - (previous ? _.get(previous.value, path, defaultNull) : defaultNull)) + _.set(query.data[i].value, fromStartPath, _.get(record.value, path, defaultNull) - start) + _.set(query.data[i].value, fromEndPath, _.get(record.value, path, defaultNull) - end) }) }) } diff --git a/universe.js b/universe.js index cdf9ee3..9f051f8 100644 --- a/universe.js +++ b/universe.js @@ -6887,7 +6887,8 @@ module.exports = function(service) { query.data = obj } - function changeMap(query, parent, aggObj) { + function changeMap(query, parent, aggObj, defaultNull) { + defaultNull = _.isUndefined(defaultNull) ? 0 : defaultNull query.data = cloneIfLocked(parent) _.recurseObject(aggObj, function(val, key, path) { @@ -6903,14 +6904,14 @@ module.exports = function(service) { fromStartPath.push(key + 'ChangeFromStart') fromEndPath.push(key + 'ChangeFromEnd') - var start = _.get(query.data[0].value, path) - var end = _.get(query.data[query.data.length - 1].value, path) + var start = _.get(query.data[0].value, path, defaultNull) + var end = _.get(query.data[query.data.length - 1].value, path, defaultNull) _.forEach(query.data, function(record, i) { var previous = query.data[i - 1] || query.data[0] - _.set(query.data[i].value, changePath, _.get(record.value, path) - (previous ? _.get(previous.value, path) : 0)) - _.set(query.data[i].value, fromStartPath, _.get(record.value, path) - start) - _.set(query.data[i].value, fromEndPath, _.get(record.value, path) - end) + _.set(query.data[i].value, changePath, _.get(record.value, path, defaultNull) - (previous ? _.get(previous.value, path, defaultNull) : defaultNull)) + _.set(query.data[i].value, fromStartPath, _.get(record.value, path, defaultNull) - start) + _.set(query.data[i].value, fromEndPath, _.get(record.value, path, defaultNull) - end) }) }) } @@ -7455,4 +7456,4 @@ function universe(data, options) { },{"./clear":32,"./column":33,"./crossfilter":34,"./filters":37,"./lodash":38,"./q.serial":40,"./query":41,"q":4}]},{},[44])(44) }); -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJub2RlX21vZHVsZXMvY3Jvc3NmaWx0ZXIyL2Nyb3NzZmlsdGVyLmpzIiwibm9kZV9tb2R1bGVzL2Nyb3NzZmlsdGVyMi9pbmRleC5qcyIsIm5vZGVfbW9kdWxlcy9wcm9jZXNzL2Jyb3dzZXIuanMiLCJub2RlX21vZHVs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5wYXJ0aXRpb25lZCB8ID4gcGl2b3QgIHwgXVxuICAgICAgLy8gIF4gICAgICAgICAgICAgXiAgICAgICAgICBeICAgICAgICAgICAgIF4gICAgICAgICAgICBeXG4gICAgICAvLyBsZWZ0ICAgICAgICAgbGVzcyAgICAgICAgIGsgICAgICAgICAgIGdyZWF0ICAgICAgICAgcmlnaHRcbiAgICAgIC8vXG4gICAgICAvLyBhW2xlZnRdIGFuZCBhW3JpZ2h0XSBhcmUgdW5kZWZpbmVkIGFuZCBhcmUgZmlsbGVkIGFmdGVyIHRoZVxuICAgICAgLy8gcGFydGl0aW9uaW5nLlxuICAgICAgLy9cbiAgICAgIC8vIEludmFyaWFudHM6XG4gICAgICAvLyAgIDEpIGZvciB4IGluIF1sZWZ0LCBsZXNzWyA6IHggPCBwaXZvdC5cbiAgICAgIC8vICAgMikgZm9yIHggaW4gW2xlc3MsIGtbIDogeCA9PSBwaXZvdC5cbiAgICAgIC8vICAgMykgZm9yIHggaW4gXWdyZWF0LCByaWdodFsgOiB4ID4gcGl2b3QuXG4gICAgICBmb3IgKHZhciBrID0gbGVzczsgayA8PSBncmVhdDsgKytrKSB7XG4gICAgICAgIHZhciBlayA9IGFba10sIHhrID0gZihlayk7XG4gICAgICAgIGlmICh4ayA8IHBpdm90VmFsdWUxKSB7XG4gICAgICAgICAgaWYgKGsgIT09IGxlc3MpIHtcbiAgICAgICAgICAgIGFba10gPSBhW2xlc3NdO1xuICAgICAgICAgICAgYVtsZXNzXSA9IGVrO1xuICAgICAgICAgIH1cbiAgICAgICAgICArK2xlc3M7XG4gICAgICAgIH0gZWxzZSBpZiAoeGsgPiBwaXZvdFZhbHVlMSkge1xuXG4gICAgICAgICAgLy8gRmluZCB0aGUgZmlyc3QgZWxlbWVudCA8PSBwaXZvdCBpbiB0aGUgcmFuZ2UgW2sgLSAxLCBncmVhdF0gYW5kXG4gICAgICAgICAgLy8gcHV0IFs6ZWs6XSB0aGVyZS4gV2Uga25vdyB0aGF0IHN1Y2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AgICAgICAgICAgICBhW2dyZWF0LS1dID0gZWs7XG4gICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgYVtrXSA9IGFbZ3JlYXRdO1xuICAgICAgICAgICAgICBhW2dyZWF0LS1dID0gZWs7XG4gICAgICAgICAgICAgIC8vIE5vdGU6IGlmIGdyZWF0IDwgayB0aGVuIHdlIHdpbGwgZXhpdCB0aGUgb3V0ZXIgbG9vcCBhbmQgZml4XG4gICAgICAgICAgICAgIC8vIGludmFyaWFudCAyICh3aGljaCB3ZSBqdXN0IHZpb2xhdGVkKS5cbiAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG4gICAgfSBlbHNlIHtcblxuICAgICAgLy8gV2UgcGFydGl0aW9uIHRoZSBsaXN0IGludG8gdGhyZWUgcGFydHM6XG4gICAgICAvLyAgMS4gPCBwaXZvdDFcbiAgICAgIC8vICAyLiA+PSBwaXZvdDEgJiYgPD0gcGl2b3QyXG4gICAgICAvLyAgMy4gPiBwaXZvdDJcbiAgICAgIC8vXG4gICAgICAvLyBEdXJpbmcgdGhlIGxvb3Agd2UgaGF2ZTpcbiAgICAgIC8vIFsgfCA8IHBpdm90MSB8ID49IHBpdm90MSAmJiA8PSBwaXZvdDIgfCB1bnBhcnRpdGlvbmVkICB8ID4gcGl2b3QyICB8IF1cbiAgICAgIC8vICBeICAgICAgICAgICAgXiAgICAgICAgICAgICAgICAgICAgICAgIF4gICAgICAgICAgICAgIF4gICAgICAgICAgICAgXlxuICAgICAgLy8gbGVmdCAgICAgICAgIGxlc3MgICAgICAgICAgICAgICAgICAgICBrICAgICAgICAgICAgICBncmVhdCAgICAgICAgcmlnaHRcbiAgICAgIC8vXG4gICAgICAvLyBhW2xlZnRdIGFuZCBhW3JpZ2h0XSBhcmUgdW5kZWZpbmVkIGFuZCBhcmUgZmlsbGVkIGFmdGVyIHRoZVxuICAgICAgLy8gcGFydGl0aW9uaW5nLlxuICAgICAgLy9cbiAgICAgIC8vIEludmFyaWFudHM6XG4gICAgICAvLyAgIDEuIGZvciB4IGluIF1sZWZ0LCBsZXNzWyA6IHggPCBwaXZvdDFcbiAgICAgIC8vICAgMi4gZm9yIHggaW4gW2xlc3MsIGtbIDogcGl2b3QxIDw9IHggJiYgeCA8PSBwaXZvdDJcbiAgICAgIC8vICAgMy4gZm9yIHggaW4gXWdyZWF0LCByaWdodFsgOiB4ID4gcGl2b3QyXG4gICAgICBmb3IgKHZhciBrID0gbGVzczsgayA8PSBncmVhdDsgaysrKSB7XG4gICAgICAgIHZhciBlayA9IGFba10sIHhrID0gZihlayk7XG4gICAgICAgIGlmICh4ayA8IHBpdm90VmFsdWUxKSB7XG4gICAgICAgICAgaWYgKGsgIT09IGxlc3MpIHtcbiAgICAgICAgICAgIGFba10gPSBhW2xlc3NdO1xuICAgICAgICAgICAgYVtsZXNzXSA9IGVrO1xuICAgICAgICAgIH1cbiAgICAgICAgICArK2xlc3M7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgaWYgKHhrID4gcGl2b3RWYWx1ZTIpIHtcbiAgICAgICAgICAgIHdoaWxlICh0cnVlKSB7XG4gICAgICAgICAgICAgIHZhciBncmVhdFZhbHVlID0gZihhW2dyZWF0XSk7XG4gICAgICAgICAgICAgIGlmIChncmVhdFZhbHVlID4gcGl2b3RWYWx1ZTIpIHtcbiAgICAgICAgICAgICAgICBncmVhdC0tO1xuICAgICAgICAgICAgICAgIGlmIChncmVhdCA8IGspIGJyZWFrO1xuICAgICAgICAgICAgICAgIC8vIFRoaXMgaXMgdGhlIG9ubHkgbG9jYXRpb24gaW5zaWRlIHRoZSBsb29wIHdoZXJlIGEgbmV3XG4gICAgICAgICAgICAgICAgLy8gaXRlcmF0aW9uIGlzIHN0YXJ0ZWQuXG4gICAgICAgICAgICAgICAgY29udGludWU7XG4gICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgLy8gYVtncmVhdF0gPD0gcGl2b3QyLlxuICAgICAgICAgICAgICAgIGlmIChncmVhdFZhbHVlIDwgcGl2b3RWYWx1ZTEpIHtcbiAgICAgICAgICAgICAgICAgIC8vIFRyaXBsZSBleGNoYW5nZS5cbiAgICAgICAgICAgICAgICAgIGFba10gPSBhW2xlc3NdO1xuICAgICAgICAgICAgICAgICAgYVtsZXNzKytdID0gYVtncmVhdF07XG4gICAgICAgICAgICAgICAgICBhW2dyZWF0LS1dID0gZWs7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgIC8vIGFbZ3JlYXRdID49IHBpdm90MS5cbiAgICAgICAgICAgICAgICAgIGFba10gPSBhW2dyZWF0XTtcbiAgICAgICAgICAgICAgICAgIGFbZ3JlYXQtLV0gPSBlaztcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9XG5cbiAgICAvLyBNb3ZlIHBpdm90cyBpbnRvIHRoZWlyIGZpbmFsIHBvc2l0aW9ucy5cbiAgICAvLyBXZSBzaHJ1bmsgdGhlIGxpc3QgZnJvbSBib3RoIHNpZGVzIChhW2xlZnRdIGFuZCBhW3JpZ2h0XSBoYXZlXG4gICAgLy8gbWVhbmluZ2xlc3MgdmFsdWVzIGluIHRoZW0pIGFuZCBub3cgd2UgbW92ZSBlbGVtZW50cyBmcm9tIHRoZSBmaXJzdFxuICAgIC8vIGFuZCB0aGlyZCBwYXJ0aXRpb24gaW50byB0aGVzZSBsb2NhdGlvbnMgc28gdGhhdCB3ZSBjYW4gc3RvcmUgdGhlXG4gICAgLy8gcGl2b3RzLlxuICAgIGFbbG9dID0gYVtsZXNzIC0gMV07XG4gICAgYVtsZXNzIC0gMV0gPSBwaXZvdDE7XG4gICAgYVtoaSAtID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pbiBbbGVzcywga1sgOiBwaXZvdDEgPCB4ICYmIHggPCBwaXZvdDJcbiAgICAgIC8vICAgMy4gZm9yIHggaW4gXWdyZWF0LCAqIF0gOiB4ID09IHBpdm90MlxuICAgICAgZm9yICh2YXIgayA9IGxlc3M7IGsgPD0gZ3JlYXQ7IGsrKykge1xuICAgICAgICB2YXIgZWsgPSBhW2tdLCB4ayA9IGYoZWspO1xuICAgICAgICBpZiAoeGsgPD0gcGl2b3RWYWx1ZTEgJiYgeGsgPj0gcGl2b3RWYWx1ZTEpIHtcbiAgICAgICAgICBpZiAoayAhPT0gbGVzcykge1xuICAgICAgICAgICAgYVtrXSA9IGFbbGVzc107XG4gICAgICAgICAgICBhW2xlc3NdID0gZWs7XG4gICAgICAgICAgfVxuICAgICAgICAgIGxlc3MrKztcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICBpZiAoeGsgPD0gcGl2b3RWYWx1ZTIgJiYgeGsgPj0gcGl2b3RWYWx1ZTIpIHtcbiAgICAgICAgICAgIHdoaWxlICh0cnVlKSB7XG4gICAgICAgICAgICAgIHZhciBncmVhdFZhbHVlID0gZihhW2dyZWF0XSk7XG4gICAgICAgICAgICAgIGlmIChncmVhdFZhbHVlIDw9IHBpdm90VmFsdWUyICYmIGdyZWF0VmFsdWUgPj0gcGl2b3RWYWx1ZTIpIHtcbiAgICAgICAgICAgICAgICBncmVhdC0tO1xuICAgICAgICAgICAgICAgIGlmIChncmVhdCA8IGspIGJyZWFrO1xuICAgICAgICAgICAgICAgIC8vIFRoaXMgaXMgdGhlIG9ubHkgbG9jYXRpb24gaW5zaWRlIHRoZSBsb29wIHdoZXJlIGEgbmV3XG4gICAgICAgICAgICAgICAgLy8gaXRlcmF0aW9uIGlzIHN0YXJ0ZWQuXG4gICAgICAgICAgICAgICAgY29udGludWU7XG4gICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgLy8gYVtncmVhdF0gPCBwaXZvdDIuXG4gICAgICAgICAgICAgICAgaWYgKGdyZWF0VmFsdWUgPCBwaXZvdFZhbHVlMSkge1xuICAgICAgICAgICAgICAgICAgLy8gVHJpcGxlIGV4Y2hhbmdlLlxuICAgICAgICAgICAgICAgICAgYVtrXSA9IGFbbGVzc107XG4gICAgICAgICAgICAgICAgICBhW2xlc3MrK10gPSBhW2dyZWF0XTtcbiAgICAgICAgICAgICAgICAgIGFbZ3JlYXQtLV0gPSBlaztcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgLy8gYVtncmVhdF0gPT0gcGl2b3QxLlxuICAgICAgICAgICAgICAgICAgYVtrXSA9IGFbZ3JlYXRdO1xuICAgICAgICAgICAgICAgICAgYVtncmVhdC0tXSA9IGVrO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfVxuICAgIH1cblxuICAgIC8vIFRoZSBzZWNvbmQgcGFydGl0aW9uIGhhcyBub3cgYmVlbiBjbGVhcmVkIG9mIHBpdm90IGVsZW1lbnRzIGFuZCBsb29rc1xuICAgIC8vIGFzIGZvbGxvd3M6XG4gICAgLy8gWyAgKiAgfCAgPiBwaXZvdDEgJiYgPCBwaXZvdDIgIHwgKiBdXG4gICAgLy8gICAgICAgIF4gICAgICAgICAgICAgICAgICAgICAgXlxuICAgIC8vICAgICAgIGxlc3MgICAgICAgICAgICAgICAgICBncmVhdFxuICAgIC8vIFNvcnQgdGhlIHNlY29uZCBwYXJ0aXRpb24gdXNpbmcgcmVjdXJzaXZlIGRlc2NlbnQuXG5cbiAgICAvLyBUaGUgc2Vjb25kIHBhcnRpdGlvbiBsb29rcyBhcyBmb2xsb3dzOlxuICAgIC8vIFsgICogIHwgID49IHBpdm90MSAmJiA8PSBwaXZvdDIgIHwgKiBdXG4gICAgLy8gICAgICAgIF4gICAgICAgICAgICAgICAgICAgICAg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AgICAgICAgICByZW1vdmVkID0gW10sXG4gICAgICAgICAgdmFsdWVJbmRleEFkZGVkID0gW10sXG4gICAgICAgICAgdmFsdWVJbmRleFJlbW92ZWQgPSBbXTtcbiAgICAgICAgICBcbiAgICAgICAgICBcbiAgICAgIC8vIEZhc3QgaW5jcmVtZW50YWwgdXBkYXRlIGJhc2VkIG9uIHByZXZpb3VzIGxvIGluZGV4LlxuICAgICAgaWYgKGxvMSA8IGxvMCkge1xuICAgICAgICBmb3IgKGkgPSBsbzEsIGogPSBNYXRoLm1pbihsbzAsIGhpMSk7IGkgPCBqOyArK2kpIHtcbiAgICAgICAgICBhZGRlZC5wdXNoKGluZGV4W2ldKTtcbiAgICAgICAgICB2YWx1ZUluZGV4QWRkZWQucHVzaChpKTtcbiAgICAgICAgfVxuICAgICAgfSBlbHNlIGlmIChsbzEgPiBsbzApIHtcbiAgICAgICAgZm9yIChpID0gbG8wLCBqID0gTWF0aC5taW4obG8xLCBoaTApOyBpIDwgajsgKytpKSB7XG4gICAgICAgICAgcmVtb3ZlZC5wdXNoKGluZGV4W2ldKTtcbiAgICAgICAgICB2YWx1ZUluZGV4UmVtb3ZlZC5wdXNoKGkpO1xuICAgICAgICB9XG4gICAgICB9XG5cbiAgICAgIC8vIEZhc3QgaW5jcmVtZW50YWwgdXBkYXRlIGJhc2VkIG9uIHByZXZpb3VzIGhpIGluZGV4LlxuICAgICAgaWYgKGhpMSA+IGhpMCkge1xuICAgICAgICBmb3IgKGkgPSBNYXRoLm1heChsbzEsIGhpMCksIGogPSBoaTE7IGkgPCBqOyArK2kpIHtcbiAgICAgICAgICBhZGRlZC5wdXNoKGluZGV4W2ldKTtcbiAgICAgICAgICB2YWx1ZUluZGV4QWRkZWQucHVzaChpKTtcbiAgICAgICAgfVxuICAgICAgfSBlbHNlIGlmIChoaTEgPCBoaTApIHtcbiAgICAgICAgZm9yIChpID0gTWF0aC5tYXgobG8wLCBoaTEpLCBqID0gaGkwOyBpIDwgajsgKytpKSB7XG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4gICAgICAgICAgLy8gQWRkIGVtcHR5IHJvd3MgYXQgdGhlIGVuZFxuICAgICAgICAgIGlmKGZpbHRlcnMuemVybyhqID0gaXRlcmFibGVzRW1wdHlSb3dzW2ldKSkge1xuICAgICAgICAgICAgYXJyYXkucHVzaChkYXRhW2pdKTtcbiAgICAgICAgICAgIC0taztcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH1cblxuICAgICAgcmV0dXJuIGFycmF5O1xuICAgIH1cblxuICAgIC8vIFJldHVybnMgdGhlIGJvdHRvbSBLIHNlbGVjdGVkIHJlY29yZHMgYmFzZWQgb24gdGhpcyBkaW1lbnNpb24ncyBvcmRlci5cbiAgICAvLyBOb3RlOiBvYnNlcnZlcyB0aGlzIGRpbWVuc2lvbidzIGZpbHRlciwgdW5saWtlIGdyb3VwIGFuZCBncm91cEFsbC5cbiAgICBmdW5jdGlvbiBib3R0b20oaykge1xuICAgICAgdmFyIGFycmF5ID0gW10sXG4gICAgICAgICAgaSxcbiAgICAgICAgICBqO1xuXG4gICAgICBpZihpdGVyYWJsZSkge1xuICAgICAgICAvLyBBZGQgZW1wdHkgcm93cyBhdCB0aGUgdG9wXG4gICAgICAgIGZvcihpID0gMDsgaSA8IGl0ZXJhYmxlc0VtcHR5Um93cy5sZW5ndGggJiYgayA+IDA7IGkrKykge1xuICAgICAgICAgIGlmKGZpbHRlcnMuemVybyhqID0gaXRlcmFibGVzRW1wdHlSb3dzW2ldKSkge1xuICAgICAgICAgICAgYXJyYXkucHVzaChkYXRhW2pdKTtcbiAgICAgICAgICAgIC0taztcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH1cblxuICAgICAgaSA9IGxvMDtcblxuICAgICAgd2hpbGUgKGkgPCBoaTAgJiYgayA+IDApIHtcbiAgICAgICAgaWYgKGZpbHRlcnMuemVybyhqID0gaW5kZXhbaV0pKSB7XG4gICAgICAgICAgYXJyYXkucHVzaChkYXRhW2pdKTtcbiAgICAgICAgICAtLWs7XG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ICAgaiA9IG5ld0luZGV4W2kxXSArIChpdGVyYWJsZSA/IG4wb2xkIDogbjApXG5cblxuICAgICAgICAgICAgaWYoaXRlcmFibGUpe1xuICAgICAgICAgICAgICBpZihncm91cEluZGV4W2pdKXtcbiAgICAgICAgICAgICAgICBncm91cEluZGV4W2pdLnB1c2goaylcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICBlbHNle1xuICAgICAgICAgICAgICAgIGdyb3VwSW5kZXhbal0gPSBba11cbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgZWxzZXtcbiAgICAgICAgICAgICAgZ3JvdXBJbmRleFtqXSA9IGs7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIC8vIEFsd2F5cyBhZGQgbmV3IHZhbHVlcyB0byBncm91cHMuIE9ubHkgcmVtb3ZlIHdoZW4gbm90IGluIGZpbHRlci5cbiAgICAgICAgICAgIC8vIFRoaXMgZ2l2ZXMgZ3JvdXBzIGZ1bGwgaW5mb3JtYXRpb24gb24gZGF0YSBsaWZlLWN5Y2xlLlxuICAgICAgICAgICAgZy52YWx1ZSA9IGFkZChnLnZhbHVlLCBkYXRhW2pdLCB0cnVlKTtcbiAgICAgICAgICAgIGlmICghZmlsdGVycy56ZXJvRXhjZXB0KGosIG9mZnNldCwgemVybykpIGcudmFsdWUgPSByZW1vdmUoZy52YWx1ZSwgZGF0YVtqXSwgZmFsc2UpO1xuICAgICAgICAgICAgaWYgKCsraTEgPj0gbjEpIGJyZWFrO1xuICAgICAgICAgICAgeDEgPSBrZXkobmV3VmFsdWVzW2kxXSk7XG4gICAgICAgICAgfVxuXG4gICAgICAgICAgZ3JvdXBJbmNyZW1lbnQoKTtcbiAgICAgICAgfVxuXG4gICAgICAgIC8vIEFkZCBhbnkgcmVtYWluaW5nIG9sZCBncm91cHMgdGhhdCB3ZXJlIGdyZWF0ZXIgdGgxYW4gYWxsIG5ldyBrZXlzLlxuICAgICAgICAvLyBObyBpbmN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ZSB7XG4gICAgICAgICAgICB1cGRhdGUgPSBjcm9zc2ZpbHRlcl9udWxsO1xuICAgICAgICAgICAgcmVzZXQgPSBjcm9zc2ZpbHRlcl9udWxsO1xuICAgICAgICAgIH1cbiAgICAgICAgICBncm91cEluZGV4ID0gbnVsbDtcbiAgICAgICAgfVxuICAgICAgICBmaWx0ZXJMaXN0ZW5lcnNbal0gPSB1cGRhdGU7XG5cbiAgICAgICAgLy8gQ291bnQgdGhlIG51bWJlciBvZiBhZGRlZCBncm91cHMsXG4gICAgICAgIC8vIGFuZCB3aWRlbiB0aGUgZ3JvdXAgaW5kZXggYXMgbmVlZGVkLlxuICAgICAgICBmdW5jdGlvbiBncm91cEluY3JlbWVudCgpIHtcbiAgICAgICAgICBpZihpdGVyYWJsZSl7XG4gICAgICAgICAgICBrKytcbiAgICAgICAgICAgIHJldHVyblxuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAoKytrID09PSBncm91cENhcGFjaXR5KSB7XG4gICAgICAgICAgICByZUluZGV4ID0gY3Jvc3NmaWx0ZXJfYXJyYXlXaWRlbihyZUluZGV4LCBncm91cFdpZHRoIDw8PSAxKTtcbiAgICAgICAgICAgIGdyb3VwSW5kZXggPSBjcm9zc2ZpbHRlcl9hcnJheVdpZGVuKGdyb3VwSW5kZXgsIGdyb3VwV2lkdGgpO1xuICAgICAgICAgICAgZ3JvdXBDYXBhY2l0eSA9IGNyb3NzZmlsdGVyX2NhcGFjaXR5KGdyb3VwV2lkdGgpO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfVxuXG4gICAgICBmdW5jdGlvbiByZW1vdmVEYXRhKCkge1xuICAgICAgICBpZiAoayA+IDEpIHtcbiAgICAgICAgICB2YXIgb2xkSyA9IGssXG4gICAgICAgICAgICAgIG9sZEdyb3VwcyA9IGdyb3VwcyxcbiAgICAgICAgICAgICAgc2Vlbkdyb3VwcyA9IGNyb3NzZmlsdGVyX2luZGV4KG9sZEssIG9sZEspO1xuXG4gICAgICAgICAgLy8gRmlsdGVyIG91dCBub24tbWF0Y2hlcyBieSBjb3B5aW5nIG1hdGNoaW5nIGdyb3VwIGluZGV4IGVudHJpZXMgdG9cbiAgICAgICAgICAvLyB0aGUgYmVnaW5uaW5nIG9mIHRoZSBhcnJheS5cbiAgICAgICAgICBmb3IgKHZhciBpID0gMCwgaiA9IDA7IGkgPCBuOyArK2kpIHtcbiAgICAgICAgICAgIGlmICghZmlsdGVycy56ZXJvKGkpKSB7XG4gICAgICAgICAgICAgIHNlZW5Hcm91cHNbZ3JvdXBJbmRleFtqXSA9IGdyb3VwSW5kZXhbaV1dID0gMTtcbiAgICAgICAgICAgICAgKytqO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cblxuICAgICAgICAgIC8vIFJlYXNzZW1ibGUgZ3JvdXBzIGluY2x1ZGluZyBvbmx5IHRob3NlIGdyb3VwcyB0aGF0IHdlcmUgcmVmZXJyZWRcbiAgICAgICAgICAvLyB0byBieSBtYXRjaGluZyBncm91cCBpbmRleCBlbnRyaWVzLiAgTm90ZSB0aGUgbmV3IGdyb3VwIGluZGV4IGluXG4gICAgICAgICAgLy8gc2Vlbkdyb3Vwcy5cbiAgICAgICAgICBncm91cHMgPSBbXSwgayA9IDA7XG4gICAgICAgICAgZm9yIChpID0gMDsgaSA8IG9sZEs7ICsraSkge1xuICAgICAgICAgICAgaWYgKHNlZW5Hcm91cHNbaV0pIHtcbiAgICAgICAgICAgICAgc2Vlbkdyb3Vwc1tpXSA9IGsrKztcbiAgICAgICAgICAgICAgZ3JvdXBzLnB1c2gob2xkR3JvdXBzW2ldKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG5cbiAgICAgICAgICBpZiAoayA+IDEpIHtcbiAgICAgICAgICAgIC8vIFJlaW5kZXggdGhlIGdyb3VwIGluZGV4IHVzaW5nIHNlZW5Hcm91cHMgdG8gZmluZCB0aGUgbmV3IGluZGV4LlxuICAgICAgICAgICAgZm9yICh2YXIgaSA9IDA7IGk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zZmlsdGVyLmFkZC9yZW1vdmUgb3BlcmF0aW9uLlxuICAgICAgZnVuY3Rpb24gdXBkYXRlTWFueShmaWx0ZXJPbmUsIGZpbHRlck9mZnNldCwgYWRkZWQsIHJlbW92ZWQsIG5vdEZpbHRlcikge1xuICAgICAgICBcbiAgICAgICAgaWYgKChmaWx0ZXJPbmUgPT09IG9uZSAmJiBmaWx0ZXJPZmZzZXQgPT09IG9mZnNldCkgfHwgcmVzZXROZWVkZWQpIHJldHVybjtcblxuICAgICAgICB2YXIgaSxcbiAgICAgICAgICAgIGosXG4gICAgICAgICAgICBrLFxuICAgICAgICAgICAgbixcbiAgICAgICAgICAgIGc7XG5cbiAgICAgICAgaWYoaXRlcmFibGUpe1xuICAgICAgICAgIC8vIEFkZCB0aGUgYWRkZWQgdmFsdWVzLlxuICAgICAgICAgIGZvciAoaSA9IDAsIG4gPSBhZGRlZC5sZW5ndGg7IGkgPCBuOyArK2kpIHtcbiAgICAgICAgICAgIGlmIChmaWx0ZXJzLnplcm9FeGNlcHQoayA9IGFkZGVkW2ldLCBvZmZzZXQsIHplcm8pKSB7XG4gICAgICAgICAgICAgIGZvciAoaiA9IDA7IGogPCBncm91cEluZGV4W2tdLmxlbmd0aDsgaisrKSB7XG4gICAgICAgICAgICAgICAgZyA9IGdyb3Vwc1tncm91cEluZGV4W2tdW2pdXTtcbiAgICAgICAgICAgICAgICBnLnZhbHVlID0gcmVkdWNlQWRkKGcudmFsdWUsIGRhdGFba10sIGZhbHNlLCBqKTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cblxuICAgICAgICAgIC8vIFJlbW92ZSB0aGUgcmVtb3ZlZCB2YWx1ZXMuXG4gICAgICAgICAgZm9yIChpID0gMCwgbiA9IHJlbW92ZWQubGVuZ3RoOyBpIDwgbjsgKytpKSB7XG4gICAgICAgICAgICBpZiAoZmlsdGVycy5vbmx5RXhjZXB0KGsgPSByZW1vdmVkW2ldLCBvZmZzZXQsIHplcm8sIGZpbHRlck9mZnNldCwgZmlsdGVyT25lKSkge1xuICAgICAgICAgICAgICBmb3IgKGogPSAwOyBqIDwgZ3JvdXBJbmRleFtrXS5sZW5ndGg7IGorKykge1xuICAgICAgICAgICAgICAgIGcgPSBncm91cHNbZ3JvdXBJbmRleFtrXVtqXV07XG4gICAgICAgICAgICAgICAgZy52YWx1ZSA9IHJlZHVjZVJlbW92ZShnLnZhbHVlLCBkYXRhW2tdLCBub3RGaWx0ZXIsIGopO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICAgIHJldHVybjtcbiAgICAgICAgfVxuXG4gICAgICAgIC8vIEFkZCB0aGUgYWRkZWQgdmFsdWVzLlxuICAgICAgICBmb3IgKGkgPSAwLCBuID0gYWRkZWQubGVuZ3RoOyBpIDwgbjsgKytpKSB7XG4gICAgICAgICAgaWYgKGZpbHRlcnMuemVyb0V4Y2VwdChrID0gYWRkZWRbaV0sIG9mZnNldCwgemVybykpIHtcbiAgICAgICAgICAgIGcgPSBncm91cHNbZ3JvdXBJbmRleFtrXV07XG4gICAgICAgICAgICBnLnZhbHVlID0gcmVkdWNlQWRkKGcudmFsdWUsIGRhdGFba10sIGZhbHNlKTtcbiAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICAvLyBSZW1vdmUgdGhlIHJlbW92ZWQgdmFsdWVzLlxuICAgICAgICBmb3IgKGkgPSAwLCBuID0gcmVtb3ZlZC5sZW5ndGg7IGkgPCBuOyArK2kpIHtcbiAgICAgICAgICBpZiAoZmlsdGVycy5vbmx5RXhjZXB0KGsgPSByZW1vdmVkW2ldLCBvZmZzZXQsIHplcm8sIGZpbHRlck9mZnNldCwgZmlsdGVyT25lKSkge1xuICAgICAgICAgICAgZyA9IGdyb3Vwc1tncm91cEluZGV4W2tdXTtcbiAgICAgICAgICAgIGcudmFsdWUgPSByZWR1Y2VSZW1vdmUoZy52YWx1ZSwgZGF0YVtrXSwgbm90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pXS5sZW5ndGg7IGorKykge1xuICAgICAgICAgICAgICBnID0gZ3JvdXBzW2dyb3VwSW5kZXhbaV1bal1dO1xuICAgICAgICAgICAgICBnLnZhbHVlID0gcmVkdWNlQWRkKGcudmFsdWUsIGRhdGFbaV0sIHRydWUsIGopO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgICBmb3IgKGkgPSAwOyBpIDwgbjsgKytpKSB7XG4gICAgICAgICAgICBpZiAoIWZpbHRlcnMuemVyb0V4Y2VwdChpLCBvZmZzZXQsIHplcm8pKSB7XG4gICAgICAgICAgICAgIGZvciAoaiA9IDA7IGogPCBncm91cEluZGV4W2ldLmxlbmd0aDsgaisrKSB7XG4gICAgICAgICAgICAgICAgZyA9IGdyb3Vwc1tncm91cEluZGV4W2ldW2pdXTtcbiAgICAgICAgICAgICAgICBnLnZhbHVlID0gcmVkdWNlUmVtb3ZlKGcudmFsdWUsIGRhdGFbaV0sIGZhbHNlLCBqKTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgICByZXR1cm47XG4gICAgICAgIH1cblxuICAgICAgICBmb3IgKGkgPSAwOyBpIDwgbjsgKytpKSB7XG4gICAgICAgICAgZyA9IGdyb3Vwc1tncm91cEluZGV4W2ldXTtcbiAgICAgICAgICBnLnZhbHVlID0gcmVkdWNlQWRkKGcudmFsdWUsIGRhdGFbaV0sIHRydWUpO1xuICAgICAgICB9XG4gICAgICAgIGZvciAoaSA9IDA7IGkgPCBuOyArK2kpIHtcbiAgICAgICAgICBpZiAoIWZpbHRlcnMuemVyb0V4Y2VwdChpLCBvZmZzZXQsIHplcm8pKSB7XG4gICAgICAgICAgICBnID0gZ3JvdXBzW2dyb3VwSW5kZXhbaV1dO1xuICAgICAgICAgICAgZy52YWx1ZSA9IHJlZHVjZVJlbW92ZShnLnZhbHVlLCBkYXRhW2ldLCBmYWxzZSk7XG4gICAgICAgICAgfVxuICAgICAgICB9XG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hbHNlO1xuICAgIHZhciByZXF1ZXN0VGljayA9IHZvaWQgMDtcbiAgICB2YXIgaXNOb2RlSlMgPSBmYWxzZTtcbiAgICAvLyBxdWV1ZSBmb3IgbGF0ZSB0YXNrcywgdXNlZCBieSB1bmhhbmRsZWQgcmVqZWN0aW9uIHRyYWNraW5nXG4gICAgdmFyIGxhdGVyUXVldWUgPSBbXTtcblxuICAgIGZ1bmN0aW9uIGZsdXNoKCkge1xuICAgICAgICAvKiBqc2hpbnQgbG9vcGZ1bmM6IHRydWUgKi9cbiAgICAgICAgdmFyIHRhc2ssIGRvbWFpbjtcblxuICAgICAgICB3aGlsZSAoaGVhZC5uZXh0KSB7XG4gICAgICAgICAgICBoZWFkID0gaGVhZC5uZXh0O1xuICAgICAgICAgICAgdGFzayA9IGhlYWQudGFzaztcbiAgICAgICAgICAgIGhlYWQudGFzayA9IHZvaWQgMDtcbiAgICAgICAgICAgIGRvbWFpbiA9IGhlYWQuZG9tYWluO1xuXG4gICAgICAgICAgICBpZiAoZG9tYWluKSB7XG4gICAgICAgICAgICAgICAgaGVhZC5kb21haW4gPSB2b2lkIDA7XG4gICAgICAgICAgICAgICAgZG9tYWluLmVudGVyKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBydW5TaW5nbGUodGFzaywgZG9tYWluKTtcblxuICAgICAgICB9XG4gICAgICAgIHdoaWxlIChsYXRlclF1ZXVlLmxlbmd0aCkge1xuICAgICAgICAgICAgdGFzayA9IGxhdGVyUXVldWUucG9wKCk7XG4gICAgICAgICAgICBydW5TaW5nbGUodGFzayk7XG4gICAgICAgIH1cbiAgICAgICAgZmx1c2hpbmcgPSBmYWxzZTtcbiAgICB9XG4gICAgLy8gcnVucyBhIHNpbmdsZSBmdW5jdGlvbiBpbiB0aGUgYXN5bmMgcXVldWVcbiAgICBmdW5jdGlvbiBydW5TaW5nbGUodGFzaywgZG9tYWluKSB7XG4gICAgICAgIHRyeSB7XG4gICAgICAgICAgICB0YXNrKCk7XG5cbiAgICAgICAgfSBjYXRjaCAoZSkge1xuICAgICAgICAgICAgaWYgKGlzTm9kZUpTKSB7XG4gICAgICAgICAgICAgICAgLy8gSW4gbm9kZSwgdW5jYXVnaHQgZXhjZXB0aW9ucyBhcmUgY29uc2lkZXJlZCBmYXRhbCBlcnJvcnMuXG4gICAgICAgICAgICAgICAgLy8gUmUtdGhyb3cgdGhlbSBzeW5jaHJvbm91c2x5IHRvIGludGVycnVwdCBmbHVzaGluZyFcblxuICAgICAgICAgICAgICAgIC8vIEVuc3VyZSBjb250aW51YXRpb24gaWYgdGhlIHVuY2F1Z2h0IGV4Y2VwdGlvbiBpcyBzdXBwcmVzc2VkXG4gICAgICAgICAgICAgICAgLy8gbGlzdGVuaW5nIFwidW5jYXVnaHRFeGNlcHRpb25cIiBldmVudHMgKGFzIGRvbWFpbnMgZG9lcykuXG4gICAgICAgICAgICAgICAgLy8gQ29udGludWUgaW4gbmV4dCBldmVudCB0byBhdm9pZCB0aWNrIHJlY3Vyc2lvbi5cbiAgICAgICAgICAgICAgICBpZiAoZG9tYWluKSB7XG4gICAgICAgICAgICAgICAgICAgIGRvbWFpbi5leGl0KCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIHNldFRpbWVvdXQoZmx1c2gsIDApO1xuICAgICAgICAgICAgICAgIGlmIChkb21haW4pIHtcbiAgICAgICAgICAgICAgICAgICAgZG9tYWluLmVudGVyKCk7XG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgdGhyb3cgZTtcblxuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAvLyBJbiBicm93c2VycywgdW5jYXVnaHQgZXhjZXB0aW9ucyBhcmUgbm90IGZhdGFsLlxuICAgICAgICAgICAgICAgIC8vIFJlLXRocm93IHRoZW0gYXN5bmNocm9ub3VzbHkgdG8gYXZvaWQgc2xvdy1kb3ducy5cbiAgICAgICAgICAgICAgICBzZXRUaW1lb3V0KGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgICAgICAgICAgdGhyb3cgZTtcbiAgICAgICAgICAgICAgICB9LCAwKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIGlmIChkb21haW4pIHtcbiAgICAgICAgICAgIGRvbWFpbi5leGl0KCk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBuZXh0VGljayA9IGZ1bmN0aW9uICh0YXNrKSB7XG4gICAgICAgIHRhaWwgPSB0YWlsLm5leHQgPSB7XG4gICAgICAgICAgICB0YXNrOiB0YXNrLFxuICAgICAgICAgICAgZG9tYWluOiBpc05vZGVKUyAmJiBwcm9jZXNzLmRvbWFpbixcbiAgICAgICAgICAgIG5leHQ6IG51bGxcbiAgICAgICAgfTtcblxuICAgICAgICBpZiAoIWZsdXNoaW5nKSB7XG4gICAgICAgICAgICBmbHVzaGluZyA9IHRydWU7XG4gICAgICAgICAgICByZXF1ZXN0VGljaygpO1xuICAgICAgICB9XG4gICAgfTtcblxuICAgIGlmICh0eXBlb2YgcHJvY2VzcyA9PT0gXCJvYmplY3RcIiAmJlxuICAgICAgICBwcm9jZXNzLnRvU3RyaW5nKCkgPT09IFwiW29iamVjdCBwcm9jZXNzXVwiICYmIHByb2Nlc3MubmV4dFRpY2spIHtcbiAgICAgICAgLy8gRW5zdXJlIFEgaXMgaW4gYSByZWFsIE5vZGUgZW52aXJvbm1lbnQsIHdpdGggYSBgcHJvY2Vzcy5uZXh0VGlja2AuXG4gICAgICAgIC8vIFRvIHNlZSB0aHJvdWdoIGZha2UgTm9kZSBlbnZpcm9ubWVudHM6XG4gICAgICAgIC8vICogTW9jaGEgdGVzdCBydW5uZXIgLSBleHBvc2VzIGEgYHByb2Nlc3NgIGdsb2JhbCB3aXRob3V0IGEgYG5leHRUaWNrYFxuICAgICAgICAvLyAqIEJyb3dzZXJpZnkgLSBleHBvc2VzIGEgYHByb2Nlc3MubmV4VGlja2AgZnVuY3Rpb24gdGhhdCB1c2VzXG4gICA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AgICAgICAgICAgLy8gc2VlayB0byB0aGUgZmlyc3QgdmFsdWUgaW4gdGhlIGFycmF5LCBhY2NvdW50aW5nXG4gICAgICAgICAgICAvLyBmb3IgdGhlIHBvc3NpYmlsaXR5IHRoYXQgaXMgaXMgYSBzcGFyc2UgYXJyYXlcbiAgICAgICAgICAgIGRvIHtcbiAgICAgICAgICAgICAgICBpZiAoaW5kZXggaW4gdGhpcykge1xuICAgICAgICAgICAgICAgICAgICBiYXNpcyA9IHRoaXNbaW5kZXgrK107XG4gICAgICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBpZiAoKytpbmRleCA+PSBsZW5ndGgpIHtcbiAgICAgICAgICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gd2hpbGUgKDEpO1xuICAgICAgICB9XG4gICAgICAgIC8vIHJlZHVjZVxuICAgICAgICBmb3IgKDsgaW5kZXggPCBsZW5ndGg7IGluZGV4KyspIHtcbiAgICAgICAgICAgIC8vIGFjY291bnQgZm9yIHRoZSBwb3NzaWJpbGl0eSB0aGF0IHRoZSBhcnJheSBpcyBzcGFyc2VcbiAgICAgICAgICAgIGlmIChpbmRleCBpbiB0aGlzKSB7XG4gICAgICAgICAgICAgICAgYmFzaXMgPSBjYWxsYmFjayhiYXNpcywgdGhpc1tpbmRleF0sIGluZGV4KTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gYmFzaXM7XG4gICAgfVxuKTtcblxudmFyIGFycmF5X2luZGV4T2YgPSB1bmN1cnJ5VGhpcyhcbiAgICBBcnJheS5wcm90b3R5cGUuaW5kZXhPZiB8fCBmdW5jdGlvbiAodmFsdWUpIHtcbiAgICAgICAgLy8gbm90IGEgdmVyeSBnb29kIHNoaW0sIGJ1dCBnb29kIGVub3VnaCBmb3Igb3VyIG9uZSB1c2Ugb2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plY3RfY3JlYXRlKFByb21pc2UucHJvdG90eXBlKTtcblxuICAgIHByb21pc2UucHJvbWlzZURpc3BhdGNoID0gZnVuY3Rpb24gKHJlc29sdmUsIG9wLCBvcGVyYW5kcykge1xuICAgICAgICB2YXIgYXJncyA9IGFycmF5X3NsaWNlKGFyZ3VtZW50cyk7XG4gICAgICAgIGlmIChtZXNzYWdlcykge1xuICAgICAgICAgICAgbWVzc2FnZXMucHVzaChhcmdzKTtcbiAgICAgICAgICAgIGlmIChvcCA9PT0gXCJ3aGVuXCIgJiYgb3BlcmFuZHNbMV0pIHsgLy8gcHJvZ3Jlc3Mgb3BlcmFuZFxuICAgICAgICAgICAgICAgIHByb2dyZXNzTGlzdGVuZXJzLnB1c2gob3BlcmFuZHNbMV0pO1xuICAgICAgICAgICAgfVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgUS5uZXh0VGljayhmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAgICAgcmVzb2x2ZWRQcm9taXNlLnByb21pc2VEaXNwYXRjaC5hcHBseShyZXNvbHZlZFByb21pc2UsIGFyZ3MpO1xuICAgICAgICAgICAgfSk7XG4gICAgICAgIH1cbiAgICB9O1xuXG4gICAgLy8gWFhYIGRlcHJlY2F0ZWRcbiAgICBwcm9taXNlLnZhbHVlT2YgPSBmdW5jdGlvbiAoKSB7XG4gICAgICAgIGlmIChtZXNzYWdlcykge1xuICAgICAgICAgICAgcmV0dXJuIHByb21pc2U7XG4gICAgICAgIH1cbiAgICAgICAgdmFyIG5lYXJlclZhbHVlID0gbmVhcmVyKHJlc29sdmVkUHJvbWlzZSk7XG4gICAgICAgIGlmIChpc1Byb21pc2UobmVhcmVyVmFsdWUpKSB7XG4gICAgICAgICAgICByZXNvbHZlZFByb21pc2UgPSBuZWFyZXJWYWx1ZTsgLy8gc2hvcnRlbiBjaGFpblxuICAgICAgICB9XG4gICAgICAgIHJldHVybiBuZWFyZXJWYWx1ZTtcbiAgICB9O1xuXG4gICAgcH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CB3ZSBjYW4gcmVtb3ZlXG4gICAgICAgICAgICAvLyB0aGlzIGJsb2NrLlxuXG4gICAgICAgICAgICBpZiAodHlwZW9mIFN0b3BJdGVyYXRpb24gPT09IFwidW5kZWZpbmVkXCIpIHtcbiAgICAgICAgICAgICAgICAvLyBFUzYgR2VuZXJhdG9yc1xuICAgICAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgICAgIHJlc3VsdCA9IGdlbmVyYXRvclt2ZXJiXShhcmcpO1xuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGV4Y2VwdGlvbikge1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gcmVqZWN0KGV4Y2VwdGlvbik7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGlmIChyZXN1bHQuZG9uZSkge1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gUShyZXN1bHQudmFsdWUpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiB3aGVuKHJlc3VsdC52YWx1ZSwgY2FsbGJhY2ssIGVycmJhY2spO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgLy8gU3BpZGVyTW9ua2V5IEdlbmVyYXRvcnNcbiAgICAgICAgICAgICAgICAvLyBGSVhNRTogUmVtb3ZlIHRoaXMgY2FzZSB3aGVuIFNNIGRvZXMgRVM2IGdlbmVyYXRvcnMuXG4gICAgICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICAgICAgcmVzdWx0ID0gZ2VuZXJhdG9yW3ZlcmJdKGFyZyk7XG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZXhjZXB0aW9uKSB7XG4gICAgICAgICAgICAgICAgICAgIGlmIChpc1N0b3BJdGVyYXRpb24oZXhjZXB0aW9uKSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIFEoZXhjZXB0aW9uLnZhbHVlKTtcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiByZWplY3QoZXhjZXB0aW9uKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICByZXR1cm4gd2hlbihyZXN1bHQsIGNhbGxiYWNrLCBlcnJiYWNrKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICB2YXIgZ2VuZXJhdG9yID0gbWFrZUdlbmVyYXRvci5hcHBseSh0aGlzLCBhcmd1bWVudHMpO1xuICAgICAgICB2YXIgY2FsbGJhY2sgPSBjb250aW51ZXIuYmluZChjb250aW51ZXIsIFwibmV4dFwiKTtcbiAgICAgICAgdmFyIGVycmJhY2sgPSBjb250aW51ZXIuYmluZChjb250aW51ZXIsIFwidGhyb3dcIik7XG4gICAgICAgIHJldHVybiBjYWxsYmFjaygpO1xuICAgIH07XG59XG5cbi8qKlxuICogVGhlIHNwYXduIGZ1bmN0aW9uIGlzIGEgc21hbGwgd3JhcHBlciBhcm91bmQgYXN5bmMgdGhhdCBpbW1lZGlhdGVseVxuICogY2FsbHMgdGhlIGdlbmVyYXRvciBhbmQgYWxzbyBlbmRzIHRoZSBwcm9taXNlIGNoYWluLCBzbyB0aGF0IGFueVxuICogdW5oYW5kbGVkIGVycm9ycyBhcmUgdGhyb3duIGluc3RlYWQgb2YgZm9yd2FyZGVkIHRvIHRoZSBlcnJvclxuICogaGFuZGxlci4gVGhpcyBpcyB1c2VmdWwgYmVjYXVzZSBpdCdzIGV4dHJlbWVseSBjb21tb24gdG8gcnVuXG4gKiBnZW5lcmF0b3JzIGF0IHRoZSB0b3AtbGV2ZWwgdG8gd29yayB3aXRoIGxpYnJhcmllcy5cbiAqL1xuUS5zcGF3biA9IHNwYXduO1xuZnVuY3Rpb24gc3Bhd24obWFrZUdlbmVyYXRvcikge1xuICAgIFEuZG9uZShRLmFzeW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9taXNlKSAmJlxuICAgICAgICAgICAgICAgIChzbmFwc2hvdCA9IHByb21pc2UuaW5zcGVjdCgpKS5zdGF0ZSA9PT0gXCJmdWxmaWxsZWRcIlxuICAgICAgICAgICAgKSB7XG4gICAgICAgICAgICAgICAgcHJvbWlzZXNbaW5kZXhdID0gc25hcHNob3QudmFsdWU7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICsrcGVuZGluZ0NvdW50O1xuICAgICAgICAgICAgICAgIHdoZW4oXG4gICAgICAgICAgICAgICAgICAgIHByb21pc2UsXG4gICAgICAgICAgICAgICAgICAgIGZ1bmN0aW9uICh2YWx1ZSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgcHJvbWlzZXNbaW5kZXhdID0gdmFsdWU7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoLS1wZW5kaW5nQ291bnQgPT09IDApIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBkZWZlcnJlZC5yZXNvbHZlKHByb21pc2VzKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICAgICAgZGVmZXJyZWQucmVqZWN0LFxuICAgICAgICAgICAgICAgICAgICBmdW5jdGlvbiAocHJvZ3Jlc3MpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGRlZmVycmVkLm5vdGlmeSh7IGluZGV4OiBpbmRleCwgdmFsdWU6IHByb2dyZXNzIH0pO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSwgdm9pZCAwKTtcbiAgICAgICAgaWYgKHBlbmRpbmdDb3VudCA9PT0gMCkge1xuICAgICAgICAgICAgZGVmZXJyZWQucmVzb2x2ZShwcm9taXNlcyk7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIGRlZmVycmVkLnByb21pc2U7XG4gICAgfSk7XG59XG5cblByb21p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ICAgZGVmZXJyZWQucmVzb2x2ZShyZXN1bHQpO1xuICAgICAgICB9XG4gICAgICAgIGZ1bmN0aW9uIG9uUmVqZWN0ZWQoKSB7XG4gICAgICAgICAgICBwZW5kaW5nQ291bnQtLTtcbiAgICAgICAgICAgIGlmIChwZW5kaW5nQ291bnQgPT09IDApIHtcbiAgICAgICAgICAgICAgICBkZWZlcnJlZC5yZWplY3QobmV3IEVycm9yKFxuICAgICAgICAgICAgICAgICAgICBcIkNhbid0IGdldCBmdWxmaWxsbWVudCB2YWx1ZSBmcm9tIGFueSBwcm9taXNlLCBhbGwgXCIgK1xuICAgICAgICAgICAgICAgICAgICBcInByb21pc2VzIHdlcmUgcmVqZWN0ZWQuXCJcbiAgICAgICAgICAgICAgICApKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBmdW5jdGlvbiBvblByb2dyZXNzKHByb2dyZXNzKSB7XG4gICAgICAgICAgICBkZWZlcnJlZC5ub3RpZnkoe1xuICAgICAgICAgICAgICAgIGluZGV4OiBpbmRleCxcbiAgICAgICAgICAgICAgICB2YWx1ZTogcHJvZ3Jlc3NcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgfSwgdW5kZWZpbmVkKTtcblxuICAgIHJldHVybiBkZWZlcnJlZC5wcm9taXNlO1xufVxuXG5Qcm9taXNlLnByb3RvdHlwZS5hbnkgPSBmdW5jdGlvbiAoKSB7XG4gICAgcmV0dXJuIGFueSh0aGlzKTtcbn07XG5cbi8qKlxuICogV2FpdHMgZm9yIGFsbCBwcm9taXNlcyB0byBiZSBzZXR0bGVkLCBlaXRoZXIgZnVsZmlsbGVkIG9yXG4gKiByZWplY3RlZC4gIFRoaXMgaXMgZGlzdGluY3QgZnJvbSBgYWxsYCBzaW5jZSB0aGF0IHdvdWxkIHN0b3BcbiAqIHdhaXRpbmcgYXQgdGhlIGZpcnN0IHJlamVjdGlvbi4gIFRoZSBwcm9taXNlIHJldHVybmVkIGJ5XG4gKiB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nVuY3Rpb24oKXtcbiAgICAgICAgICAgIHZhciBwb3N0cHJvY2VzcyA9IGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gcG9zdHByb2Nlc3MuYWxsKCk7XG4gICAgICAgICAgICB9O1xuICAgICAgICAgICAgcG9zdHByb2Nlc3MuYWxsID0gZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICAgIHJldHVybiBncm91cC5hbGwoKTtcbiAgICAgICAgICAgIH07XG4gICAgICAgICAgICB2YXIgcG9zdHByb2Nlc3NvcnMgPSByZWR1Y3Rpby5wb3N0cHJvY2Vzc29ycztcbiAgICAgICAgICAgIE9iamVjdC5rZXlzKHBvc3Rwcm9jZXNzb3JzKS5mb3JFYWNoKGZ1bmN0aW9uIChuYW1lKSB7XG4gICAgICAgICAgICAgICAgcG9zdHByb2Nlc3NbbmFtZV0gPSBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAgICAgICAgIHZhciBfYWxsID0gcG9zdHByb2Nlc3MuYWxsO1xuICAgICAgICAgICAgICAgICAgICB2YXIgYXJncyA9IFtdLnNsaWNlLmNhbGwoYXJndW1lbnRzKTtcbiAgICAgICAgICAgICAgICAgICAgcG9zdHByb2Nlc3MuYWxsID0gZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHBvc3Rwcm9jZXNzb3JzW25hbWVdKF9hbGwsIGYsIHApLmFwcGx5KG51bGwsIGFyZ3MpO1xuICAgICAgICAgICAgICAgICAgICB9O1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gcG9zdHByb2Nlc3M7XG4gICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgcmV0dXJuIHBvc3Rwcm9jZXNzO1xuICAgICAgICB9O1xuICAgIH07XG59XG5cbm1vZHVsZS5leHBvcnRzID0gcG9zdFByb2Nlc3M7XG4iLCJtb2R1bGUuZXhwb3J0cyA9IGZ1bmN0aW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uc1xuICAgICAgcmV0dXJuIFByb21pc2UuYWxsKF8ubWFwKHNlcnZpY2UuY29sdW1ucywgZGlzcG9zZUNvbHVtbikpXG4gICAgICAgIC50aGVuKGZ1bmN0aW9uKCkge1xuICAgICAgICAgIHNlcnZpY2UuY29sdW1ucyA9IFtdXG4gICAgICAgICAgcmV0dXJuIHNlcnZpY2VcbiAgICAgICAgfSlcblxuICAgIH1cblxuXG4gICAgcmV0dXJuIFByb21pc2UuYWxsKF8ubWFwKGRlZiwgZnVuY3Rpb24oZCkge1xuICAgICAgICBpZiAoXy5pc09iamVjdChkKSkge1xuICAgICAgICAgIGQgPSBkLmtleVxuICAgICAgICB9XG4gICAgICAgIC8vIENsZWFyIHRoZSBjb2x1bW5cbiAgICAgICAgdmFyIGNvbHVtbiA9IF8ucmVtb3ZlKHNlcnZpY2UuY29sdW1ucywgZnVuY3Rpb24oYykge1xuICAgICAgICAgIGlmIChfLmlzQXJyYXkoZCkpIHtcbiAgICAgICAgICAgIHJldHVybiAhXy54b3IoYy5rZXksIGQpLmxlbmd0aFxuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAoYy5rZXkgPT09IGQpIHtcbiAgICAgICAgICAgIGlmIChjLmR5bmFtaWNSZWZlcmVuY2UpIHtcbiAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlXG4gICAgICAgICAgICB9XG4gICAgICAgICAgICByZXR1cm4gdHJ1ZVxuICAgICAgICAgIH1cbiAgICAgICAgfSlbMF1cblxuICAgICAgICBpZiAoIWNvbHVtbikge1xuICAgICAgICAgIC8vIGNvbnNvbGUuaW5mbygnQXR0ZW1wdGVkIHRvIGNsZWFyIGEgY29sdW1uIHRoYXQgaXMgcmVxdWlyZWQgZm9yIGFub3RoZXIgcXVlcnkhJywgYylcbiAgICAgICAgICByZXR1cm5cbiAgICAgICAgfVxuXG4gICAgICAgIGRpc3Bvc2VDb2x1bW4oY29sdW1uKVxuICAgICAgfSkpXG4gICAgICAudGhlbihmdW5jdGlvbigpI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IHZhbHVlIHRvIHRoZSBzdWJHZXR0ZXJcbiAgICAgICAgcmV0dXJuIGZ1bmN0aW9uKGQpIHtcbiAgICAgICAgICBkID0gZFtrZXldXG4gICAgICAgICAgcmV0dXJuIGdldFN1YihkLCBnZXRTdWIpXG4gICAgICAgIH1cblxuICAgICAgfSlcblxuICAgICAgLy8gQWxsIG9iamVjdCBleHByZXNzaW9ucyBhcmUgYmFzaWNhbGx5IEFORCdzXG4gICAgICAvLyBSZXR1cm4gQU5EIHdpdGggYSBtYXAgb2YgdGhlIHN1YkdldHRlcnNcbiAgICAgIGlmIChpc0FnZ3JlZ2F0aW9uKSB7XG4gICAgICAgIGlmIChzdWJHZXR0ZXJzLmxlbmd0aCA9PT0gMSkge1xuICAgICAgICAgIHJldHVybiBmdW5jdGlvbihkKSB7XG4gICAgICAgICAgICByZXR1cm4gc3ViR2V0dGVyc1swXShkKVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gZnVuY3Rpb24oZCkge1xuICAgICAgICAgIHJldHVybiBfLm1hcChzdWJHZXR0ZXJzLCBmdW5jdGlvbihnZXRTdWIpIHtcbiAgICAgICAgICAgIHJldHVybiBnZXRTdWIoZClcbiAgICAgICAgICB9KVxuICAgICAgICB9XG4gICAgICB9XG4gICAgICByZXR1cm4gZnVuY3Rpb24oZCkge1xuICAgICAgICByZXR1cm4gZXhwcmVzc2lvbnMuJGFuZChkLCBmdW5jdGlvbihkKSB7XG4gICAgICAgICAgcmV0dXJuIF8ubWFwKHN1YkdldHRlcnMsIGZ1bmN0aW9uKGdldFN1Yikge1xuICAgICAgICAgICAgcmV0dXJuIGdldFN1YihkKVxuICAgICAgICAgIH0pXG4gICAgICAgIH0pXG4gICAgICB9XG4gICAgfVxuXG4gICAgY29uc29sZS5sb2coJ25vIGV4cHJlc3Npb24gZm91bmQgZm9yICcsIG9iailcbiAgICByZXR1cm4gZmFsc2VcbiAgfVxufVxuIiwiJ3VzZSBzdHJpY3QnXG5c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3I7XG4gICAgICB9XG4gICAgfSBlbHNlIHtcbiAgICAgIC8vV2FpdCB1bnRpbCB0aGUgcHJldmlvdXMgcHJvbWlzZSBoYXMgcmVzb2x2ZWQgb3IgcmVqZWN0ZWQgdG8gZXhlY3V0ZSB0aGUgbmV4dCB0YXNrXG4gICAgICBuZXh0UHJvbWlzZSA9IHByZXZQcm9taXNlLnRoZW4oXG4gICAgICAgIC8qc3VjY2VzcyovXG4gICAgICAgIGZ1bmN0aW9uKGRhdGEpIHtcbiAgICAgICAgICBpZiAoIXN1Y2Nlc3MpIHtcbiAgICAgICAgICAgIHJldHVybiBkYXRhO1xuICAgICAgICAgIH1cbiAgICAgICAgICB2YXIgcmV0ID0gc3VjY2VzcyhkYXRhKTtcbiAgICAgICAgICBpZiAoIWlzUHJvbWlzZUxpa2UocmV0KSkge1xuICAgICAgICAgICAgZXJyb3IubWVzc2FnZSA9IFwiVGFzayBcIiArIGtleSArIFwiIGRpZCBub3QgcmV0dXJuIGEgcHJvbWlzZS5cIjtcbiAgICAgICAgICAgIHRocm93IGVycm9yO1xuICAgICAgICAgIH1cbiAgICAgICAgICByZXR1cm4gcmV0O1xuICAgICAgICB9LFxuICAgICAgICAvKmZhaWx1cmUqL1xuICAgICAgICBmdW5jdGlvbihyZWFzb24pIHtcbiAgICAgICAgICBpZiAoIWZhaWwpIHtcbiAgICAgICAgICAgIHJldHVybiBQcm9taXNlLnJlamVjdChyZWFzb24pO1xuICAgICAgICAgIH1cbiAgICAgICAgICB2YXIgcmV0ID0gZmFpbChyZWFzb24pO1xuICAgICAgICAgIGlmICghaXNQcm9taXNlTGlrZShyZXQpKSB7XG4gICAgICAgICAgICBlcnJvci5tZXNzYWdlID0gXCJGYWlsIGZvciB0YXNrIFwiICsga2V5ICsgXCIgZGlkIG5vdCByZXR1cm4gYSBwcm9taXNlLlwiO1xuICAgICAgICAgICAgdGhyb3cgZXJyb3I7XG4gICAgICAgICAgfVxuICAgICAgICAgIHJldHVybiByZXQ7XG4g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GlvbigpIHtcbiAgICAgICAgICAgIHJldHVybiBxLmdyb3VwLmRpc3Bvc2UoKVxuICAgICAgICAgIH0pXG4gICAgICAgICAgLnRoZW4oZnVuY3Rpb24oKSB7XG4gICAgICAgICAgICBxLmNvbHVtbi5xdWVyaWVzLnNwbGljZShxLmNvbHVtbi5xdWVyaWVzLmluZGV4T2YocSksIDEpXG4gICAgICAgICAgICBpZiAoIXEuY29sdW1uLnF1ZXJpZXMubGVuZ3RoKSB7XG4gICAgICAgICAgICAgIHJldHVybiBzZXJ2aWNlLmNsZWFyKHEuY29sdW1uLmtleSlcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9KVxuICAgICAgICAgIC50aGVuKGZ1bmN0aW9uKCkge1xuICAgICAgICAgICAgcmV0dXJuIHNlcnZpY2VcbiAgICAgICAgICB9KVxuICAgICAgfVxuXG4gICAgICBmdW5jdGlvbiBwb3N0QWdncmVnYXRlTWV0aG9kV3JhcChwb3N0TWV0aG9kKSB7XG4gICAgICAgIHJldHVybiBmdW5jdGlvbigpIHtcbiAgICAgICAgICB2YXIgYXJncyA9IEFycmF5LnByb3RvdHlwZS5zbGljZS5jYWxsKGFyZ3VtZW50cyk7XG4gICAgICAgICAgdmFyIHN1YiA9IHt9XG4gICAgICAgICAgbmV3UXVlcnlPYmooc3ViLCBxKVxuICAgICAgICAgIGFyZ3MudW5zaGlmdChzdWIsIHEpXG5cbiAgICAgICAgICBxLnBvc3RBZ2dyZWdhdGlvbnMucHVzaChmdW5jdGlvbigpIHtcbiAgICAgICAgICAgIFByb21pc2UucmVzb2x2ZShwb3N0TWV0aG9kLmFwcGx5KG51bGwsIGFyZ3MpKVxuICAgICAgICAgICAgICAudGhlbihwb3N0QWdncmVnYXRlQ2hpbGRyZW4pXG4gICAgICAgICAgfSlcblxuICAgICAgICAgIHJldHVybiBQcm9taXNlLnJlc29sdmUocG9zdE1ldGhvZC5hcHBseShudWxsLCBhcmdzKSlcbiAgICAgICAgICAgIC50aGVuKHBvc3R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N0YXJ0ZWQuXG4gICAgICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICAgICAgfSBlbHNlIGlmIChncmVhdFZhbHVlIDwgcGl2b3RWYWx1ZTEpIHtcbiAgICAgICAgICAgICAgLy8gVHJpcGxlIGV4Y2hhbmdlLlxuICAgICAgICAgICAgICBhW2tdID0gYVtsZXNzXTtcbiAgICAgICAgICAgICAgYVtsZXNzKytdID0gYVtncmVhdF07XG4gICAgICAgICAgICAgIGFbZ3JlYXQtLV0gPSBlaztcbiAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICBhW2tdID0gYVtncmVhdF07XG4gICAgICAgICAgICAgIGFbZ3JlYXQtLV0gPSBlaztcbiAgICAgICAgICAgICAgLy8gTm90ZTogaWYgZ3JlYXQgPCBrIHRoZW4gd2Ugd2lsbCBleGl0IHRoZSBvdXRlciBsb29wIGFuZCBmaXhcbiAgICAgICAgICAgICAgLy8gaW52YXJpYW50IDIgKHdoaWNoIHdlIGp1c3QgdmlvbGF0ZWQpLlxuICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9IGVsc2Uge1xuXG4gICAgICAvLyBXZSBwYXJ0aXRpb24gdGhlIGxpc3QgaW50byB0aHJlZSBwYXJ0czpcbiAgICAgIC8vICAxLiA8IHBpdm90MVxuICAgICAgLy8gIDIuID49IHBpdm90MSAmJiA8PSBwaXZvdDJcbiAgICAgIC8vICAzLiA+IHBpdm90MlxuICAgICAgLy9cbiAgICAgIC8vIER1cmluZyB0aGUgbG9vcCB3ZSBoYXZlOlxuICAgICAgLy8gWyB8IDwgcGl2b3QxIHwgPj0gcGl2b3QxICYmIDw9IHBpdm90MiB8IHVucGFydGl0aW9uZWQgIHwgPiBwaXZvdDIgIHwgXVxuICAgICAgLy8gIF4gICAgICAgICAgICBeICAgICAgICAgICAgICAgICAgICAgICAgXiAgICAgICAgICAgICAgXiAgICAgICAgICAgICBeXG4gICAgICAvLyBsZWZ0ICAgICAgICAgbGVzcyAgICAgICAgICAgICAgICAgICAgIGsgICAgICAgICAgICAgIGdyZWF0ICAgICAgICByaWdodFxuICAgICAgLy9cbiAgICAgIC8vIGFbbGVmdF0gYW5kIGFbcmlnaHRdIGFyZSB1bmRlZmluZWQgYW5kIGFyZSBmaWxsZWQgYWZ0ZXIgdGhlXG4gICAgICAvLyBwYXJ0aXRpb25pbmcuXG4gICAgICAvL1xuICAgICAgLy8gSW52YXJpYW50czpcbiAgICAgIC8vICAgMS4gZm9yIHggaW4gXWxlZnQsIGxlc3NbIDogeCA8IHBpdm90MVxuICAgICAgLy8gICAyLiBmb3IgeCBpbiBbbGVzcywga1sgOiBwaXZvdDEgPD0geCAmJiB4IDw9IHBpdm90MlxuICAgICAgLy8gICAzLiBmb3IgeCBpbiBdZ3JlYXQsIHJpZ2h0WyA6IHggPiBwaXZvdDJcbiAgICAgIGZvciAodmFyIGsgPSBsZXNzOyBrIDw9IGdyZWF0OyBrKyspIHtcbiAgICAgICAgdmFyIGVrID0gYVtrXSwgeGsgPSBmKGVrKTtcbiAgICAgICAgaWYgKHhrIDwgcGl2b3RWYWx1ZTEpIHtcbiAgICAgICAgICBpZiAoayAhPT0gbGVzcykge1xuICAgICAgICAgICAgYVtrXSA9IGFbbGVzc107XG4gICAgICAgICAgICBhW2xlc3NdID0gZWs7XG4gICAgICAgICAgfVxuICAgICAgICAgICsrbGVzcztcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICBpZiAoeGsgPiBwaXZvdFZhbHVlMikge1xuICAgICAgICAgICAgd2hpbGUgKHRydWUpIHtcbiAgICAgICAgICAgICAgdmFyIGdyZWF0VmFsdWUgPSBmKGFbZ3JlYXRdKTtcbiAgICAgICAgICAgICAgaWYgKGdyZWF0VmFsdWUgPiBwaXZvdFZhbHVlMikge1xuICAgICAgICAgICAgICAgIGdyZWF0LS07XG4gICAgICAgICAgICAgICAgaWYgKGdyZWF0IDwgaykgYnJlYWs7XG4gICAgICAgICAgICAgICAgLy8gVGhpcyBpcyB0aGUgb25seSBsb2NhdGlvbiBpbnNpZGUgdGhlIGxvb3Agd2hlcmUgYSBuZXdcbiAgICAgICAgICAgICAgICAvLyBpdGVyYXRpb24gaXMgc3RhcnRlZC5cbiAgICAgICAgICAgICAgICBjb250aW51ZTtcbiAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAvLyBhW2dyZWF0XSA8PSBwaXZvdDIuXG4gICAgICAgICAgICAgICAgaWYgKGdyZWF0VmFsdWUgPCBwaXZvdFZhbHVlMSkge1xuICAgICAgICAgICAgICAgICAgLy8gVHJpcGxlIGV4Y2hhbmdlLlxuICAgICAgICAgICAgICAgICAgYVtrXSA9IGFbbGVzc107XG4gICAgICAgICAgICAgICAgICBhW2xlc3MrK10gPSBhW2dyZWF0XTtcbiAgICAgICAgICAgICAgICAgIGFbZ3JlYXQtLV0gPSBlaztcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgLy8gYVtncmVhdF0gPj0gcGl2b3QxLlxuICAgICAgICAgICAgICAgICAgYVtrXSA9IGFbZ3JlYXRdO1xuICAgICAgICAgICAgICAgICAgYVtncmVhdC0tXSA9IGVrO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfVxuICAgIH1cblxuICAgIC8vIE1vdmUgcGl2b3RzIGludG8gdGhlaXIgZmluYWwgcG9zaXRpb25zLlxuICAgIC8vIFdlIHNocnVuayB0aGUgbGlzdCBmcm9tIGJvdGggc2lkZXMgKGFbbGVmdF0gYW5kIGFbcmlnaHRdIGhhdmVcbiAgICAvLyBtZWFuaW5nbGVzcyB2YWx1ZXMgaW4gdGhlbSkgYW5kIG5vdyB3ZS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AgICAgICAgICAgICAgICAgIF4gICAgICAgICAgICAgIF5cbiAgICAgIC8vICAgICAgICAgICAgbGVzcyAgICAgICAgICAgICAgICAgICAgIGsgICAgICAgICAgICAgIGdyZWF0XG4gICAgICAvL1xuICAgICAgLy8gSW52YXJpYW50czpcbiAgICAgIC8vICAgMS4gZm9yIHggaW4gWyAqLCBsZXNzWyA6IHggPT0gcGl2b3QxXG4gICAgICAvLyAgIDIuIGZvciB4IGluIFtsZXNzLCBrWyA6IHBpdm90MSA8IHggJiYgeCA8IHBpdm90MlxuICAgICAgLy8gICAzLiBmb3IgeCBpbiBdZ3JlYXQsICogXSA6IHggPT0gcGl2b3QyXG4gICAgICBmb3IgKHZhciBrID0gbGVzczsgayA8PSBncmVhdDsgaysrKSB7XG4gICAgICAgIHZhciBlayA9IGFba10sIHhrID0gZihlayk7XG4gICAgICAgIGlmICh4ayA8PSBwaXZvdFZhbHVlMSAmJiB4ayA+PSBwaXZvdFZhbHVlMSkge1xuICAgICAgICAgIGlmIChrICE9PSBsZXNzKSB7XG4gICAgICAgICAgICBhW2tdID0gYVtsZXNzXTtcbiAgICAgICAgICAgIGFbbGVzc10gPSBlaztcbiAgICAgICAgICB9XG4gICAgICAgICAgbGVzcysrO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIGlmICh4ayA8PSBwaXZvdFZhbHVlMiAmJiB4ayA+PSBwaXZvdFZhbHVlMikge1xuICAgICAgICAgICAgd2hpbGUgKHRydWUpIHtcbiAgICAgICAgICAgICAgdmFyIGdyZWF0VmFsdWUgPSBmKGFbZ3JlYXRdKTtcbiAgICAgICAgICAgICAgaWYgKGdyZWF0VmFsdWUgPD0gcGl2b3RWYWx1ZTIgJiYgZ3JlYXRWYWx1ZSA+PSBwaXZvdFZhbHVlMikge1xuICAgICAgICAgICAgICAgIGdyZWF0LS07XG4gICAgICAgICAgICAgICAgaWYgKGdyZWF0IDwgaykgYnJlYWs7XG4gICAgICAgICAgICAgICAgLy8gVGhpcyBpcyB0aGUgb25seSBsb2NhdGlvbiBpbnNpZGUgdGhlIGxvb3Agd2hlcmUgYSBuZXdcbiAgICAgICAgICAgICAgICAvLyBpdGVyYXRpb24gaXMgc3RhcnRlZC5cbiAgICAgICAgICAgICAgICBjb250aW51ZTtcbiAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAvLyBhW2dyZWF0XSA8IHBpdm90Mi5cbiAgICAgICAgICAgICAgICBpZiAoZ3JlYXRWYWx1ZSA8IHBpdm90VmFsdWUxKSB7XG4gICAgICAgICAgICAgICAgICAvLyBUcmlwbGUgZXhjaGFuZ2UuXG4gICAgICAgICAgICAgICAgICBhW2tdID0gYVtsZXNzXTtcbiAgICAgICAgICAgICAgICAgIGFbbGVzcysrXSA9IGFbZ3JlYXRdO1xuICAgICAgICAgICAgICAgICAgYVtncmVhdC0tXSA9IGVrO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAvLyBhW2dyZWF0XSA9PSBwaXZvdDEuXG4gICAgICAgICAgICAgICAgICBhW2tdID0gYVtncmVhdF07XG4gICAgICAgICAgICAgICAgICBhW2dyZWF0LS1dID0gZWs7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG4gICAgfVxuXG4gICAgLy8gVGhlIHNlY29uZCBwYXJ0aXRpb24gaGFzIG5vdyBiZWVuIGNsZWFyZWQgb2YgcGl2b3QgZWxlbWVudHMgYW5kIGxvb2tzXG4gICAgLy8gYXMgZm9sbG93czpcbiAgICAvLyBbICAqICB8ICA+IHBpdm90MSAmJiA8IHBpdm90MiAgfCAqIF1cbiAgICAvLyAgICAgICAgXiAgICAgICAgICAgICAgICAgICAgICBeXG4gICAgLy8gICAgICAgbGVzcyAgICAgICAgICAgICAgICAgIGdyZWF0XG4gICAgLy8gU29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AgICAgICAgLy8gTm93IGhhbmRsZSBlbXB0eSByb3dzLlxuICAgICAgICBpZihib3VuZHNbMF0gPT09IDAgJiYgYm91bmRzWzFdID09PSBpbmRleC5sZW5ndGgpIHtcbiAgICAgICAgICBmb3IoaSA9IDA7IGkgPCBpdGVyYWJsZXNFbXB0eVJvd3MubGVuZ3RoOyBpKyspIHtcbiAgICAgICAgICAgIGlmKChmaWx0ZXJzW29mZnNldF1bayA9IGl0ZXJhYmxlc0VtcHR5Um93c1tpXV0gJiBvbmUpKSB7XG4gICAgICAgICAgICAgIC8vIFdhcyBub3QgaW4gdGhlIGZpbHRlciwgc28gc2V0IHRoZSBmaWx0ZXIgYW5kIGFkZFxuICAgICAgICAgICAgICBmaWx0ZXJzW29mZnNldF1ba10gXj0gb25lO1xuICAgICAgICAgICAgICBhZGRlZC5wdXNoKGspO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAvLyBmaWx0ZXIgaW4gcGxhY2UgLSByZW1vdmUgZW1wdHkgcm93cyBpZiBuZWNlc3NhcnlcbiAgICAgICAgICBmb3IoaSA9IDA7IGkgPCBpdGVyYWJsZXNFbXB0eVJvd3MubGVuZ3RoOyBpKyspIHtcbiAgICAgICAgICAgIGlmKCEoZmlsdGVyc1tvZmZzZXRdW2sgPSBpdGVyYWJsZXNFbXB0eVJvd3NbaV1dICYgb25lKSkge1xuICAgICAgICAgICAgICAvLyBXYXMgaW4gdGhlIGZpbHRlciwgc28gc2V0IHRoZSBmaWx0ZXIgYW5kIHJlbW92ZVxuICAgICAgICAgICAgICBmaWx0ZXJzW29mZnNldF1ba10gXj0gb25lO1xuICAgICAgICAgICAgICByZW1vdmVkLnB1c2goayk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG5cbiAgICAgIGxvMCA9IGxvMTtcbiAgICAgIGhpMCA9IGhpMTtcbiAgICAgIGZpbHRlckxpc3R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gICAgICB2YXIgaSxcbiAgICAgICAgICBrLFxuICAgICAgICAgIHgsXG4gICAgICAgICAgYWRkZWQgPSBbXSxcbiAgICAgICAgICByZW1vdmVkID0gW10sXG4gICAgICAgICAgdmFsdWVJbmRleEFkZGVkID0gW10sXG4gICAgICAgICAgdmFsdWVJbmRleFJlbW92ZWQgPSBbXSxcbiAgICAgICAgICBpbmRleExlbmd0aCA9IGluZGV4Lmxlbmd0aDtcblxuICAgICAgaWYoIWl0ZXJhYmxlKSB7XG4gICAgICAgIGZvciAoaSA9IDA7IGkgPCBpbmRleExlbmd0aDsgKytpKSB7XG4gICAgICAgICAgaWYgKCEoZmlsdGVyc1tvZmZzZXRdW2sgPSBpbmRleFtpXV0gJiBvbmUpIF4gISEoeCA9IGYodmFsdWVzW2ldLCBpKSkpIHtcbiAgICAgICAgICAgIGlmICh4KSBhZGRlZC5wdXNoKGspO1xuICAgICAgICAgICAgZWxzZSByZW1vdmVkLnB1c2goayk7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG4gICAgICBcbiAgICAgIGlmKGl0ZXJhYmxlKSB7XG4gICAgICAgIGZvcihpPTA7IGkgPCBpbmRleExlbmd0aDsgKytpKSB7XG4gICAgICAgICAgaWYoZih2YWx1ZXNbaV0sIGkpKSB7XG4gICAgICAgICAgICBhZGRlZC5wdXNoKGluZGV4W2ldKTtcbiAgICAgICAgICAgIHZhbHVlSW5kZXhBZGRlZC5wdXNoKGkpO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByZW1vdmVkLnB1c2goaW5kZXhbaV0pO1xuICAgICAgICAgICAgdmFsdWVJbmRleFJlbW92ZWQucHVzaChpKTtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICAgIFxuICAgICAgaWYoIWl0ZXJhYmxlKSB7XG4gICAgICAgIGZvcihpPTA7IGk8YWRkZWQubGVuZ3RoOyBpKyspIHtcbiAgICAgICAgICBpZihmaWx0ZXJzW29m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3NbaV0pKSB7XG4gICAgICAgICAgICBhcnJheS5wdXNoKGRhdGFbal0pO1xuICAgICAgICAgICAgLS1rO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfVxuXG4gICAgICBpID0gbG8wO1xuXG4gICAgICB3aGlsZSAoaSA8IGhpMCAmJiBrID4gMCkge1xuICAgICAgICBpZiAoZmlsdGVycy56ZXJvKGogPSBpbmRleFtpXSkpIHtcbiAgICAgICAgICBhcnJheS5wdXNoKGRhdGFbal0pO1xuICAgICAgICAgIC0taztcbiAgICAgICAgfVxuICAgICAgICBpKys7XG4gICAgICB9XG5cbiAgICAgIHJldHVybiBhcnJheTtcbiAgICB9XG5cbiAgICAvLyBBZGRzIGEgbmV3IGdyb3VwIHRvIHRoaXMgZGltZW5zaW9uLCB1c2luZyB0aGUgc3BlY2lmaWVkIGtleSBmdW5jdGlvbi5cbiAgICBmdW5jdGlvbiBncm91cChrZXkpIHtcbiAgICAgIHZhciBncm91cCA9IHtcbiAgICAgICAgdG9wOiB0b3AsXG4gICAgICAgIGFsbDogYWxsLFxuICAgICAgICByZWR1Y2U6IHJlZHVjZSxcbiAgICAgICAgcmVkdWNlQ291bnQ6IHJlZHVjZUNvdW50LFxuICAgICAgICByZWR1Y2VTdW06IHJlZHVjZVN1bSxcbiAgICAgICAgb3JkZXI6IG9yZGVyLFxuICAgICAgICBvcmRlck5hdHVyYWw6IG9yZGVyTmF0dXJhbCxcbiAgICAgICAgc2l6ZTogc2l6ZSxcbiAgICAgICAgZGlzcG9zZTogZGlzcG9zZSxcbiAgICAgICAgcmVtb3ZlOiBkaXNwb3NlIC8vIGZvciBiYWNrd2FyZHMtY29tcGF0aWJpbGl0eVxuICAgICAgfTtcblxuICAgICAgLy8gRW5zdXJlIHRoYXQgdGhpcyBncm91cCB3aWxsIGJlIHJlbW92ZWQgd2hlbiB0aGUgZGltZW5zaW9uIGlzIHJlbW92ZWQuXG4gICAgICBkaW1lbnNpb25Hcm91cHMucHVzaChncm91c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gIC8vIEFkZCBhbnkgc2VsZWN0ZWQgcmVjb3JkcyBiZWxvbmdpbmcgdG8gdGhlIGFkZGVkIGdyb3VwLCB3aGlsZVxuICAgICAgICAgIC8vIGFkdmFuY2luZyB0aGUgbmV3IGtleSBhbmQgcG9wdWxhdGluZyB0aGUgYXNzb2NpYXRlZCBncm91cCBpbmRleC5cblxuICAgICAgICAgIHdoaWxlICh4MSA8PSB4KSB7XG4gICAgICAgICAgICBqID0gbmV3SW5kZXhbaTFdICsgKGl0ZXJhYmxlID8gbjBvbGQgOiBuMClcblxuXG4gICAgICAgICAgICBpZihpdGVyYWJsZSl7XG4gICAgICAgICAgICAgIGlmKGdyb3VwSW5kZXhbal0pe1xuICAgICAgICAgICAgICAgIGdyb3VwSW5kZXhbal0ucHVzaChrKVxuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIGVsc2V7XG4gICAgICAgICAgICAgICAgZ3JvdXBJbmRleFtqXSA9IFtrXVxuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBlbHNle1xuICAgICAgICAgICAgICBncm91cEluZGV4W2pdID0gaztcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgLy8gQWx3YXlzIGFkZCBuZXcgdmFsdWVzIHRvIGdyb3Vwcy4gT25seSByZW1vdmUgd2hlbiBub3QgaW4gZmlsdGVyLlxuICAgICAgICAgICAgLy8gVGhpcyBnaXZlcyBncm91cHMgZnVsbCBpbmZvcm1hdGlvbiBvbiBkYXRhIGxpZmUtY3ljbGUuXG4gICAgICAgICAgICBnLnZhbHVlID0gYWRkKGcudmFsdWUsIGRhdGFbal0sIHRydWUpO1xuICAgICAgICAgICAgaWYgKCFmaWx0ZXJzLnplcm9FeGNlcHQoaiwgb2Zmc2V0LCB6ZXJvKSkgZy52YWx1ZSA9IHJlbW92ZShnLnZhbHVlLCBkYXRhW2pdLCBmYWxzZSk7XG4gICAgICAgICAgICBpZiAoKytpMSA+PSBuMSkgYnJlYWs7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G4gICAgICAgIC8vIGNhbiBidWlsZCBhbiAndW5maWx0ZXJlZCcgdmlldyBldmVuIGlmIHRoZXJlIGFyZSBhbHJlYWR5IGZpbHRlcnMgaW5cbiAgICAgICAgLy8gcGxhY2Ugb24gb3RoZXIgZGltZW5zaW9ucy5cbiAgICAgICAgaWYoaXRlcmFibGUpe1xuICAgICAgICAgIGZvciAoaSA9IDA7IGkgPCBuOyArK2kpIHtcbiAgICAgICAgICAgIGZvciAoaiA9IDA7IGogPCBncm91cEluZGV4W2ldLmxlbmd0aDsgaisrKSB7XG4gICAgICAgICAgICAgIGcgPSBncm91cHNbZ3JvdXBJbmRleFtpXVtqXV07XG4gICAgICAgICAgICAgIGcudmFsdWUgPSByZWR1Y2VBZGQoZy52YWx1ZSwgZGF0YVtpXSwgdHJ1ZSwgaik7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICAgIGZvciAoaSA9IDA7IGkgPCBuOyArK2kpIHtcbiAgICAgICAgICAgIGlmICghZmlsdGVycy56ZXJvRXhjZXB0KGksIG9mZnNldCwgemVybykpIHtcbiAgICAgICAgICAgICAgZm9yIChqID0gMDsgaiA8IGdyb3VwSW5kZXhbaV0ubGVuZ3RoOyBqKyspIHtcbiAgICAgICAgICAgICAgICBnID0gZ3JvdXBzW2dyb3VwSW5kZXhbaV1bal1dO1xuICAgICAgICAgICAgICAgIGcudmFsdWUgPSByZWR1Y2VSZW1vdmUoZy52YWx1ZSwgZGF0YVtpXSwgZmFsc2UsIGopO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICAgIHJldHVybjtcbiAgICAgICAgfVxuXG4gICAgICAgIGZvciAoaSA9IDA7IGkgPCBuOyArK2kpIHtcbiAgICAgICAgICBnID0gZ3JvdXBzW2dyb3VwSW5kZXhbaV1dO1xuICAgICAgICAgIGcudmFsdWUgPSByZWR1Y2VBZGQoZy52YWx1ZSwgZGF0YVtpXSwgdHJ1ZSk7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gICAgICBmbHVzaGluZyA9IGZhbHNlO1xuICAgIH1cbiAgICAvLyBydW5zIGEgc2luZ2xlIGZ1bmN0aW9uIGluIHRoZSBhc3luYyBxdWV1ZVxuICAgIGZ1bmN0aW9uIHJ1blNpbmdsZSh0YXNrLCBkb21haW4pIHtcbiAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgIHRhc2soKTtcblxuICAgICAgICB9IGNhdGNoIChlKSB7XG4gICAgICAgICAgICBpZiAoaXNOb2RlSlMpIHtcbiAgICAgICAgICAgICAgICAvLyBJbiBub2RlLCB1bmNhdWdodCBleGNlcHRpb25zIGFyZSBjb25zaWRlcmVkIGZhdGFsIGVycm9ycy5cbiAgICAgICAgICAgICAgICAvLyBSZS10aHJvdyB0aGVtIHN5bmNocm9ub3VzbHkgdG8gaW50ZXJydXB0IGZsdXNoaW5nIVxuXG4gICAgICAgICAgICAgICAgLy8gRW5zdXJlIGNvbnRpbnVhdGlvbiBpZiB0aGUgdW5jYXVnaHQgZXhjZXB0aW9uIGlzIHN1cHByZXNzZWRcbiAgICAgICAgICAgICAgICAvLyBsaXN0ZW5pbmcgXCJ1bmNhdWdodEV4Y2VwdGlvblwiIGV2ZW50cyAoYXMgZG9tYWlucyBkb2VzKS5cbiAgICAgICAgICAgICAgICAvLyBDb250aW51ZSBpbiBuZXh0IGV2ZW50IHRvIGF2b2lkIHRpY2sgcmVjdXJzaW9uLlxuICAgICAgICAgICAgICAgIGlmIChkb21haW4pIHtcbiAgICAgICAgICAgICAgICAgICAgZG9tYWluLmV4aXQoKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgc2V0VGltZW91dChmbHVzaCwgMCk7XG4gICAgICAgICAgICAgICAgaWYgKGRvbWFpbikge1xuICAgICAgICAgICAgICAgICAgICBkb21haW4uZW50ZXIoKTtcbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICB0aHJvdyBlO1xuXG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIC8vIEluIGJyb3dzZXJzLCB1bmNhdWdodCBleGNlcHRpb25zIGFyZSBub3QgZmF0YWwuXG4gICAgICAgICAgICAgICAgLy8gUmUtdGhyb3cgdGhlbSBhc3luY2hyb25vdXNseSB0byBhdm9pZCBzbG93LWRvd25zLlxuICAgICAgICAgICAgICAgIHNldFRpbWVvdXQoZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICAgICAgICB0aHJvdyBlO1xuICAgICAgICAgICAgICAgIH0sIDApO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgaWYgKGRvbWFpbikge1xuICAgICAgICAgICAgZG9tYWluLmV4aXQoKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIG5leHRUaWNrID0gZnVuY3Rpb24gKHRhc2spIHtcbiAgICAgICAgdGFpbCA9IHRhaWwubmV4dCA9IHtcbiAgICAgICAgICAgIHRhc2s6IHRhc2ssXG4gICAgICAgICAgICBkb21haW46IGlzTm9kZUpTICYmIHByb2Nlc3MuZG9tYWluLFxuICAgICAgICAgICAgbmV4dDogbnVsbFxuICAgICAgICB9O1xuXG4gICAgICAgIGlmICghZmx1c2hpbmcpIHtcbiAgICAgICAgICAgIGZsdXNoaW5nID0gdHJ1ZTtcbiAgICAgICAgICAgIHJlcXVlc3RUaWNrKCk7XG4gICAgICAgIH1cbiAgICB9O1xuXG4gICAgaWYgKHR5cGVvZiBwcm9jZXNzID09PSBcIm9iamVjdFwiICYmXG4gICAgICAgIHByb2Nlc3MudG9TdHJpbmcoKSA9PT0gXCJbb2JqZWN0IHByb2Nlc3NdXCIgJiYgcHJvY2Vzcy5uZXh0VGljaykge1xuICAgICAgICAvLyBFbnN1cmUgUSBpcyBpbiBhIHJlYWwgTm9kZSBlbnZpcm9ubWVudCwgd2l0aCBhIGBwcm9jZXNzLm5leHRUaWNrYC5cbiAgICAgICAgLy8gVG8gc2VlIHRocm91Z2ggZmFrZSBOb2RlIGVudmlyb25tZW50czpcbi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pIHtcbiAgICAgICAgdmFyIGluZGV4ID0gMCxcbiAgICAgICAgICAgIGxlbmd0aCA9IHRoaXMubGVuZ3RoO1xuICAgICAgICAvLyBjb25jZXJuaW5nIHRoZSBpbml0aWFsIHZhbHVlLCBpZiBvbmUgaXMgbm90IHByb3ZpZGVkXG4gICAgICAgIGlmIChhcmd1bWVudHMubGVuZ3RoID09PSAxKSB7XG4gICAgICAgICAgICAvLyBzZWVrIHRvIHRoZSBmaXJzdCB2YWx1ZSBpbiB0aGUgYXJyYXksIGFjY291bnRpbmdcbiAgICAgICAgICAgIC8vIGZvciB0aGUgcG9zc2liaWxpdHkgdGhhdCBpcyBpcyBhIHNwYXJzZSBhcnJheVxuICAgICAgICAgICAgZG8ge1xuICAgICAgICAgICAgICAgIGlmIChpbmRleCBpbiB0aGlzKSB7XG4gICAgICAgICAgICAgICAgICAgIGJhc2lzID0gdGhpc1tpbmRleCsrXTtcbiAgICAgICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGlmICgrK2luZGV4ID49IGxlbmd0aCkge1xuICAgICAgICAgICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSB3aGlsZSAoMSk7XG4gICAgICAgIH1cbiAgICAgICAgLy8gcmVkdWNlXG4gICAgICAgIGZvciAoOyBpbmRleCA8IGxlbmd0aDsgaW5kZXgrKykge1xuICAgICAgICAgICAgLy8gYWNjb3VudCBmb3IgdGhlIHBvc3NpYmlsaXR5IHRoYXQgdGhlIGFycmF5IGlzIHNwYXJzZVxuICAgICAgICAgICAgaWYgKGluZGV4IGluIHRoaXMpIHtcbiAgICAgICAgICAgICAgICBiYXNpcyA9IGNhbGxiYWNrKGJhc2lzLCB0aGlzW2luZGV4XSwgaW5kZXgpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIHJldHVybiBiYXNpcztcbiAgIC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FrZVN0YWNrVHJhY2VMb25nKGV4Y2VwdGlvbiwgc2VsZik7XG4gICAgICAgICAgICB0cnkge1xuICAgICAgICAgICAgICAgIHJldHVybiByZWplY3RlZChleGNlcHRpb24pO1xuICAgICAgICAgICAgfSBjYXRjaCAobmV3RXhjZXB0aW9uKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIHJlamVjdChuZXdFeGNlcHRpb24pO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIHJldHVybiByZWplY3QoZXhjZXB0aW9uKTtcbiAgICB9XG5cbiAgICBmdW5jdGlvbiBfcHJvZ3Jlc3NlZCh2YWx1ZSkge1xuICAgICAgICByZXR1cm4gdHlwZW9mIHByb2dyZXNzZWQgPT09IFwiZnVuY3Rpb25cIiA/IHByb2dyZXNzZWQodmFsdWUpIDogdmFsdWU7XG4gICAgfVxuXG4gICAgUS5uZXh0VGljayhmdW5jdGlvbiAoKSB7XG4gICAgICAgIHNlbGYucHJvbWlzZURpc3BhdGNoKGZ1bmN0aW9uICh2YWx1ZSkge1xuICAgICAgICAgICAgaWYgKGRvbmUpIHtcbiAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBkb25lID0gdHJ1ZTtcblxuICAgICAgICAgICAgZGVmZXJyZWQucmVzb2x2ZShfZnVsZmlsbGVkKHZhbHVlKSk7XG4gICAgICAgIH0sIFwid2hlblwiLCBbZnVuY3Rpb24gKGV4Y2VwdGlvbikge1xuICAgICAgICAgICAgaWYgKGRvbmUpIHtcbiAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBkb25lID0gdHJ1ZTtcblxuICAgICAgICAgICAgZGVmZXJyZWQucmVzb2x2ZShfcmVqZWN0ZWQoZXhjZXB0aW9uKSk7XG4gICAgICAgIH1dKTtcbiAgICB9KTtcblxuICAgIC8vIFByb2dyZXNzIHByb3BhZ2F0b3IgbmVlZCB0byBiZSBhdHRh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XQgd2UnZCBhbHNvXG4gICAgICAgICAgICAvLyBsaWtlIHRvIG1ha2UgaXQgcG9zc2libGUgdG8gdXNlIGdlbmVyYXRvcnMgaW4gZGVwbG95ZWQgYnJvd3NlcnMsIHNvXG4gICAgICAgICAgICAvLyB3ZSBhbHNvIHN1cHBvcnQgUHl0aG9uLXN0eWxlIGdlbmVyYXRvcnMuICBBdCBzb21lIHBvaW50IHdlIGNhbiByZW1vdmVcbiAgICAgICAgICAgIC8vIHRoaXMgYmxvY2suXG5cbiAgICAgICAgICAgIGlmICh0eXBlb2YgU3RvcEl0ZXJhdGlvbiA9PT0gXCJ1bmRlZmluZWRcIikge1xuICAgICAgICAgICAgICAgIC8vIEVTNiBHZW5lcmF0b3JzXG4gICAgICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICAgICAgcmVzdWx0ID0gZ2VuZXJhdG9yW3ZlcmJdKGFyZyk7XG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZXhjZXB0aW9uKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiByZWplY3QoZXhjZXB0aW9uKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgaWYgKHJlc3VsdC5kb25lKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBRKHJlc3VsdC52YWx1ZSk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHdoZW4ocmVzdWx0LnZhbHVlLCBjYWxsYmFjaywgZXJyYmFjayk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAvLyBTcGlkZXJNb25rZXkgR2VuZXJhdG9yc1xuICAgICAgICAgICAgICAgIC8vIEZJWE1FOiBSZW1vdmUgdGhpcyBjYXNlIHdoZW4gU00gZG9lcyBFUzYgZ2VuZXJhdG9ycy5cbiAgICAgICAgICAgICAgICB0cnkge1xuICAgICAgICAgICAgICAgICAgICByZXN1bHQgPSBnZW5lcmF0b3JbdmVyYl0oYXJnKTtcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChleGNlcHRpb24pIHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKGlzU3RvcEl0ZXJhdGlvbihleGNlcHRpb24pKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gUShleGNlcHRpb24udmFsdWUpO1xuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHJlamVjdChleGNlcHRpb24pO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIHJldHVybiB3aGVuKHJlc3VsdCwgY2FsbGJhY2ssIGVycmJhY2spO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIHZhciBnZW5lcmF0b3IgPSBtYWtlR2VuZXJhdG9yLmFwcGx5KHRoaXMsIGFyZ3VtZW50cyk7XG4gICAgICAgIHZhciBjYWxsYmFjayA9IGNvbnRpbnVlci5iaW5kKGNvbnRpbnVlciwgXCJuZXh0XCIpO1xuICAgICAgICB2YXIgZXJyYmFjayA9IGNvbnRpbnVlci5iaW5kKGNvbnRpbnVlciwgXCJ0aHJvd1wiKTtcbiAgICAgICAgcmV0dXJuIGNhbGxiYWNrKCk7XG4gICAgfTtcbn1cblxuLyoqXG4gKiBUaGUgc3Bhd24gZnVuY3Rpb24gaXMgYSBzbWFsbCB3cmFwcGVyIGFyb3VuZCBhc3luYyB0aGF0IGltbWVkaWF0ZWx5XG4gKiBjYWxscyB0aGUgZ2VuZXJhdG9yIGFuZCBhbHNvIGVuZHMgdGhlIHByb21pc2UgY2hhaW4sIHNvIHRoYXQgYW55XG4gKiB1bmhhbmRsZWQgZXJyb3JzIGFyZSB0aHJvd24gaW5zdGVhZCBvZiBmb3J3YXJkZWQgdG8gdGhlIGVycm9yXG4gKiBoYW5kbGVyLiBUa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BwZW5kaW5nQ291bnQgPSAwO1xuICAgICAgICB2YXIgZGVmZXJyZWQgPSBkZWZlcigpO1xuICAgICAgICBhcnJheV9yZWR1Y2UocHJvbWlzZXMsIGZ1bmN0aW9uICh1bmRlZmluZWQsIHByb21pc2UsIGluZGV4KSB7XG4gICAgICAgICAgICB2YXIgc25hcHNob3Q7XG4gICAgICAgICAgICBpZiAoXG4gICAgICAgICAgICAgICAgaXNQcm9taXNlKHByb21pc2UpICYmXG4gICAgICAgICAgICAgICAgKHNuYXBzaG90ID0gcHJvbWlzZS5pbnNwZWN0KCkpLnN0YXRlID09PSBcImZ1bGZpbGxlZFwiXG4gICAgICAgICAgICApIHtcbiAgICAgICAgICAgICAgICBwcm9taXNlc1tpbmRleF0gPSBzbmFwc2hvdC52YWx1ZTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgKytwZW5kaW5nQ291bnQ7XG4gICAgICAgICAgICAgICAgd2hlbihcbiAgICAgICAgICAgICAgICAgICAgcHJvbWlzZSxcbiAgICAgICAgICAgICAgICAgICAgZnVuY3Rpb24gKHZhbHVlKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBwcm9taXNlc1tpbmRleF0gPSB2YWx1ZTtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmICgtLXBlbmRpbmdDb3VudCA9PT0gMCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRlZmVycmVkLnJlc29sdmUocHJvbWlzZXMpO1xuICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgICAgICBkZWZlcnJlZC5yZWplY3QsXG4gICAgICAgICAgICAgICAgICAgIGZ1bmN0aW9uIChwcm9ncmVzcykge1xuICAgICAgICAgICAgICAgICAgICAgICAgZGVmZXJyZWQubm90aWZ5KHsgaW5kZXg6IGluZGV4LCB2YWx1ZTogcHJvZ3Jlc3MgfSk7XG4gICAgICAgICAgICAgICAgICAg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RleCkge1xuICAgICAgICB2YXIgcHJvbWlzZSA9IHByb21pc2VzW2luZGV4XTtcblxuICAgICAgICBwZW5kaW5nQ291bnQrKztcblxuICAgICAgICB3aGVuKHByb21pc2UsIG9uRnVsZmlsbGVkLCBvblJlamVjdGVkLCBvblByb2dyZXNzKTtcbiAgICAgICAgZnVuY3Rpb24gb25GdWxmaWxsZWQocmVzdWx0KSB7XG4gICAgICAgICAgICBkZWZlcnJlZC5yZXNvbHZlKHJlc3VsdCk7XG4gICAgICAgIH1cbiAgICAgICAgZnVuY3Rpb24gb25SZWplY3RlZCgpIHtcbiAgICAgICAgICAgIHBlbmRpbmdDb3VudC0tO1xuICAgICAgICAgICAgaWYgKHBlbmRpbmdDb3VudCA9PT0gMCkge1xuICAgICAgICAgICAgICAgIGRlZmVycmVkLnJlamVjdChuZXcgRXJyb3IoXG4gICAgICAgICAgICAgICAgICAgIFwiQ2FuJ3QgZ2V0IGZ1bGZpbGxtZW50IHZhbHVlIGZyb20gYW55IHByb21pc2UsIGFsbCBcIiArXG4gICAgICAgICAgICAgICAgICAgIFwicHJvbWlzZXMgd2VyZSByZWplY3RlZC5cIlxuICAgICAgICAgICAgICAgICkpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIGZ1bmN0aW9uIG9uUHJvZ3Jlc3MocHJvZ3Jlc3MpIHtcbiAgICAgICAgICAgIGRlZmVycmVkLm5vdGlmeSh7XG4gICAgICAgICAgICAgICAgaW5kZXg6IGluZGV4LFxuICAgICAgICAgICAgICAgIHZhbHVlOiBwcm9ncmVzc1xuICAgICAgICAgICAgfSk7XG4gICAgICAgIH1cbiAgICB9LCB1bmRlZmluZWQpO1xuXG4gICAgcmV0dXJuIGRlZmVycmVkLnByb21pc2U7XG59XG5cblByb21pc2UucHJvdG90eXBlLmFueSA9IGZ1bmN0aW9uICgpIHtcbiAgICByZXR1cm4gYW55KHRoaXMpO1xufTtcblxuLyoqXG4gKiBXYWl0cyBmb3IgYWxsIHByb21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ljZSkge1xuICByZXR1cm4gZnVuY3Rpb24gY2xlYXIoZGVmKSB7XG5cbiAgICAvLyBDbGVhciBhIHNpbmdsZSBvciBtdWx0aXBsZSBjb2x1bW4gZGVmaW5pdGlvbnNcbiAgICBpZiAoZGVmKSB7XG4gICAgICBkZWYgPSBfLmlzQXJyYXkoZGVmKSA/IGRlZiA6IFtkZWZdXG4gICAgfVxuXG4gICAgaWYgKCFkZWYpIHtcbiAgICAgIC8vIENsZWFyIGFsbCBvZiB0aGUgY29sdW1uIGRlZmVuaXRpb25zXG4gICAgICByZXR1cm4gUHJvbWlzZS5hbGwoXy5tYXAoc2VydmljZS5jb2x1bW5zLCBkaXNwb3NlQ29sdW1uKSlcbiAgICAgICAgLnRoZW4oZnVuY3Rpb24oKSB7XG4gICAgICAgICAgc2VydmljZS5jb2x1bW5zID0gW11cbiAgICAgICAgICByZXR1cm4gc2VydmljZVxuICAgICAgICB9KVxuXG4gICAgfVxuXG5cbiAgICByZXR1cm4gUHJvbWlzZS5hbGwoXy5tYXAoZGVmLCBmdW5jdGlvbihkKSB7XG4gICAgICAgIGlmIChfLmlzT2JqZWN0KGQpKSB7XG4gICAgICAgICAgZCA9IGQua2V5XG4gICAgICAgIH1cbiAgICAgICAgLy8gQ2xlYXIgdGhlIGNvbHVtblxuICAgICAgICB2YXIgY29sdW1uID0gXy5yZW1vdmUoc2VydmljZS5jb2x1bW5zLCBmdW5jdGlvbihjKSB7XG4gICAgICAgICAgaWYgKF8uaXNBcnJheShkKSkge1xuICAgICAgICAgICAgcmV0dXJuICFfLnhvcihjLmtleSwgZCkubGVuZ3RoXG4gICAgICAgICAgfVxuICAgICAgICAgIGlmIChjLmtleSA9PT0gZCkge1xuICAgICAgICAgICAgaWYgKGMuZHluYW1pY1JlZmVyZW5jZSkge1xuICAgICAgICAgICAgICByZXR1cm4gZmFsc2VcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHJldHVybiB0cnVlXG4gICAgICAgICAgfVxuICAgICAgICB9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BfLmZvckVhY2godGFza3MsIGZ1bmN0aW9uKHRhc2ssIGtleSkge1xuICAgIHZhciBzdWNjZXNzID0gdGFzay5zdWNjZXNzIHx8IHRhc2s7XG4gICAgdmFyIGZhaWwgPSB0YXNrLmZhaWw7XG4gICAgdmFyIG5vdGlmeSA9IHRhc2subm90aWZ5O1xuICAgIHZhciBuZXh0UHJvbWlzZTtcblxuICAgIC8vRmlyc3QgdGFza1xuICAgIGlmICghcHJldlByb21pc2UpIHtcbiAgICAgIG5leHRQcm9taXNlID0gc3VjY2VzcygpO1xuICAgICAgaWYgKCFpc1Byb21pc2VMaWtlKG5leHRQcm9taXNlKSkge1xuICAgICAgICBlcnJvci5tZXNzYWdlID0gXCJUYXNrIFwiICsga2V5ICsgXCIgZGlkIG5vdCByZXR1cm4gYSBwcm9taXNlLlwiO1xuICAgICAgICB0aHJvdyBlcnJvcjtcbiAgICAgIH1cbiAgICB9IGVsc2Uge1xuICAgICAgLy9XYWl0IHVudGlsIHRoZSBwcmV2aW91cyBwcm9taXNlIGhhcyByZXNvbHZlZCBvciByZWplY3RlZCB0byBleGVjdXRlIHRoZSBuZXh0IHRhc2tcbiAgICAgIG5leHRQcm9taXNlID0gcHJldlByb21pc2UudGhlbihcbiAgICAgICAgLypzdWNjZXNzKi9cbiAgICAgICAgZnVuY3Rpb24oZGF0YSkge1xuICAgICAgICAgIGlmICghc3VjY2Vzcykge1xuICAgICAgICAgICAgcmV0dXJuIGRhdGE7XG4gICAgICAgICAgfVxuICAgICAgICAgIHZhciByZXQgPSBzdWNjZXNzKGRhdGEpO1xuICAgICAgICAgIGlmICghaXNQcm9taXNlTGlrZShyZXQpKSB7XG4gICAgICAgICAgICBlcnJvci5tZXNzYWdlID0gXCJUYXNrIFwiICsga2V5ICsgXCIgZGlkIG5vdCByZXR1cm4gYSBwcm9taXNlLlwiO1xuICAgICAgICAgICAgdGhyb3cgZXJyb3I7XG4gICAgICAgICAgfVxuICAgICAgICAgIHJldHVybiByZXQ7XG4g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NldCl7XG4gICAgICAgIGlmKCFfLmlzVW5kZWZpbmVkKHNldCkpe1xuICAgICAgICAgIHEubG9ja2VkID0gISFzZXRcbiAgICAgICAgICByZXR1cm5cbiAgICAgICAgfVxuICAgICAgICBxLmxvY2tlZCA9IHRydWVcbiAgICAgIH1cblxuICAgICAgZnVuY3Rpb24gdW5sb2NrKCl7XG4gICAgICAgIHEubG9ja2VkID0gZmFsc2VcbiAgICAgIH1cblxuICAgICAgZnVuY3Rpb24gY2xlYXJRdWVyeSgpIHtcbiAgICAgICAgXy5mb3JFYWNoKHEucmVtb3ZlTGlzdG5lcnMsIGZ1bmN0aW9uKGwpIHtcbiAgICAgICAgICBsKClcbiAgICAgICAgfSlcbiAgICAgICAgcmV0dXJuIFByb21pc2UudHJ5KGZ1bmN0aW9uKCkge1xuICAgICAgICAgICAgcmV0dXJuIHEuZ3JvdXAuZGlzcG9zZSgpXG4gICAgICAgICAgfSlcbiAgICAgICAgICAudGhlbihmdW5jdGlvbigpIHtcbiAgICAgICAgICAgIHEuY29sdW1uLnF1ZXJpZXMuc3BsaWNlKHEuY29sdW1uLnF1ZXJpZXMuaW5kZXhPZihxKSwgMSlcbiAgICAgICAgICAgIGlmICghcS5jb2x1bW4ucXVlcmllcy5sZW5ndGgpIHtcbiAgICAgICAgICAgICAgcmV0dXJuIHNlcnZpY2UuY2xlYXIocS5jb2x1bW4ua2V5KVxuICAgICAgICAgICAgfVxuICAgICAgICAgIH0pXG4gICAgICAgICAgLnRoZW4oZnVuY3Rpb24oKSB7XG4gICAgICAgICAgICByZXR1cm4gc2VydmljZVxuICAgICAgICAgIH0pXG4gICAgICB9XG5cbiAgICAgIGZ1bmN0aW9uIHBvc3RBZ2dyZWdhdGVNZXRob2RXcmFwKHBvc3RNZXRob2QpIHtcbiAgICAgICAgcmV0dXJuIGZ1bmN0aW9uKCkge1xuICAgICAgICAgIHZhciBhcmdzID0gQXJyYXkucHJvdG90eXBlLnNsaWNlLmNhbGwoYXJndW1lbnRzK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goY2IpXG4gICAgcmV0dXJuIGZ1bmN0aW9uKCl7XG4gICAgICBzZXJ2aWNlLmRhdGFMaXN0ZW5lcnMuc3BsaWNlKHNlcnZpY2UuZGF0YUxpc3RlbmVycy5pbmRleE9mKGNiKSwgMSlcbiAgICB9XG4gIH1cblxuICBmdW5jdGlvbiBvbkZpbHRlcihjYil7XG4gICAgc2VydmljZS5maWx0ZXJMaXN0ZW5lcnMucHVzaChjYilcbiAgICByZXR1cm4gZnVuY3Rpb24oKXtcbiAgICAgIHNlcnZpY2UuZmlsdGVyTGlzdGVuZXJzLnNwbGljZShzZXJ2aWNlLmZpbHRlckxpc3RlbmVycy5pbmRleE9mKGNiKSwgMSlcbiAgICB9XG4gIH1cbn1cbiJdfQ== diff --git a/universe.min.js b/universe.min.js index 3d7a28b..cbeca7b 100644 --- a/universe.min.js +++ b/universe.min.js @@ -1,3 +1,3 @@ !function(n){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=n();else if("function"==typeof define&&define.amd)define([],n);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.universe=n()}}(function(){var n;return function e(n,t,r){function i(o,c){if(!t[o]){if(!n[o]){var a="function"==typeof require&&require;if(!c&&a)return a(o,!0);if(u)return u(o,!0);var s=new Error("Cannot find module '"+o+"'");throw s.code="MODULE_NOT_FOUND",s}var f=t[o]={exports:{}};n[o][0].call(f.exports,function(e){var t=n[o][1][e];return i(t?t:e)},f,f.exports,e,n,t,r)}return t[o].exports}for(var u="function"==typeof require&&require,o=0;or;++r)u[r]=n[e[r]];return u}function r(n){function e(e,t,r,i){for(;i>r;){var u=r+i>>>1;n(e[u])r;){var u=r+i>>>1;t>>1)+1;--u>0;)r(n,u,i,e);return n}function t(n,e,t){for(var i,u=t-e;--u>0;)i=n[e],n[e]=n[e+u],n[e+u]=i,r(n,1,u,e);return n}function r(e,t,r,i){for(var u,o=e[--i+t],c=n(o);(u=t<<1)<=r&&(r>u&&n(e[i+u])>n(e[i+u+1])&&u++,!(c<=n(e[i+u])));)e[i+t]=e[i+u],t=u;e[i+t]=o}return e.sort=t,e}function o(n){function e(e,r,i,u){var o,c,a,s,f=new Array(u=Math.min(i-r,u));for(c=0;u>c;++c)f[c]=e[r++];if(t(f,0,u),i>r){o=n(f[0]);do(a=n(s=e[r])>o)&&(f[0]=s,o=n(t(f,0,u)[0]));while(++ri;++i){for(var u=i,o=e[i],c=n(o);u>t&&n(e[u-1])>c;--u)e[u]=e[u-1];e[u]=o}return e}return e}function a(n){function e(n,e,i){return(T>i-e?r:t)(n,e,i)}function t(t,r,i){var u,o=(i-r)/6|0,c=r+o,a=i-1-o,s=r+i-1>>1,f=s-o,l=s+o,d=t[c],p=n(d),v=t[f],h=n(v),m=t[s],y=n(m),g=t[l],x=n(g),k=t[a],b=n(k);p>h&&(u=d,d=v,v=u,u=p,p=h,h=u),x>b&&(u=g,g=k,k=u,u=x,x=b,b=u),p>y&&(u=d,d=m,m=u,u=p,p=y,y=u),h>y&&(u=v,v=m,m=u,u=h,h=y,y=u),p>x&&(u=d,d=g,g=u,u=p,p=x,x=u),y>x&&(u=m,m=g,g=u,u=y,y=x,x=u),h>b&&(u=v,v=k,k=u,u=h,h=b,b=u),h>y&&(u=v,v=m,m=u,u=h,h=y,y=u),x>b&&(u=g,g=k,k=u,u=x,x=b,b=u);var j=v,w=h,A=g,O=x;t[c]=d,t[f]=t[r],t[s]=m,t[l]=t[i-1],t[a]=k;var L=r+1,S=i-2,R=O>=w&&w>=O;if(R)for(var q=L;S>=q;++q){var E=t[q],$=n(E);if(w>$)q!==L&&(t[q]=t[L],t[L]=E),++L;else if($>w)for(;;){var I=n(t[S]);{if(!(I>w)){if(w>I){t[q]=t[L],t[L++]=t[S],t[S--]=E;break}t[q]=t[S],t[S--]=E;break}S--}}}else for(var q=L;S>=q;q++){var E=t[q],$=n(E);if(w>$)q!==L&&(t[q]=t[L],t[L]=E),++L;else if($>O)for(;;){var I=n(t[S]);{if(!(I>O)){w>I?(t[q]=t[L],t[L++]=t[S],t[S--]=E):(t[q]=t[S],t[S--]=E);break}if(S--,q>S)break}}}if(t[r]=t[L-1],t[L-1]=j,t[i-1]=t[S+1],t[S+1]=A,e(t,r,L-1),e(t,S+2,i),R)return t;if(c>L&&S>a){for(var T,I;(T=n(t[L]))<=w&&T>=w;)++L;for(;(I=n(t[S]))<=O&&I>=O;)--S;for(var q=L;S>=q;q++){var E=t[q],$=n(E);if(w>=$&&$>=w)q!==L&&(t[q]=t[L],t[L]=E),L++;else if(O>=$&&$>=O)for(;;){var I=n(t[S]);{if(!(O>=I&&I>=O)){w>I?(t[q]=t[L],t[L++]=t[S],t[S--]=E):(t[q]=t[S],t[S--]=E);break}if(S--,q>S)break}}}}return e(t,L,S+1)}var r=c(n);return e}function s(n){for(var e=new Array(n),t=-1;++tt;)n[t++]=0;return n}function d(n,e){if(e>32)throw new Error("invalid array width!");return n}function p(n){this.length=n,this.subarrays=1,this.width=8,this.masks={0:0},this[0]=C(n)}function v(n,e){return function(t){var r=t.length;return[n.left(t,e,0,r),n.right(t,e,0,r)]}}function h(n,e){var t=e[0],r=e[1];return function(e){var i=e.length;return[n.left(e,t,0,i),n.left(e,r,0,i)]}}function m(n){return[0,n.length]}function y(){return null}function g(){return 0}function x(n){return n+1}function b(n){return n-1}function j(n){return function(e,t){return e+ +n(t)}}function w(n){return function(e,t){return e-n(t)}}function A(){function n(n){var e=T,t=n.length;return t&&(I=I.concat(n),E.lengthen(T+=t),P.forEach(function(r){r(n,e,t)}),q("dataAdded")),$}function r(){for(var n=O(T,T),e=[],t=0,r=0;T>t;++t)E.zero(t)?e.push(t):n[t]=r++;C.forEach(function(n){n(-1,-1,[],e,!0)}),N.forEach(function(e){e(n)});for(var t=0,r=0;T>t;++t)E.zero(t)||(t!==r&&(E.copy(r,t),I[r]=I[t]),++r);I.length=T=r,E.truncate(r),q("dataRemoved")}function c(n,r){function c(e,u,o){if(r){for(yn=0,v=0,k=[],i=0;iv+p;v++)tn[v+p]=rn[v]}for(i=0;i0t;++t)E.zero(e=X[t])||(t!==r&&(H[r]=H[t]),X[r]=n[e],++r);for(H.length=r;T>r;)X[r++]=0;var i=dn(H);hn=i[0],mn=i[1]}function d(n){var e=n[0],t=n[1];if(sn)return sn=null,B(function(n,r){return r>=e&&t>r},0===n[0]&&n[1]===X.length),hn=e,mn=t,fn;var i,u,o,c=[],a=[],s=[],f=[];if(hn>e)for(i=e,u=Math.min(hn,t);u>i;++i)c.push(X[i]),s.push(i);else if(e>hn)for(i=hn,u=Math.min(e,mn);u>i;++i)a.push(X[i]),f.push(i);if(t>mn)for(i=Math.max(e,mn),u=t;u>i;++i)c.push(X[i]),s.push(i);else if(mn>t)for(i=Math.max(hn,t),u=mn;u>i;++i)a.push(X[i]),f.push(i);if(r){var l=[],d=[];for(i=0;it;++t)!(E[G][i=X[t]]&Q)^!!(u=n(H[t],t))&&(u?o.push(i):c.push(i));if(r)for(t=0;f>t;++t)n(H[t],t)?(o.push(X[t]),a.push(t)):(c.push(X[t]),s.push(t));if(r){var l=[],d=[];for(t=0;t=hn&&n>0;)E.zero(e=X[i])&&(t.push(I[e]),--n);if(r)for(i=0;i0;i++)E.zero(e=an[i])&&(t.push(I[e]),--n);return t}function D(n){var e,t,i=[];if(r)for(e=0;e0;e++)E.zero(t=an[e])&&(i.push(I[t]),--n);for(e=hn;mn>e&&n>0;)E.zero(t=X[e])&&(i.push(I[t]),--n),e++;return i}function V(n){function c(e,u,o,c){function a(){return r?void W++:void(++W===J&&(b=F(b,_<<=1),U=F(U,_),J=S(_)))}r&&(n0old=o,o=H.length-e.length,c=e.length);var p,v,h,m,g,x,k=P,b=r?[]:O(W,J),j=K,w=D,A=V,L=W,R=0,q=0;for(en&&(j=A=y),en&&(w=A=y),P=new Array(W),W=0,U=r?L>1?U:[]:L>1?z(U,T):O(T,J),L&&(h=(v=k[0]).key);c>q&&!((m=n(e[q]))>=m);)++q;for(;c>q;){for(v&&m>=h?(g=v,x=h,b[R]=W,(v=k[++R])&&(h=v.key)):(g={key:m,value:A()},x=m),P[W]=g;x>=m&&(p=u[q]+(r?n0old:o),r?U[p]?U[p].push(W):U[p]=[W]:U[p]=W,g.value=j(g.value,I[p],!0),E.zeroExcept(p,G,Y)||(g.value=w(g.value,I[p],!1)),!(++q>=c));)m=n(e[q]);a()}for(;L>R;)P[b[R]=W]=k[R++],a();if(r)for(i=0;iR)if(r)U=t(U,b,!0);else for(R=0;o>R;++R)U[R]=b[U[R]];p=C.indexOf(Z),W>1?(Z=s,nn=l):(!W&&tn&&(W=1,P=[{key:null,value:A()}]),1===W?(Z=f,nn=d):(Z=y,nn=y),U=null),C[p]=Z}function a(){if(W>1){for(var n=W,e=P,t=O(n,n),r=0,i=0;T>r;++r)E.zero(r)||(t[U[i]=U[r]]=1,++i);for(P=[],W=0,r=0;n>r;++r)t[r]&&(t[r]=W++,P.push(e[r]));if(W>1)for(var r=0;i>r;++r)U[r]=t[U[r]];else U=null;C[C.indexOf(Z)]=W>1?(nn=l,Z=s):1===W?(nn=d,Z=f):nn=Z=y}else if(1===W){if(tn)return;for(var r=0;T>r;++r)if(!E.zero(r))return;P=[],W=0,C[C.indexOf(Z)]=Z=nn=y}}function s(n,e,t,i,u){if(!(n===Q&&e===G||en)){var o,c,a,s,f;if(r){for(o=0,s=t.length;s>o;++o)if(E.zeroExcept(a=t[o],G,Y))for(c=0;co;++o)if(E.onlyExcept(a=i[o],G,Y,e,n))for(c=0;co;++o)E.zeroExcept(a=t[o],G,Y)&&(f=P[U[a]],f.value=K(f.value,I[a],!1));for(o=0,s=i.length;s>o;++o)E.onlyExcept(a=i[o],G,Y,e,n)&&(f=P[U[a]],f.value=D(f.value,I[a],u))}}}function f(n,e,t,r,i){if(!(n===Q&&e===G||en)){var u,o,c,a=P[0];for(u=0,c=t.length;c>u;++u)E.zeroExcept(o=t[u],G,Y)&&(a.value=K(a.value,I[o],!1));for(u=0,c=r.length;c>u;++u)E.onlyExcept(o=r[u],G,Y,e,n)&&(a.value=D(a.value,I[o],i))}}function l(){var n,e,t;for(n=0;W>n;++n)P[n].value=V();if(r){for(n=0;T>n;++n)for(e=0;en;++n)if(!E.zeroExcept(n,G,Y))for(e=0;en;++n)t=P[U[n]],t.value=K(t.value,I[n],!0);for(n=0;T>n;++n)E.zeroExcept(n,G,Y)||(t=P[U[n]],t.value=D(t.value,I[n],!1))}}function d(){var n,e=P[0];for(e.value=V(),n=0;T>n;++n)e.value=K(e.value,I[n],!0);for(n=0;T>n;++n)E.zeroExcept(n,G,Y)||(e.value=D(e.value,I[n],!1))}function p(){return en&&(nn(),en=!1),P}function v(n){var e=M(p(),0,P.length,n);return B.sort(e,0,e.length)}function h(n,e,t){return K=n,D=e,V=t,en=!0,$}function m(){return h(x,b,g)}function k(n){return h(j(n),w(n),g)}function A(n){function e(e){return n(e.value)}return M=o(e),B=u(e),$}function L(){return A(e)}function R(){return W}function q(){var n=C.indexOf(Z);return n>=0&&C.splice(n,1),n=pn.indexOf(c),n>=0&&pn.splice(n,1),n=N.indexOf(a),n>=0&&N.splice(n,1),$}var $={top:v,all:p,reduce:h,reduceCount:m,reduceSum:k,order:A,orderNatural:L,size:R,dispose:q,remove:q};vn.push($);var P,U,M,B,K,D,V,_=8,J=S(_),W=0,Z=y,nn=y,en=!0,tn=n===y;return arguments.length<1&&(n=e),C.push(Z),pn.push(c),N.push(a),c(H,X,0,T),m().orderNatural()}function _(){var n=V(y),e=n.all;return delete n.all,delete n.top,delete n.order,delete n.orderNatural,delete n.size,n.value=function(){return e()[0].value},n}function J(){vn.forEach(function(n){n.dispose()});var n=P.indexOf(c);return n>=0&&P.splice(n,1),n=P.indexOf(s),n>=0&&P.splice(n,1),n=N.indexOf(f),n>=0&&N.splice(n,1),E.masks[G]&=Y,U()}var Q,Y,G,H,X,W,Z,nn,en,tn,rn,un,on,cn,an,sn,fn={filter:p,filterExact:A,filterRange:$,filterFunction:M,filterAll:U,top:K,bottom:D,group:V,groupAll:_,dispose:J,remove:J},ln=a(function(n){return nn[n]}),dn=m,pn=[],vn=[],hn=0,mn=0,yn=0;P.unshift(c),P.push(s),N.push(f);var gn=E.add();return G=gn.offset,Q=gn.one,Y=~Q,c(I,0,T),s(I,0,T),fn}function s(){function n(n,e){var t;if(!p)for(t=e;T>t;++t)a=s(a,I[t],!0),E.zero(t)||(a=f(a,I[t],!1))}function e(n,e,t,r,i){var u,o,c;if(!p){for(u=0,c=t.length;c>u;++u)E.zero(o=t[u])&&(a=s(a,I[o],i));for(u=0,c=r.length;c>u;++u)E.only(o=r[u],e,n)&&(a=f(a,I[o],i))}}function t(){var n;for(a=l(),n=0;T>n;++n)a=s(a,I[n],!0),E.zero(n)||(a=f(a,I[n],!1))}function r(n,e,t){return s=n,f=e,l=t,p=!0,d}function i(){return r(x,b,g)}function u(n){return r(j(n),w(n),g)}function o(){return p&&(t(),p=!1),a}function c(){var t=C.indexOf(e);return t>=0&&C.splice(t),t=P.indexOf(n),t>=0&&P.splice(t),d}var a,s,f,l,d={reduce:r,reduceCount:i,reduceSum:u,value:o,dispose:c,remove:c},p=!0;return C.push(e),P.push(n),n(I,0,T),i()}function f(){return T}function d(){return I}function A(n){return"function"!=typeof n?void console.warn("onChange callback parameter must be a function!"):(U.push(n),function(){U.splice(U.indexOf(n),1)})}function q(n){for(var e=0;ee?C:65537>e?P:N)(n)}function L(n){for(var e=O(n,n),t=-1;++t=e)return n;var t=new n.constructor(e);return t.set(n),t},F=function(n,e){var t;switch(e){case 16:t=P(n.length);break;case 32:t=N(n.length);break;default:throw new Error("invalid array width!")}return t.set(n),t}),p.prototype.lengthen=function(n){var e,t;for(e=0,t=this.subarrays;t>e;++e)this[e]=z(this[e],n);this.length=n},p.prototype.add=function(){var n,e,t,r,i;for(r=0,i=this.subarrays;i>r;++r)if(n=this.masks[r],e=this.width-32*r,t=~n&-~n,!(e>=32)||t)return 32>e&&t&1<t;++t)this[t][n]=this[t][e]},p.prototype.truncate=function(n){var e,t;for(e=0,t=this.subarrays;t>e;++e){for(var r=this.length-1;r>=n;r--)this[e][r]=0;this[e].length=n}this.length=n},p.prototype.zero=function(n){var e,t;for(e=0,t=this.subarrays;t>e;++e)if(this[e][n])return!1;return!0},p.prototype.zeroExcept=function(n,e,t){var r,i;for(r=0,i=this.subarrays;i>r;++r)if(r===e?this[r][n]&t:this[r][n])return!1;return!0},p.prototype.only=function(n,e,t){var r,i;for(r=0,i=this.subarrays;i>r;++r)if(this[r][n]!=(r===e?t:0))return!1;return!0},p.prototype.onlyExcept=function(n,e,t,r,i){var u,o,c;for(o=0,c=this.subarrays;c>o;++o)if(u=this[o][n],o===e&&(u&=t),u!=(o===r?i:0))return!1;return!0},n.crossfilter=A}("undefined"!=typeof t&&t||this)},{}],2:[function(n,e,t){e.exports=n("./crossfilter").crossfilter},{"./crossfilter":1}],3:[function(n,e,t){function r(){f=!1,c.length?s=c.concat(s):l=-1,s.length&&i()}function i(){if(!f){var n=setTimeout(r);f=!0;for(var e=s.length;e;){for(c=s,s=[];++l1)for(var t=1;t=J&&fn>=r}function s(){if(K)try{throw new Error}catch(n){var e=n.stack.split("\n"),t=e[0].indexOf("@")>0?e[1]:e[2],r=c(t);if(!r)return;return V=r[0],r[1]}}function f(n,e,t){return function(){return"undefined"!=typeof console&&"function"==typeof console.warn&&console.warn(e+" is deprecated, use "+t+" instead.",new Error("").stack),n.apply(n,arguments)}}function l(n){return n instanceof h?n:x(n)?R(n):S(n)}function d(){function n(n){e=n,u.source=n,X(t,function(e,t){l.nextTick(function(){n.promiseDispatch.apply(n,t)})},void 0),t=void 0,r=void 0}var e,t=[],r=[],i=nn(d.prototype),u=nn(h.prototype);if(u.promiseDispatch=function(n,i,u){var o=H(arguments);t?(t.push(o),"when"===i&&u[1]&&r.push(u[1])):l.nextTick(function(){e.promiseDispatch.apply(e,o)})},u.valueOf=function(){if(t)return u;var n=y(e);return g(n)&&(e=n),n},u.inspect=function(){return e?e.inspect():{state:"pending"}},l.longStackSupport&&K)try{throw new Error}catch(o){u.stack=o.stack.substring(o.stack.indexOf("\n")+1)}return i.promise=u,i.resolve=function(t){e||n(l(t))},i.fulfill=function(t){e||n(S(t))},i.reject=function(t){e||n(L(t))},i.notify=function(n){e||X(r,function(e,t){l.nextTick(function(){t(n)})},void 0)},i}function p(n){if("function"!=typeof n)throw new TypeError("resolver must be a function.");var e=d();try{n(e.resolve,e.reject,e.notify)}catch(t){e.reject(t)}return e.promise}function v(n){return p(function(e,t){for(var r=0,i=n.length;i>r;r++)l(n[r]).then(e,t)})}function h(n,e,t){void 0===e&&(e=function(n){return L(new Error("Promise does not support operation: "+n))}),void 0===t&&(t=function(){return{state:"unknown"}});var r=nn(h.prototype);if(r.promiseDispatch=function(t,i,u){var o;try{o=n[i]?n[i].apply(r,u):e.call(r,i,u)}catch(c){o=L(c)}t&&t(o)},r.inspect=t,t){var i=t();"rejected"===i.state&&(r.exception=i.reason),r.valueOf=function(){var n=t();return"pending"===n.state||"rejected"===n.state?r:n.value}}return r}function m(n,e,t,r){return l(n).then(e,t,r)}function y(n){if(g(n)){var e=n.inspect();if("fulfilled"===e.state)return e.value}return n}function g(n){return n instanceof h}function x(n){return t(n)&&"function"==typeof n.then}function k(n){return g(n)&&"pending"===n.inspect().state}function b(n){return!g(n)||"fulfilled"===n.inspect().state}function j(n){return g(n)&&"rejected"===n.inspect().state}function w(){on.length=0,cn.length=0,sn||(sn=!0)}function A(n,t){sn&&("object"==typeof e&&"function"==typeof e.emit&&l.nextTick.runAfter(function(){-1!==W(cn,n)&&(e.emit("unhandledRejection",t,n),an.push(n))}),cn.push(n),t&&"undefined"!=typeof t.stack?on.push(t.stack):on.push("(no stack) "+t))}function O(n){if(sn){var t=W(cn,n);-1!==t&&("object"==typeof e&&"function"==typeof e.emit&&l.nextTick.runAfter(function(){var r=W(an,n);-1!==r&&(e.emit("rejectionHandled",on[t],n),an.splice(r,1))}),cn.splice(t,1),on.splice(t,1))}}function L(n){var e=h({when:function(e){return e&&O(this),e?e(n):this}},function(){return this},function(){return{state:"rejected",reason:n}});return A(e,n),e}function S(n){return h({when:function(){return n},get:function(e){return n[e]},set:function(e,t){n[e]=t},"delete":function(e){delete n[e]},post:function(e,t){return null===e||void 0===e?n.apply(void 0,t):n[e].apply(n,t)},apply:function(e,t){return n.apply(e,t)},keys:function(){return tn(n)}},void 0,function(){return{state:"fulfilled",value:n}})}function R(n){var e=d();return l.nextTick(function(){try{n.then(e.resolve,e.reject,e.notify)}catch(t){e.reject(t)}}),e.promise}function q(n){return h({isDef:function(){}},function(e,t){return P(n,e,t)},function(){return l(n).inspect()})}function E(n,e,t){return l(n).spread(e,t)}function $(n){return function(){function e(n,e){var o;if("undefined"==typeof StopIteration){try{o=t[n](e)}catch(c){return L(c)}return o.done?l(o.value):m(o.value,i,u)}try{o=t[n](e)}catch(c){return r(c)?l(c.value):L(c)}return m(o,i,u)}var t=n.apply(this,arguments),i=e.bind(e,"next"),u=e.bind(e,"throw");return i()}}function I(n){l.done(l.async(n)())}function T(n){throw new _(n)}function C(n){return function(){return E([this,N(arguments)],function(e,t){return n.apply(e,t)})}}function P(n,e,t){return l(n).dispatch(e,t)}function N(n){return m(n,function(n){var e=0,t=d();return X(n,function(r,i,u){var o;g(i)&&"fulfilled"===(o=i.inspect()).state?n[u]=o.value:(++e,m(i,function(r){n[u]=r,0===--e&&t.resolve(n)},t.reject,function(n){t.notify({index:u,value:n})}))},void 0),0===e&&t.resolve(n),t.promise})}function z(n){if(0===n.length)return l.resolve();var e=l.defer(),t=0;return X(n,function(r,i,u){function o(n){e.resolve(n)}function c(){t--,0===t&&e.reject(new Error("Can't get fulfillment value from any promise, all promises were rejected."))}function a(n){e.notify({index:u,value:n})}var s=n[u];t++,m(s,o,c,a)},void 0),e.promise}function F(n){return m(n,function(n){return n=Z(n,l),m(N(Z(n,function(n){return m(n,Q,Q)})),function(){return n})})}function U(n){return l(n).allSettled()}function M(n,e){return l(n).then(void 0,void 0,e)}function B(n,e){return l(n).nodeify(e)}var K=!1;try{throw new Error}catch(D){K=!!D.stack}var V,_,J=s(),Q=function(){},Y=function(){function n(){for(var n,e;r.next;)r=r.next,n=r.task,r.task=void 0,e=r.domain,e&&(r.domain=void 0,e.enter()),t(n,e);for(;a.length;)n=a.pop(),t(n);u=!1}function t(e,t){try{e()}catch(r){if(c)throw t&&t.exit(),setTimeout(n,0),t&&t.enter(),r;setTimeout(function(){throw r},0)}t&&t.exit()}var r={task:void 0,next:null},i=r,u=!1,o=void 0,c=!1,a=[];if(Y=function(n){i=i.next={task:n,domain:c&&e.domain,next:null},u||(u=!0,o())},"object"==typeof e&&"[object process]"===e.toString()&&e.nextTick)c=!0,o=function(){e.nextTick(n)};else if("function"==typeof setImmediate)o="undefined"!=typeof window?setImmediate.bind(window,n):function(){setImmediate(n)};else if("undefined"!=typeof MessageChannel){var s=new MessageChannel;s.port1.onmessage=function(){o=f,s.port1.onmessage=n,n()};var f=function(){s.port2.postMessage(0)};o=function(){setTimeout(n,0),f()}}else o=function(){setTimeout(n,0)};return Y.runAfter=function(n){a.push(n),u||(u=!0,o())},Y}(),G=Function.call,H=n(Array.prototype.slice),X=n(Array.prototype.reduce||function(n,e){var t=0,r=this.length;if(1===arguments.length)for(;;){if(t in this){e=this[t++];break}if(++t>=r)throw new TypeError}for(;r>t;t++)t in this&&(e=n(e,this[t],t));return e}),W=n(Array.prototype.indexOf||function(n){for(var e=0;e2?n.resolve(H(arguments,1)):n.resolve(t)}},l.Promise=p,l.promise=p,p.race=v,p.all=N,p.reject=L,p.resolve=l,l.passByCopy=function(n){return n},h.prototype.passByCopy=function(){return this},l.join=function(n,e){return l(n).join(e)},h.prototype.join=function(n){return l([this,n]).spread(function(n,e){if(n===e)return n;throw new Error("Can't join: not the same: "+n+" "+e)})},l.race=v,h.prototype.race=function(){return this.then(l.race)},l.makePromise=h,h.prototype.toString=function(){return"[object Promise]"},h.prototype.then=function(n,e,t){function r(e){try{return"function"==typeof n?n(e):e}catch(t){return L(t)}}function u(n){if("function"==typeof e){i(n,c);try{return e(n)}catch(t){return L(t)}}return L(n)}function o(n){return"function"==typeof t?t(n):n}var c=this,a=d(),s=!1;return l.nextTick(function(){c.promiseDispatch(function(n){s||(s=!0,a.resolve(r(n)))},"when",[function(n){s||(s=!0,a.resolve(u(n)))}])}),c.promiseDispatch(void 0,"when",[void 0,function(n){var e,t=!1;try{e=o(n)}catch(r){if(t=!0,!l.onerror)throw r;l.onerror(r)}t||a.notify(e)}]),a.promise},l.tap=function(n,e){return l(n).tap(e)},h.prototype.tap=function(n){return n=l(n),this.then(function(e){return n.fcall(e).thenResolve(e)})},l.when=m,h.prototype.thenResolve=function(n){return this.then(function(){return n})},l.thenResolve=function(n,e){return l(n).thenResolve(e)},h.prototype.thenReject=function(n){return this.then(function(){throw n})},l.thenReject=function(n,e){return l(n).thenReject(e)},l.nearer=y,l.isPromise=g,l.isPromiseAlike=x,l.isPending=k,h.prototype.isPending=function(){return"pending"===this.inspect().state},l.isFulfilled=b,h.prototype.isFulfilled=function(){return"fulfilled"===this.inspect().state},l.isRejected=j,h.prototype.isRejected=function(){return"rejected"===this.inspect().state};var on=[],cn=[],an=[],sn=!0;l.resetUnhandledRejections=w,l.getUnhandledReasons=function(){return on.slice()},l.stopUnhandledRejectionTracking=function(){w(),sn=!1},w(),l.reject=L,l.fulfill=S,l.master=q,l.spread=E,h.prototype.spread=function(n,e){return this.all().then(function(e){return n.apply(void 0,e)},e)},l.async=$,l.spawn=I,l["return"]=T,l.promised=C,l.dispatch=P,h.prototype.dispatch=function(n,e){var t=this,r=d();return l.nextTick(function(){t.promiseDispatch(r.resolve,n,e)}),r.promise},l.get=function(n,e){return l(n).dispatch("get",[e])},h.prototype.get=function(n){return this.dispatch("get",[n])},l.set=function(n,e,t){return l(n).dispatch("set",[e,t])},h.prototype.set=function(n,e){return this.dispatch("set",[n,e])},l.del=l["delete"]=function(n,e){return l(n).dispatch("delete",[e])},h.prototype.del=h.prototype["delete"]=function(n){return this.dispatch("delete",[n])},l.mapply=l.post=function(n,e,t){return l(n).dispatch("post",[e,t])},h.prototype.mapply=h.prototype.post=function(n,e){return this.dispatch("post",[n,e])},l.send=l.mcall=l.invoke=function(n,e){return l(n).dispatch("post",[e,H(arguments,2)])},h.prototype.send=h.prototype.mcall=h.prototype.invoke=function(n){return this.dispatch("post",[n,H(arguments,1)])},l.fapply=function(n,e){return l(n).dispatch("apply",[void 0,e])},h.prototype.fapply=function(n){return this.dispatch("apply",[void 0,n])},l["try"]=l.fcall=function(n){return l(n).dispatch("apply",[void 0,H(arguments,1)])},h.prototype.fcall=function(){return this.dispatch("apply",[void 0,H(arguments)])},l.fbind=function(n){var e=l(n),t=H(arguments,1);return function(){return e.dispatch("apply",[this,t.concat(H(arguments))])}},h.prototype.fbind=function(){var n=this,e=H(arguments);return function(){return n.dispatch("apply",[this,e.concat(H(arguments))])}},l.keys=function(n){return l(n).dispatch("keys",[])},h.prototype.keys=function(){return this.dispatch("keys",[])},l.all=N,h.prototype.all=function(){return N(this)},l.any=z,h.prototype.any=function(){return z(this)},l.allResolved=f(F,"allResolved","allSettled"),h.prototype.allResolved=function(){return F(this)},l.allSettled=U,h.prototype.allSettled=function(){return this.then(function(n){return N(Z(n,function(n){function e(){return n.inspect()}return n=l(n),n.then(e,e)}))})},l.fail=l["catch"]=function(n,e){return l(n).then(void 0,e)},h.prototype.fail=h.prototype["catch"]=function(n){return this.then(void 0,n)},l.progress=M,h.prototype.progress=function(n){return this.then(void 0,void 0,n)},l.fin=l["finally"]=function(n,e){return l(n)["finally"](e)},h.prototype.fin=h.prototype["finally"]=function(n){return n=l(n),this.then(function(e){return n.fcall().then(function(){return e})},function(e){return n.fcall().then(function(){throw e})})},l.done=function(n,e,t,r){return l(n).done(e,t,r)},h.prototype.done=function(n,t,r){var u=function(n){l.nextTick(function(){if(i(n,o),!l.onerror)throw n;l.onerror(n)})},o=n||t||r?this.then(n,t,r):this;"object"==typeof e&&e&&e.domain&&(u=e.domain.bind(u)),o.then(void 0,u)},l.timeout=function(n,e,t){return l(n).timeout(e,t)},h.prototype.timeout=function(n,e){var t=d(),r=setTimeout(function(){e&&"string"!=typeof e||(e=new Error(e||"Timed out after "+n+" ms"),e.code="ETIMEDOUT"),t.reject(e)},n);return this.then(function(n){clearTimeout(r),t.resolve(n)},function(n){clearTimeout(r),t.reject(n)},t.notify),t.promise},l.delay=function(n,e){return void 0===e&&(e=n,n=void 0),l(n).delay(e)},h.prototype.delay=function(n){return this.then(function(e){var t=d();return setTimeout(function(){t.resolve(e)},n),t.promise})},l.nfapply=function(n,e){return l(n).nfapply(e)},h.prototype.nfapply=function(n){var e=d(),t=H(n);return t.push(e.makeNodeResolver()),this.fapply(t).fail(e.reject),e.promise},l.nfcall=function(n){var e=H(arguments,1);return l(n).nfapply(e)},h.prototype.nfcall=function(){var n=H(arguments),e=d();return n.push(e.makeNodeResolver()),this.fapply(n).fail(e.reject),e.promise},l.nfbind=l.denodeify=function(n){var e=H(arguments,1);return function(){var t=e.concat(H(arguments)),r=d();return t.push(r.makeNodeResolver()),l(n).fapply(t).fail(r.reject),r.promise}},h.prototype.nfbind=h.prototype.denodeify=function(){var n=H(arguments);return n.unshift(this),l.denodeify.apply(void 0,n)},l.nbind=function(n,e){var t=H(arguments,2);return function(){function r(){return n.apply(e,arguments)}var i=t.concat(H(arguments)),u=d();return i.push(u.makeNodeResolver()),l(r).fapply(i).fail(u.reject),u.promise}},h.prototype.nbind=function(){var n=H(arguments,0);return n.unshift(this),l.nbind.apply(void 0,n)},l.nmapply=l.npost=function(n,e,t){return l(n).npost(e,t)},h.prototype.nmapply=h.prototype.npost=function(n,e){var t=H(e||[]),r=d();return t.push(r.makeNodeResolver()),this.dispatch("post",[n,t]).fail(r.reject),r.promise},l.nsend=l.nmcall=l.ninvoke=function(n,e){var t=H(arguments,2),r=d();return t.push(r.makeNodeResolver()),l(n).dispatch("post",[e,t]).fail(r.reject),r.promise},h.prototype.nsend=h.prototype.nmcall=h.prototype.ninvoke=function(n){var e=H(arguments,1),t=d();return e.push(t.makeNodeResolver()),this.dispatch("post",[n,e]).fail(t.reject),t.promise},l.nodeify=B,h.prototype.nodeify=function(n){return n?void this.then(function(e){l.nextTick(function(){n(null,e)})},function(e){l.nextTick(function(){n(e)})}):this},l.noConflict=function(){throw new Error("Q.noConflict only works when Q is used as a global")};var fn=s();return l})}).call(this,e("_process"))},{_process:3}],5:[function(n,e,t){function r(n,e){function t(n){if("string"==typeof n){var e=n,t=function(n){return n[e]};return t}return n}function u(n){if("string"==typeof n){var e=n,t=function(n){return+n[e]};return t}return n}n.fromObject=function(t){return arguments.length?(_assign(e,t), -n):e},n.toObject=function(){return e},n.count=function(t){return arguments.length?(e.count=t,n):e.count},n.sum=function(t){return arguments.length?(t=u(t),e.sum=t,n):e.sum},n.avg=function(t){return arguments.length?(t=u(t),"function"==typeof t?(e.sum&&console.warn("SUM aggregation is being overwritten by AVG aggregation"),e.sum=t,e.avg=!0,e.count=!0):e.avg=t,n):e.avg},n.exception=function(r){return arguments.length?(r=t(r),e.exceptionAccessor=r,n):e.exceptionAccessor},n.filter=function(t){return arguments.length?(e.filter=t,n):e.filter},n.valueList=function(r){return arguments.length?(r=t(r),e.valueList=r,n):e.valueList},n.median=function(t){return arguments.length?(t=u(t),"function"==typeof t&&(e.valueList&&console.warn("VALUELIST accessor is being overwritten by median aggregation"),e.valueList=t),e.median=t,n):e.median},n.min=function(t){return arguments.length?(t=u(t),"function"==typeof t&&(e.valueList&&console.warn("VALUELIST accessor is being overwritten by median aggregation"),e.valueList=t),e.min=t,n):e.min},n.max=function(t){return arguments.length?(t=u(t),"function"==typeof t&&(e.valueList&&console.warn("VALUELIST accessor is being overwritten by median aggregation"),e.valueList=t),e.max=t,n):e.max},n.exceptionCount=function(r){return arguments.length?(r=t(r),"function"==typeof r?(e.sum&&console.warn("EXCEPTION accessor is being overwritten by exception count aggregation"),e.exceptionAccessor=r,e.exceptionCount=!0):e.exceptionCount=r,n):e.exceptionCount},n.exceptionSum=function(t){return arguments.length?(t=u(t),e.exceptionSum=t,n):e.exceptionSum},n.histogramValue=function(t){return arguments.length?(t=u(t),e.histogramValue=t,n):e.histogramValue},n.histogramBins=function(t){return arguments.length?(e.histogramThresholds=t,n):e.histogramThresholds},n.std=function(t){return arguments.length?(t=u(t),"function"==typeof t?(e.sumOfSquares=t,e.sum=t,e.count=!0,e.std=!0):e.std=t,n):e.std},n.sumOfSq=function(t){return arguments.length?(t=u(t),e.sumOfSquares=t,n):e.sumOfSquares},n.value=function(n,t){return arguments.length&&"string"==typeof n?(e.values||(e.values={}),e.values[n]={},e.values[n].parameters=i(),r(e.values[n],e.values[n].parameters),t&&(e.values[n].accessor=t),e.values[n]):void console.error("'value' requires a string argument.")},n.nest=function(r){return arguments.length?(r.map(t),e.nestKeys=r,n):e.nestKeys},n.alias=function(t){return arguments.length?(e.aliasKeys=t,n):e.aliasKeys},n.aliasProp=function(t){return arguments.length?(e.aliasPropKeys=t,n):e.aliasPropKeys},n.groupAll=function(t){return arguments.length?(e.groupAll=t,n):e.groupAll},n.dataList=function(t){return arguments.length?(e.dataList=t,n):e.dataList}}var i=n("./parameters.js");_assign=function(n){if(null==n)throw new TypeError("Cannot convert undefined or null to object");for(var e=Object(n),t=1;t0?t(n).avg=t(n).sum/t(n).count:t(n).avg=0,n}},remove:function(n,e,t){return function(n,r,i){return e&&e(n,r,i),t(n).count>0?t(n).avg=t(n).sum/t(n).count:t(n).avg=0,n}},initial:function(n,e){return function(t){return t=n(t),e(t).avg=0,t}}};e.exports=r},{}],9:[function(n,e,t){function r(n,e,t){t||(t=function(n){return n});var j={reduceAdd:e.reduceAdd,reduceRemove:e.reduceRemove,reduceInitial:e.reduceInitial};(n.count||n.std)&&(e.reduceAdd=u.add(e.reduceAdd,t),e.reduceRemove=u.remove(e.reduceRemove,t),e.reduceInitial=u.initial(e.reduceInitial,t)),n.sum&&(e.reduceAdd=o.add(n.sum,e.reduceAdd,t),e.reduceRemove=o.remove(n.sum,e.reduceRemove,t),e.reduceInitial=o.initial(e.reduceInitial,t)),n.avg&&(n.count&&n.sum?(e.reduceAdd=c.add(n.sum,e.reduceAdd,t),e.reduceRemove=c.remove(n.sum,e.reduceRemove,t),e.reduceInitial=c.initial(e.reduceInitial,t)):console.error("You must set .count(true) and define a .sum(accessor) to use .avg(true).")),n.exceptionCount&&(n.exceptionAccessor?(e.reduceAdd=p.add(n.exceptionAccessor,e.reduceAdd,t),e.reduceRemove=p.remove(n.exceptionAccessor,e.reduceRemove,t),e.reduceInitial=p.initial(e.reduceInitial,t)):console.error("You must define an .exception(accessor) to use .exceptionCount(true).")),n.exceptionSum&&(n.exceptionAccessor?(e.reduceAdd=v.add(n.exceptionAccessor,n.exceptionSum,e.reduceAdd,t),e.reduceRemove=v.remove(n.exceptionAccessor,n.exceptionSum,e.reduceRemove,t),e.reduceInitial=v.initial(e.reduceInitial,t)):console.error("You must define an .exception(accessor) to use .exceptionSum(accessor).")),(n.valueList||n.median||n.min||n.max)&&(e.reduceAdd=d.add(n.valueList,e.reduceAdd,t),e.reduceRemove=d.remove(n.valueList,e.reduceRemove,t),e.reduceInitial=d.initial(e.reduceInitial,t)),n.dataList&&(e.reduceAdd=b.add(n.dataList,e.reduceAdd,t),e.reduceRemove=b.remove(n.dataList,e.reduceRemove,t),e.reduceInitial=b.initial(e.reduceInitial,t)),n.median&&(e.reduceAdd=a.add(e.reduceAdd,t),e.reduceRemove=a.remove(e.reduceRemove,t),e.reduceInitial=a.initial(e.reduceInitial,t)),n.min&&(e.reduceAdd=s.add(e.reduceAdd,t),e.reduceRemove=s.remove(e.reduceRemove,t),e.reduceInitial=s.initial(e.reduceInitial,t)),n.max&&(e.reduceAdd=f.add(e.reduceAdd,t),e.reduceRemove=f.remove(e.reduceRemove,t),e.reduceInitial=f.initial(e.reduceInitial,t)),n.exceptionAccessor&&(e.reduceAdd=l.add(n.exceptionAccessor,e.reduceAdd,t),e.reduceRemove=l.remove(n.exceptionAccessor,e.reduceRemove,t),e.reduceInitial=l.initial(e.reduceInitial,t)),n.histogramValue&&n.histogramThresholds&&(e.reduceAdd=h.add(n.histogramValue,e.reduceAdd,t),e.reduceRemove=h.remove(n.histogramValue,e.reduceRemove,t),e.reduceInitial=h.initial(n.histogramThresholds,e.reduceInitial,t)),n.sumOfSquares&&(e.reduceAdd=m.add(n.sumOfSquares,e.reduceAdd,t),e.reduceRemove=m.remove(n.sumOfSquares,e.reduceRemove,t),e.reduceInitial=m.initial(e.reduceInitial,t)),n.std&&(n.sumOfSquares&&n.sum?(e.reduceAdd=y.add(e.reduceAdd,t),e.reduceRemove=y.remove(e.reduceRemove,t),e.reduceInitial=y.initial(e.reduceInitial,t)):console.error("You must set .sumOfSq(accessor) and define a .sum(accessor) to use .std(true). Or use .std(accessor).")),n.nestKeys&&(e.reduceAdd=g.add(n.nestKeys,e.reduceAdd,t),e.reduceRemove=g.remove(n.nestKeys,e.reduceRemove,t),e.reduceInitial=g.initial(e.reduceInitial,t)),n.aliasKeys&&(e.reduceInitial=x.initial(e.reduceInitial,t,n.aliasKeys)),n.aliasPropKeys&&(e.reduceAdd=k.add(n.aliasPropKeys,e.reduceAdd,t),e.reduceRemove=k.add(n.aliasPropKeys,e.reduceRemove,t)),n.filter&&(e.reduceAdd=i.add(n.filter,e.reduceAdd,j.reduceAdd,t),e.reduceRemove=i.remove(n.filter,e.reduceRemove,j.reduceRemove,t)),n.values&&Object.getOwnPropertyNames(n.values).forEach(function(i){var u=function(n){return function(e){return e=n(e),t(e)[i]={},e}};e.reduceInitial=u(e.reduceInitial),r(n.values[i].parameters,e,function(n){return n[i]})})}var i=n("./filter.js"),u=n("./count.js"),o=n("./sum.js"),c=n("./avg.js"),a=n("./median.js"),s=n("./min.js"),f=n("./max.js"),l=n("./value-count.js"),d=n("./value-list.js"),p=n("./exception-count.js"),v=n("./exception-sum.js"),h=n("./histogram.js"),m=n("./sum-of-squares.js"),y=n("./std.js"),g=n("./nest.js"),x=n("./alias.js"),k=n("./aliasProp.js"),b=n("./data-list.js"),j={build:r};e.exports=j},{"./alias.js":6,"./aliasProp.js":7,"./avg.js":8,"./count.js":11,"./data-list.js":12,"./exception-count.js":13,"./exception-sum.js":14,"./filter.js":15,"./histogram.js":16,"./max.js":17,"./median.js":18,"./min.js":19,"./nest.js":20,"./std.js":26,"./sum-of-squares.js":27,"./sum.js":28,"./value-count.js":29,"./value-list.js":30}],10:[function(n,e,t){var r=function(n){return function(e){return e[n]}};_grouper=function(n,e){return n||(n=function(n){return n}),function(t,r){e&&e(t,r);var i=n(t),u=n(r);return"undefined"!=typeof u.count&&(i.count+=u.count),"undefined"!=typeof u.sum&&(i.sum+=u.sum),"undefined"!=typeof u.avg&&(i.avg=i.sum/i.count),t}},reductio_cap=function(n,e,t){var i=(e.reduceInitial(),t.values?Object.keys(t.values):[]),u=_grouper();if(i.length)for(var o=0;ou;u++)f=o[u],r=l(n,f,0,n.length),n[r]&&n[r].key===f||n.splice(r,0,{key:f,value:t.reduceInitial()}),t.reduceAdd(n[r].value,i,c);return n},function(n,i,c){for(o=e.groupAll(i),s=o.length,u=0;s>u;u++)r=l(n,o[u],0,n.length),t.reduceRemove(n[r].value,i,c);return n},function(){return[]}),n.all||(n.all=function(){return this.value()})}else n.reduce(t.reduceAdd,t.reduceRemove,t.reduceInitial);return c(n,e,t),n}var e=o(),t={};return u.build(n,e),n}var i=n("./build.js"),u=n("./accessors.js"),o=n("./parameters.js"),c=n("./postprocess"),a=n("crossfilter");n("./postprocessors")(r),c=c(r),e.exports=r},{"./accessors.js":5,"./build.js":9,"./parameters.js":21,"./postprocess":22,"./postprocessors":23,crossfilter:2}],25:[function(n,e,t){function r(n,e){return e>n?-1:n>e?1:n>=e?0:NaN}var i=function(n){if("function"==typeof n)return n;if(~n.indexOf(".")){var e=n.split(".");return function(n){return e.reduce(function(n,e){return n[e]},n)}}return function(e){return e[n]}},u=function(n,e){return function(t,r){return e(n(t),n(r))}};({}).toString;e.exports=function(n){return function(e,t){return 1===arguments.length&&(t=r),n().sort(u(i(e),t))}}},{}],26:[function(n,e,t){var r={add:function(n,e){return function(t,r,i){if(n&&n(t,r,i),e(t).count>0){e(t).std=0;var u=e(t).sumOfSq-e(t).sum*e(t).sum/e(t).count;u>0&&(e(t).std=Math.sqrt(u/(e(t).count-1)))}else e(t).std=0;return t}},remove:function(n,e){return function(t,r,i){if(n&&n(t,r,i),e(t).count>0){e(t).std=0;var u=e(t).sumOfSq-e(t).sum*e(t).sum/e(t).count;u>0&&(e(t).std=Math.sqrt(u/(e(t).count-1)))}else e(t).std=0;return t}},initial:function(n,e){return function(t){return t=n(t),e(t).std=0,t}}};e.exports=r},{}],27:[function(n,e,t){var r={add:function(n,e,t){return function(r,i,u){return e&&e(r,i,u),t(r).sumOfSq=t(r).sumOfSq+n(i)*n(i),r}},remove:function(n,e,t){return function(r,i,u){return e&&e(r,i,u),t(r).sumOfSq=t(r).sumOfSq-n(i)*n(i),r}},initial:function(n,e){return function(t){return t=n(t),e(t).sumOfSq=0,t}}};e.exports=r},{}],28:[function(n,e,t){var r={add:function(n,e,t){return function(r,i,u){return e&&e(r,i,u),t(r).sum=t(r).sum+n(i),r}},remove:function(n,e,t){return function(r,i,u){return e&&e(r,i,u),t(r).sum=t(r).sum-n(i),r}},initial:function(n,e){return function(t){return t=n(t),e(t).sum=0,t}}};e.exports=r},{}],29:[function(n,e,t){var r=n("crossfilter"),i={add:function(n,e,t){var r,i;return function(u,o,c){return e&&e(u,o,c),r=t(u).bisect(t(u).values,n(o),0,t(u).values.length),i=t(u).values[r],i&&i[0]===n(o)?i[1]++:t(u).values.splice(r,0,[n(o),1]),u}},remove:function(n,e,t){var r;return function(i,u,o){return e&&e(i,u,o),r=t(i).bisect(t(i).values,n(u),0,t(i).values.length),t(i).values[r][1]--,i}},initial:function(n,e){return function(t){return t=n(t),e(t).values=[],e(t).bisect=r.bisect.by(function(n){return n[0]}).left,t}}};e.exports=i},{crossfilter:2}],30:[function(n,e,t){var r=n("crossfilter"),i={add:function(n,e,t){var i,u=r.bisect.by(function(n){return n}).left;return function(r,o,c){return e&&e(r,o,c),i=u(t(r).valueList,n(o),0,t(r).valueList.length),t(r).valueList.splice(i,0,n(o)),r}},remove:function(n,e,t){var i,u=r.bisect.by(function(n){return n}).left;return function(r,o,c){return e&&e(r,o,c),i=u(t(r).valueList,n(o),0,t(r).valueList.length),t(r).valueList.splice(i,1),r}},initial:function(n,e){return function(t){return t=n(t),e(t).valueList=[],t}}};e.exports=i},{crossfilter:2}],31:[function(n,e,t){"use strict";function r(n){function e(){var e=i(n);return function(n){return e(n)}}if("string"==typeof n){if(!o(n))return n;n=a(n)}return"number"==typeof n?n:k.isObject(n)?e():void 0}function i(n){if(n=k.isObject(n)?u(n):n,k.isString(n))return o(n)?i(a(n)):function(e){return e[n]};if(k.isArray(n)){var e=k.map(n,i);return function(n){return e.map(function(e){return e(n)})}}if(n.key){if(b[n.key]){var t=i(n.value);return function(e){return b[n.key](t(e))}}console.error("Could not find aggregration method",n)}return[]}function u(n){var e,t=[];for(var r in n)if(n.hasOwnProperty(r)){e={key:r,value:n[r]};var i={};i[r]=n[r],t.push(i)}return t.length>1?t:e}function o(n){return["$","("].indexOf(n.charAt(0))>-1}function c(n){var e=[],t=n.indexOf("("),r=n.indexOf(")"),i=t>-1?n.substring(0,t):n;return b[i]?(t>-1&&r>-1&&r>t&&(e=n.substring(t+1,r).split(",")),{aggregator:b[i],params:e}):!1}function a(n){function e(n){return n=n.replace(" ",""),'"'+n.replace(t,function(n,t){return r.test(t)?"$"===t.charAt(0)?'":{"'+t.replace(r,function(n,t){return","===n?',"':e(n).trim()})+"}":':["'+t.replace(r,function(n,e){return'","'})+'"]':void 0})}var t=/\((.+)\)/g,r=/(?:\([^\(\)]*\))|(,)/g;return JSON.parse("{"+e(n)+"}")}function s(n){return n.reduce(function(n,e){return n+e},0)}function f(n){return n.reduce(function(n,e){return n+e},0)/n.length}function l(n){return Math.max.apply(null,n)}function d(n){return Math.min.apply(null,n)}function p(n){return n.length}function v(n){return n[0]}function h(n){return n[n.length-1]}function m(n,e){return n[e]}function y(n,e){return n[n.length-e]}function g(n,e){return n[Math.round(n.length*(e/100))]}function x(n,e){return n.map(function(n){return n[e]})}var k=n("./lodash"),b={$sum:s,$avg:f,$max:l,$min:d,$count:p,$first:v,$last:h,$get:m,$nth:m,$nthLast:y,$nthPct:g,$map:x};e.exports={makeValueAccessor:r,aggregators:b,extractKeyValOrArray:u,parseAggregatorParams:c}},{"./lodash":38}],32:[function(n,e,t){"use strict";var r=n("q"),i=n("./lodash");e.exports=function(n){return function(e){function t(e){var t=[];e.removeListeners&&(t=i.map(e.removeListeners,function(n){return r.resolve(n())}));var u=e.complex?JSON.stringify(e.key):e.key;return delete n.filters[u],e.dimension&&t.push(r.resolve(e.dimension.dispose())),r.all(t)}return e&&(e=i.isArray(e)?e:[e]),e?r.all(i.map(e,function(e){i.isObject(e)&&(e=e.key);var r=i.remove(n.columns,function(n){return i.isArray(e)?!i.xor(n.key,e).length:n.key===e?!n.dynamicReference:void 0})[0];r&&t(r)})).then(function(){return n}):r.all(i.map(n.columns,t)).then(function(){return n.columns=[],n})}}},{"./lodash":38,q:4}],33:[function(n,e,t){"use strict";var r=n("q"),i=n("./lodash");e.exports=function(e){function t(n){return i.isUndefined(n)&&(n=!0),i.isArray(n)||(n=[n]),r.all(i.map(n,c)).then(function(n){return e})}function u(n){return i.find(e.columns,function(e){return i.isArray(n)?!i.xor(e.key,n).length:e.key===n})}function o(n){return i.isNumber(n)?"number":i.isBoolean(n)?"bool":i.isArray(n)?"array":i.isObject(n)?"object":"string"}function c(n){var t=i.isObject(n)?n:{key:n},c=u(t.key);return c?(c=c,c.temporary=!1,c.dynamicReference&&(c.dynamicReference=!1),c.promise.then(function(){return e})):(t.queries=[],e.columns.push(t),t.promise=r["try"](function(){return r.resolve(e.cf.all())}).then(function(n){var e;if(i.isArray(t.key)){if(t.complex=!0,e=i.values(i.pick(n[0],t.key)),e.length!==t.key.length)throw new Error("Column key does not exist in data!",t.key)}else e=n[0][t.key];if(!t.complex&&t.key!==!0&&"undefined"==typeof e)throw new Error("Column key does not exist in data!",t.key);return t.type=t.key===!0?"all":t.complex?"complex":t.array?"array":o(e),a.make(t.key,t.type)}).then(function(n){function u(n){return t.key===!0?r.resolve():r.resolve(t.dimension.bottom(1/0)).then(function(n){var e=a.makeAccessor(t.key);"complex"===t.type?t.values=i.uniq(i.flatten(i.map(n,e))):"array"===t.type?t.values=i.uniq(i.flatten(i.map(n,e))):t.values=i.uniq(i.map(n,e))})}t.dimension=n,t.filterCount=0;var o=e.onDataChange(u);return t.removeListeners=[o],u()}),t.promise.then(function(){return e}))}var a=n("./dimension")(e),s=t;return s.find=u,s}},{"./dimension":35,"./lodash":38,q:4}],34:[function(n,e,t){"use strict";var r=n("q"),i=n("crossfilter2"),u=n("./lodash");e.exports=function(n){function e(n){return u.isArray(n)?r.resolve(i(n)):n&&"function"==typeof n.dimension?r.resolve(n):r.reject(new Error("No Crossfilter data or instance found!"))}function t(e){return n.options.generatedColumns?u.map(e,function(e,t){return u.forEach(n.options.generatedColumns,function(n,t){e[t]=n(e)}),e}):e}function o(e){return e=t(e),r["try"](function(){return r.resolve(n.cf.add(e))}).then(function(){return r.serial(u.map(n.dataListeners,function(n){return function(){return n(!0)}}))}).then(function(){return n})}function c(){return r["try"](function(){return r.resolve(n.cf.remove())}).then(function(){return n})}return{build:e,generateColumns:t,add:o,remove:c}}},{"./lodash":38,crossfilter2:2,q:4}],35:[function(n,e,t){"use strict";var r=n("q"),i=n("./lodash");e.exports=function(n){function e(e,i){var u=t(e);return r.resolve(n.cf.dimension(u,"array"==i))}function t(n){var e;if(i.isArray(n)){var t=i.map(n,function(n){return"d['"+n+"']"});e=new Function("d","return "+JSON.stringify(t).replace(/\"/g,""))}else e=n===!0?function(n,e){return e}:function(e){return e[n]};return e}return{make:e,makeAccessor:t}}},{"./lodash":38,q:4}],36:[function(n,e,t){"use strict";function r(n,e){return n[e]}function i(n,e){e=e(n);for(var t=0;te()}function s(n,e){return n>=e()}function f(n,e){return n-1}function h(n,e){return-1===n.indexOf(e())}function m(n,e){return e().indexOf(n)>-1}function y(n,e){return-1===e().indexOf(n)}function g(n,e){return n.length===e()}e.exports={$field:r,$and:i,$or:u,$not:o,$eq:c,$gt:a,$gte:s,$lt:f,$lte:l,$ne:d,$type:p,$in:v,$nin:h,$contains:m,$excludes:y,$size:g}},{}],37:[function(n,e,t){"use strict";var r=n("q"),i=n("./lodash"),u=n("./expressions"),o=n("./aggregation");e.exports=function(n){function e(e,t,u,o){var s=n.column.find(e);return r["try"](function(){return s?s:n.column({key:e,temporary:!0}).then(function(){return n.column.find(e)})}).then(function(e){var r=i.clone(n.filters,!0),s=e.complex?JSON.stringify(e.key):e.key;return r[s]=c(t,u,o),a(r)})}function t(){return a({})}function c(n,e,t){return i.isUndefined(n)?!1:i.isFunction(n)?{value:n,"function":n,replace:!0,type:"function"}:i.isObject(n)?{value:n,"function":d(n),replace:!0,type:"function"}:i.isArray(n)?{value:n,replace:e||t,type:e?"range":"inclusive"}:{value:n,replace:t,type:"exact"}}function a(e){var t=i.map(e,function(t,u){var o=n.filters[u];if(t.replace&&o&&i.isEqual(t,o))return r.resolve();var c;return c="["===u.charAt(0)?n.column.find(JSON.parse(u)):n.column.find(u),t&&o&&!t.replace&&(e[u]=t=s(t,o)),t?"exact"===t.type?r.resolve(c.dimension.filterExact(t.value)):"range"===t.type?r.resolve(c.dimension.filterRange(t.value)):"inclusive"===t.type?r.resolve(c.dimension.filterFunction(function(n){return t.value.indexOf(n)>-1})):"function"===t.type?r.resolve(c.dimension.filterFunction(t["function"])):r.resolve(c.dimension.filterAll()):r.resolve(c.dimension.filterAll())});return r.all(t).then(function(){n.filters=e;var t=[];return i.forEach(n.filters,function(e,r){e||(t.push({key:r,val:e}),delete n.filters[r])}),r.all(i.map(t,function(e){var t=n.column.find("["===e.key.charAt(0)?JSON.parse(e.key):e.key);return t.temporary&&!t.dynamicReference?n.clear(t.key):void 0}))}).then(function(){return r.all(i.map(n.filterListeners,function(n){return n()}))}).then(function(){return n})}function s(n,e){if("exact"===n.type&&"inclusive"===e.type)n.value=i.xor([n.value],e.value);else if("inclusive"===n.type&&"exact"===e.type)n.value=i.xor(n.value,[e.value]);else if("inclusive"===n.type&&"inclusive"===e.type)n.value=i.xor(n.value,e.value);else if("exact"===n.type&&"exact"===e.type){if(n.value===e.value)return!1;n.value=[n.value,e.value]}return n.value.length?1===n.value.length?(n.type="exact",n.value=n.value[0]):n.type="inclusive":n=!1,n}function f(n){function e(n){i.forEach(n,function(n,r){var u=l(n,r);u&&t.push(u),i.isString(n)&&(u=l(null,n),u&&t.push(u)),i.isObject(n)&&e(n)})}var t=[];return e(n.filter),t}function l(n,e){return"$data"===e?!0:e&&"$column"===e?i.isString(n)?n:(console.warn('The value for filter "$column" must be a valid column key',n),!1):void 0}function d(e,t){var r;if(i.isString(e)){var c=l(null,e);if(c){var a=n.cf.all();return function(n){return a}}}return i.isString(e)||i.isNumber(e)||i.isBoolean(e)?function(n){return"undefined"==typeof n?e:u.$eq(n,function(){return e})}:i.isArray(e)?(r=i.map(e,function(n){return d(n,t)}),function(n){return r.map(function(e){return e(n)})}):i.isObject(e)?(r=i.map(e,function(e,r){var i=d(e,t),c=l(e,r);if(c){var a=n.column.find(c),s=a.values;return function(n){return s}}if(u[r])return function(n){return u[r](n,i)};var f=o.parseAggregatorParams(r);return f?(t=!0,i=d(e,t),function(n){return f.aggregator.apply(null,[i()].concat(f.params))}):function(n){return n=n[r],i(n,i)}}),t?1===r.length?function(n){return r[0](n)}:function(n){return i.map(r,function(e){return e(n)})}:function(n){return u.$and(n,function(n){return i.map(r,function(e){return e(n)})})}):(console.log("no expression found for ",e),!1)}return{filter:e,filterAll:t,applyFilters:a,makeFunction:d,scanForDynamicFilters:f}}},{"./aggregation":31,"./expressions":36,"./lodash":38,q:4}],38:[function(n,e,t){"use strict";function r(n){n=n||{};for(var e=1;e1){var i=e.shift();r(n[i]="[object Object]"===Object.prototype.toString.call(n[i])?n[i]:{},e,t)}else n[e[0]]=t}function v(n,e){var t,r;if(l(e)){if(c(n)){t=[];for(r in n)n.hasOwnProperty(r)&&t.push(e(n[r],r,n));return t}return n.map(e)}if(c(n)){t=[];for(r in n)n.hasOwnProperty(r)&&t.push(n[r]);return t}return n.map(function(n,t){return n[e]})}function h(n){return Object.keys(n)}function m(n,e){return l(e)?n.sort(function(n,t){return e(n)>e(t)?1:e(n)r?n.splice(r,t-r):r>t&&n.push.apply(n,new Array(r-t)),y(n,function(t,r){n[r]=e[r]}),n}function A(n){var e=new Set;return n.filter(function(n){var t=!1;return e.has(n)||(e.add(n),t=!0),t})}function O(n){for(var e=[],t=0;tt;)n[r]=n[r-1],--r;n[r]=t}return n}function S(n){var e=[];for(var t in n)n.hasOwnProperty(t)&&e.push(n[t]);return e}function R(n,e){function t(n,r){for(var i in n){var u=b(r);if(u.push(i),"object"==typeof n[i]&&null!==n[i])t(n[i],u);else{if(!n.hasOwnProperty(i))continue;e(n[i],i,u)}}}return t(n,[]),n}e.exports={assign:r,find:i,remove:u,isArray:o,isObject:c,isBoolean:a,isString:s,isNumber:f,isFunction:l,get:d,set:p,map:v,keys:h,sortBy:m,forEach:y,isUndefined:g,pick:x,xor:k,clone:b,isEqual:j,replaceArray:w,uniq:A,flatten:O,sort:L,values:S,recurseObject:R}},{}],39:[function(n,e,t){"use strict";function r(n){return n.locked?u.clone(n.data):n.data}var i=n("q"),u=n("./lodash"),o=n("./aggregation");e.exports=function(n){function e(n,e,t){return n.data=r(e),i.resolve(t(n,e))}function t(n,e,t){n.data=r(e),n.data=u.sortBy(n.data,function(n){return n.key}),t&&n.data.reverse()}function c(n,e,t,i){n.data=r(e),u.isUndefined(i)?(i=t||0,t=0):(t=t||0,i=i||n.data.length),n.data=n.data.splice(t,i-t)}function a(n,e,t,i,c,a){n.data=r(e),t=t||0,i=i||n.data.length;var s=n.data.splice(t,i-t),f={key:a||"Other",value:{}};u.recurseObject(c,function(n,e,t){var r=[];u.forEach(s,function(n){r.push(u.get(n.value,t))}),u.set(f.value,t,o.aggregators[n](r))}),n.data.splice(t,0,f)}function s(n,e,t,i,o){n.data=r(e),t=t||0,i=i||n.data.length;var c={key:[n.data[t].key,n.data[i].key],value:{}};u.recurseObject(o,function(e,r,o){var a=u.clone(o);a.pop(),a.push(r+"Change"),u.set(c.value,a,u.get(n.data[i].value,o)-u.get(n.data[t].value,o))}),n.data=c}function f(n,e,t){n.data=r(e),u.recurseObject(t,function(e,t,r){var i=u.clone(r),o=u.clone(r),c=u.clone(r);i.pop(), -o.pop(),c.pop(),i.push(t+"Change"),o.push(t+"ChangeFromStart"),c.push(t+"ChangeFromEnd");var a=u.get(n.data[0].value,r),s=u.get(n.data[n.data.length-1].value,r);u.forEach(n.data,function(e,t){var f=n.data[t-1]||n.data[0];u.set(n.data[t].value,i,u.get(e.value,r)-(f?u.get(f.value,r):0)),u.set(n.data[t].value,o,u.get(e.value,r)-a),u.set(n.data[t].value,c,u.get(e.value,r)-s)})})}return{post:e,sortByKey:t,limit:c,squash:a,change:s,changeMap:f}}},{"./aggregation":31,"./lodash":38,q:4}],40:[function(n,e,t){"use strict";function r(n){var e,t=new Error;return u.forEach(n,function(n,r){var u,c=n.success||n,a=n.fail,s=n.notify;if(e)u=e.then(function(n){if(!c)return n;var e=c(n);if(!o(e))throw t.message="Task "+r+" did not return a promise.",t;return e},function(n){if(!a)return i.reject(n);var e=a(n);if(!o(e))throw t.message="Fail for task "+r+" did not return a promise.",t;return e},s);else if(u=c(),!o(u))throw t.message="Task "+r+" did not return a promise.",t;e=u}),e||i.when()}var i=n("q"),u=n("./lodash");i.serial=r;var o=function(n){return n&&u.isFunction(n.then)}},{"./lodash":38,q:4}],41:[function(n,e,t){"use strict";var r=n("q"),i=n("./lodash");e.exports=function(e){var t=n("./reductiofy")(e),u=n("./filters")(e),o=n("./postAggregation")(e),c=i.keys(o);return function(n){function a(n){return e.column({key:n.original.groupBy,type:i.isUndefined(n.type)?null:n.type,array:!!n.array}).then(function(){var t=e.column.find(n.original.groupBy);return n.column=t,t.queries.push(n),t.removeListeners.push(function(){return n.clear()}),n})}function s(n){return r.resolve(n.column.dimension.group()).then(function(e){return n.group=e,n})}function f(n){var t=u.scanForDynamicFilters(n.original);return t.length?r.all(i.map(t,function(t){return e.column({key:t,dynamicReference:n.group})})).then(function(){var t=e.onDataChange(function(){return l(n)});return n.removeListeners.push(t),n}):n}function l(n){var t=e.onFilter(function(){return h(n)});return n.removeListeners.push(t),d(n).then(p).then(v).then(h)}function d(n){return t(n.original).then(function(e){return n.reducer=e,n})}function p(n){return r.resolve(n.reducer(n.group)).then(function(){return n})}function v(n){return r.resolve(n.group.all()).then(function(e){return n.data=e,n})}function h(n){return n.postAggregations.length>1&&(n.locked=!0),r.all(i.map(n.postAggregations,function(n){return n()})).then(function(){return n})}function m(n,t){function u(e){return i.isUndefined(e)?void(n.locked=!0):void(n.locked=!!e)}function a(){n.locked=!1}function s(){return i.forEach(n.removeListners,function(n){n()}),r["try"](function(){return n.group.dispose()}).then(function(){return n.column.queries.splice(n.column.queries.indexOf(n),1),n.column.queries.length?void 0:e.clear(n.column.key)}).then(function(){return e})}function f(e){return function(){function t(){return h(u).then(function(){return u})}var i=Array.prototype.slice.call(arguments),u={};return m(u,n),i.unshift(u,n),n.postAggregations.push(function(){r.resolve(e.apply(null,i)).then(t)}),r.resolve(e.apply(null,i)).then(t)}}var l=!1;return t||(t=n,n={},l=!0),i.assign(n,{universe:e,crossfilter:e.cf,parent:t,column:t.column,dimension:t.dimension,group:t.group,reducer:t.reducer,original:t.original,hash:t.hash,removeListeners:[],postAggregations:[],locked:l,lock:u,unlock:a,clear:s}),i.forEach(c,function(e){n[e]=f(o[e])}),n}for(var y=JSON.stringify(n),g=0;g0?t(n).avg=t(n).sum/t(n).count:t(n).avg=0,n}},remove:function(n,e,t){return function(n,r,i){return e&&e(n,r,i),t(n).count>0?t(n).avg=t(n).sum/t(n).count:t(n).avg=0,n}},initial:function(n,e){return function(t){return t=n(t),e(t).avg=0,t}}};e.exports=r},{}],9:[function(n,e,t){function r(n,e,t){t||(t=function(n){return n});var j={reduceAdd:e.reduceAdd,reduceRemove:e.reduceRemove,reduceInitial:e.reduceInitial};(n.count||n.std)&&(e.reduceAdd=u.add(e.reduceAdd,t),e.reduceRemove=u.remove(e.reduceRemove,t),e.reduceInitial=u.initial(e.reduceInitial,t)),n.sum&&(e.reduceAdd=o.add(n.sum,e.reduceAdd,t),e.reduceRemove=o.remove(n.sum,e.reduceRemove,t),e.reduceInitial=o.initial(e.reduceInitial,t)),n.avg&&(n.count&&n.sum?(e.reduceAdd=c.add(n.sum,e.reduceAdd,t),e.reduceRemove=c.remove(n.sum,e.reduceRemove,t),e.reduceInitial=c.initial(e.reduceInitial,t)):console.error("You must set .count(true) and define a .sum(accessor) to use .avg(true).")),n.exceptionCount&&(n.exceptionAccessor?(e.reduceAdd=p.add(n.exceptionAccessor,e.reduceAdd,t),e.reduceRemove=p.remove(n.exceptionAccessor,e.reduceRemove,t),e.reduceInitial=p.initial(e.reduceInitial,t)):console.error("You must define an .exception(accessor) to use .exceptionCount(true).")),n.exceptionSum&&(n.exceptionAccessor?(e.reduceAdd=v.add(n.exceptionAccessor,n.exceptionSum,e.reduceAdd,t),e.reduceRemove=v.remove(n.exceptionAccessor,n.exceptionSum,e.reduceRemove,t),e.reduceInitial=v.initial(e.reduceInitial,t)):console.error("You must define an .exception(accessor) to use .exceptionSum(accessor).")),(n.valueList||n.median||n.min||n.max)&&(e.reduceAdd=d.add(n.valueList,e.reduceAdd,t),e.reduceRemove=d.remove(n.valueList,e.reduceRemove,t),e.reduceInitial=d.initial(e.reduceInitial,t)),n.dataList&&(e.reduceAdd=b.add(n.dataList,e.reduceAdd,t),e.reduceRemove=b.remove(n.dataList,e.reduceRemove,t),e.reduceInitial=b.initial(e.reduceInitial,t)),n.median&&(e.reduceAdd=a.add(e.reduceAdd,t),e.reduceRemove=a.remove(e.reduceRemove,t),e.reduceInitial=a.initial(e.reduceInitial,t)),n.min&&(e.reduceAdd=s.add(e.reduceAdd,t),e.reduceRemove=s.remove(e.reduceRemove,t),e.reduceInitial=s.initial(e.reduceInitial,t)),n.max&&(e.reduceAdd=f.add(e.reduceAdd,t),e.reduceRemove=f.remove(e.reduceRemove,t),e.reduceInitial=f.initial(e.reduceInitial,t)),n.exceptionAccessor&&(e.reduceAdd=l.add(n.exceptionAccessor,e.reduceAdd,t),e.reduceRemove=l.remove(n.exceptionAccessor,e.reduceRemove,t),e.reduceInitial=l.initial(e.reduceInitial,t)),n.histogramValue&&n.histogramThresholds&&(e.reduceAdd=h.add(n.histogramValue,e.reduceAdd,t),e.reduceRemove=h.remove(n.histogramValue,e.reduceRemove,t),e.reduceInitial=h.initial(n.histogramThresholds,e.reduceInitial,t)),n.sumOfSquares&&(e.reduceAdd=m.add(n.sumOfSquares,e.reduceAdd,t),e.reduceRemove=m.remove(n.sumOfSquares,e.reduceRemove,t),e.reduceInitial=m.initial(e.reduceInitial,t)),n.std&&(n.sumOfSquares&&n.sum?(e.reduceAdd=y.add(e.reduceAdd,t),e.reduceRemove=y.remove(e.reduceRemove,t),e.reduceInitial=y.initial(e.reduceInitial,t)):console.error("You must set .sumOfSq(accessor) and define a .sum(accessor) to use .std(true). Or use .std(accessor).")),n.nestKeys&&(e.reduceAdd=g.add(n.nestKeys,e.reduceAdd,t),e.reduceRemove=g.remove(n.nestKeys,e.reduceRemove,t),e.reduceInitial=g.initial(e.reduceInitial,t)),n.aliasKeys&&(e.reduceInitial=x.initial(e.reduceInitial,t,n.aliasKeys)),n.aliasPropKeys&&(e.reduceAdd=k.add(n.aliasPropKeys,e.reduceAdd,t),e.reduceRemove=k.add(n.aliasPropKeys,e.reduceRemove,t)),n.filter&&(e.reduceAdd=i.add(n.filter,e.reduceAdd,j.reduceAdd,t),e.reduceRemove=i.remove(n.filter,e.reduceRemove,j.reduceRemove,t)),n.values&&Object.getOwnPropertyNames(n.values).forEach(function(i){var u=function(n){return function(e){return e=n(e),t(e)[i]={},e}};e.reduceInitial=u(e.reduceInitial),r(n.values[i].parameters,e,function(n){return n[i]})})}var i=n("./filter.js"),u=n("./count.js"),o=n("./sum.js"),c=n("./avg.js"),a=n("./median.js"),s=n("./min.js"),f=n("./max.js"),l=n("./value-count.js"),d=n("./value-list.js"),p=n("./exception-count.js"),v=n("./exception-sum.js"),h=n("./histogram.js"),m=n("./sum-of-squares.js"),y=n("./std.js"),g=n("./nest.js"),x=n("./alias.js"),k=n("./aliasProp.js"),b=n("./data-list.js"),j={build:r};e.exports=j},{"./alias.js":6,"./aliasProp.js":7,"./avg.js":8,"./count.js":11,"./data-list.js":12,"./exception-count.js":13,"./exception-sum.js":14,"./filter.js":15,"./histogram.js":16,"./max.js":17,"./median.js":18,"./min.js":19,"./nest.js":20,"./std.js":26,"./sum-of-squares.js":27,"./sum.js":28,"./value-count.js":29,"./value-list.js":30}],10:[function(n,e,t){var r=function(n){return function(e){return e[n]}};_grouper=function(n,e){return n||(n=function(n){return n}),function(t,r){e&&e(t,r);var i=n(t),u=n(r);return"undefined"!=typeof u.count&&(i.count+=u.count),"undefined"!=typeof u.sum&&(i.sum+=u.sum),"undefined"!=typeof u.avg&&(i.avg=i.sum/i.count),t}},reductio_cap=function(n,e,t){var i=(e.reduceInitial(),t.values?Object.keys(t.values):[]),u=_grouper();if(i.length)for(var o=0;ou;u++)f=o[u],r=l(n,f,0,n.length),n[r]&&n[r].key===f||n.splice(r,0,{key:f,value:t.reduceInitial()}),t.reduceAdd(n[r].value,i,c);return n},function(n,i,c){for(o=e.groupAll(i),s=o.length,u=0;s>u;u++)r=l(n,o[u],0,n.length),t.reduceRemove(n[r].value,i,c);return n},function(){return[]}),n.all||(n.all=function(){return this.value()})}else n.reduce(t.reduceAdd,t.reduceRemove,t.reduceInitial);return c(n,e,t),n}var e=o(),t={};return u.build(n,e),n}var i=n("./build.js"),u=n("./accessors.js"),o=n("./parameters.js"),c=n("./postprocess"),a=n("crossfilter");n("./postprocessors")(r),c=c(r),e.exports=r},{"./accessors.js":5,"./build.js":9,"./parameters.js":21,"./postprocess":22,"./postprocessors":23,crossfilter:2}],25:[function(n,e,t){function r(n,e){return e>n?-1:n>e?1:n>=e?0:NaN}var i=function(n){if("function"==typeof n)return n;if(~n.indexOf(".")){var e=n.split(".");return function(n){return e.reduce(function(n,e){return n[e]},n)}}return function(e){return e[n]}},u=function(n,e){return function(t,r){return e(n(t),n(r))}};({}).toString;e.exports=function(n){return function(e,t){return 1===arguments.length&&(t=r),n().sort(u(i(e),t))}}},{}],26:[function(n,e,t){var r={add:function(n,e){return function(t,r,i){if(n&&n(t,r,i),e(t).count>0){e(t).std=0;var u=e(t).sumOfSq-e(t).sum*e(t).sum/e(t).count;u>0&&(e(t).std=Math.sqrt(u/(e(t).count-1)))}else e(t).std=0;return t}},remove:function(n,e){return function(t,r,i){if(n&&n(t,r,i),e(t).count>0){e(t).std=0;var u=e(t).sumOfSq-e(t).sum*e(t).sum/e(t).count;u>0&&(e(t).std=Math.sqrt(u/(e(t).count-1)))}else e(t).std=0;return t}},initial:function(n,e){return function(t){return t=n(t),e(t).std=0,t}}};e.exports=r},{}],27:[function(n,e,t){var r={add:function(n,e,t){return function(r,i,u){return e&&e(r,i,u),t(r).sumOfSq=t(r).sumOfSq+n(i)*n(i),r}},remove:function(n,e,t){return function(r,i,u){return e&&e(r,i,u),t(r).sumOfSq=t(r).sumOfSq-n(i)*n(i),r}},initial:function(n,e){return function(t){return t=n(t),e(t).sumOfSq=0,t}}};e.exports=r},{}],28:[function(n,e,t){var r={add:function(n,e,t){return function(r,i,u){return e&&e(r,i,u),t(r).sum=t(r).sum+n(i),r}},remove:function(n,e,t){return function(r,i,u){return e&&e(r,i,u),t(r).sum=t(r).sum-n(i),r}},initial:function(n,e){return function(t){return t=n(t),e(t).sum=0,t}}};e.exports=r},{}],29:[function(n,e,t){var r=n("crossfilter"),i={add:function(n,e,t){var r,i;return function(u,o,c){return e&&e(u,o,c),r=t(u).bisect(t(u).values,n(o),0,t(u).values.length),i=t(u).values[r],i&&i[0]===n(o)?i[1]++:t(u).values.splice(r,0,[n(o),1]),u}},remove:function(n,e,t){var r;return function(i,u,o){return e&&e(i,u,o),r=t(i).bisect(t(i).values,n(u),0,t(i).values.length),t(i).values[r][1]--,i}},initial:function(n,e){return function(t){return t=n(t),e(t).values=[],e(t).bisect=r.bisect.by(function(n){return n[0]}).left,t}}};e.exports=i},{crossfilter:2}],30:[function(n,e,t){var r=n("crossfilter"),i={add:function(n,e,t){var i,u=r.bisect.by(function(n){return n}).left;return function(r,o,c){return e&&e(r,o,c),i=u(t(r).valueList,n(o),0,t(r).valueList.length),t(r).valueList.splice(i,0,n(o)),r}},remove:function(n,e,t){var i,u=r.bisect.by(function(n){return n}).left;return function(r,o,c){return e&&e(r,o,c),i=u(t(r).valueList,n(o),0,t(r).valueList.length),t(r).valueList.splice(i,1),r}},initial:function(n,e){return function(t){return t=n(t),e(t).valueList=[],t}}};e.exports=i},{crossfilter:2}],31:[function(n,e,t){"use strict";function r(n){function e(){var e=i(n);return function(n){return e(n)}}if("string"==typeof n){if(!o(n))return n;n=a(n)}return"number"==typeof n?n:k.isObject(n)?e():void 0}function i(n){if(n=k.isObject(n)?u(n):n,k.isString(n))return o(n)?i(a(n)):function(e){return e[n]};if(k.isArray(n)){var e=k.map(n,i);return function(n){return e.map(function(e){return e(n)})}}if(n.key){if(b[n.key]){var t=i(n.value);return function(e){return b[n.key](t(e))}}console.error("Could not find aggregration method",n)}return[]}function u(n){var e,t=[];for(var r in n)if(n.hasOwnProperty(r)){e={key:r,value:n[r]};var i={};i[r]=n[r],t.push(i)}return t.length>1?t:e}function o(n){return["$","("].indexOf(n.charAt(0))>-1}function c(n){var e=[],t=n.indexOf("("),r=n.indexOf(")"),i=t>-1?n.substring(0,t):n;return b[i]?(t>-1&&r>-1&&r>t&&(e=n.substring(t+1,r).split(",")),{aggregator:b[i],params:e}):!1}function a(n){function e(n){return n=n.replace(" ",""),'"'+n.replace(t,function(n,t){return r.test(t)?"$"===t.charAt(0)?'":{"'+t.replace(r,function(n,t){return","===n?',"':e(n).trim()})+"}":':["'+t.replace(r,function(n,e){return'","'})+'"]':void 0})}var t=/\((.+)\)/g,r=/(?:\([^\(\)]*\))|(,)/g;return JSON.parse("{"+e(n)+"}")}function s(n){return n.reduce(function(n,e){return n+e},0)}function f(n){return n.reduce(function(n,e){return n+e},0)/n.length}function l(n){return Math.max.apply(null,n)}function d(n){return Math.min.apply(null,n)}function p(n){return n.length}function v(n){return n[0]}function h(n){return n[n.length-1]}function m(n,e){return n[e]}function y(n,e){return n[n.length-e]}function g(n,e){return n[Math.round(n.length*(e/100))]}function x(n,e){return n.map(function(n){return n[e]})}var k=n("./lodash"),b={$sum:s,$avg:f,$max:l,$min:d,$count:p,$first:v,$last:h,$get:m,$nth:m,$nthLast:y,$nthPct:g,$map:x};e.exports={makeValueAccessor:r,aggregators:b,extractKeyValOrArray:u,parseAggregatorParams:c}},{"./lodash":38}],32:[function(n,e,t){"use strict";var r=n("q"),i=n("./lodash");e.exports=function(n){return function(e){function t(e){var t=[];e.removeListeners&&(t=i.map(e.removeListeners,function(n){return r.resolve(n())}));var u=e.complex?JSON.stringify(e.key):e.key;return delete n.filters[u],e.dimension&&t.push(r.resolve(e.dimension.dispose())),r.all(t)}return e&&(e=i.isArray(e)?e:[e]),e?r.all(i.map(e,function(e){i.isObject(e)&&(e=e.key);var r=i.remove(n.columns,function(n){return i.isArray(e)?!i.xor(n.key,e).length:n.key===e?!n.dynamicReference:void 0})[0];r&&t(r)})).then(function(){return n}):r.all(i.map(n.columns,t)).then(function(){return n.columns=[],n})}}},{"./lodash":38,q:4}],33:[function(n,e,t){"use strict";var r=n("q"),i=n("./lodash");e.exports=function(e){function t(n){return i.isUndefined(n)&&(n=!0),i.isArray(n)||(n=[n]),r.all(i.map(n,c)).then(function(n){return e})}function u(n){return i.find(e.columns,function(e){return i.isArray(n)?!i.xor(e.key,n).length:e.key===n})}function o(n){return i.isNumber(n)?"number":i.isBoolean(n)?"bool":i.isArray(n)?"array":i.isObject(n)?"object":"string"}function c(n){var t=i.isObject(n)?n:{key:n},c=u(t.key);return c?(c=c,c.temporary=!1,c.dynamicReference&&(c.dynamicReference=!1),c.promise.then(function(){return e})):(t.queries=[],e.columns.push(t),t.promise=r["try"](function(){return r.resolve(e.cf.all())}).then(function(n){var e;if(i.isArray(t.key)){if(t.complex=!0,e=i.values(i.pick(n[0],t.key)),e.length!==t.key.length)throw new Error("Column key does not exist in data!",t.key)}else e=n[0][t.key];if(!t.complex&&t.key!==!0&&"undefined"==typeof e)throw new Error("Column key does not exist in data!",t.key);return t.type=t.key===!0?"all":t.complex?"complex":t.array?"array":o(e),a.make(t.key,t.type)}).then(function(n){function u(n){return t.key===!0?r.resolve():r.resolve(t.dimension.bottom(1/0)).then(function(n){var e=a.makeAccessor(t.key);"complex"===t.type?t.values=i.uniq(i.flatten(i.map(n,e))):"array"===t.type?t.values=i.uniq(i.flatten(i.map(n,e))):t.values=i.uniq(i.map(n,e))})}t.dimension=n,t.filterCount=0;var o=e.onDataChange(u);return t.removeListeners=[o],u()}),t.promise.then(function(){return e}))}var a=n("./dimension")(e),s=t;return s.find=u,s}},{"./dimension":35,"./lodash":38,q:4}],34:[function(n,e,t){"use strict";var r=n("q"),i=n("crossfilter2"),u=n("./lodash");e.exports=function(n){function e(n){return u.isArray(n)?r.resolve(i(n)):n&&"function"==typeof n.dimension?r.resolve(n):r.reject(new Error("No Crossfilter data or instance found!"))}function t(e){return n.options.generatedColumns?u.map(e,function(e,t){return u.forEach(n.options.generatedColumns,function(n,t){e[t]=n(e)}),e}):e}function o(e){return e=t(e),r["try"](function(){return r.resolve(n.cf.add(e))}).then(function(){return r.serial(u.map(n.dataListeners,function(n){return function(){return n(!0)}}))}).then(function(){return n})}function c(){return r["try"](function(){return r.resolve(n.cf.remove())}).then(function(){return n})}return{build:e,generateColumns:t,add:o,remove:c}}},{"./lodash":38,crossfilter2:2,q:4}],35:[function(n,e,t){"use strict";var r=n("q"),i=n("./lodash");e.exports=function(n){function e(e,i){var u=t(e);return r.resolve(n.cf.dimension(u,"array"==i))}function t(n){var e;if(i.isArray(n)){var t=i.map(n,function(n){return"d['"+n+"']"});e=new Function("d","return "+JSON.stringify(t).replace(/\"/g,""))}else e=n===!0?function(n,e){return e}:function(e){return e[n]};return e}return{make:e,makeAccessor:t}}},{"./lodash":38,q:4}],36:[function(n,e,t){"use strict";function r(n,e){return n[e]}function i(n,e){e=e(n);for(var t=0;te()}function s(n,e){return n>=e()}function f(n,e){return n-1}function h(n,e){return-1===n.indexOf(e())}function m(n,e){return e().indexOf(n)>-1}function y(n,e){return-1===e().indexOf(n)}function g(n,e){return n.length===e()}e.exports={$field:r,$and:i,$or:u,$not:o,$eq:c,$gt:a,$gte:s,$lt:f,$lte:l,$ne:d,$type:p,$in:v,$nin:h,$contains:m,$excludes:y,$size:g}},{}],37:[function(n,e,t){"use strict";var r=n("q"),i=n("./lodash"),u=n("./expressions"),o=n("./aggregation");e.exports=function(n){function e(e,t,u,o){var s=n.column.find(e);return r["try"](function(){return s?s:n.column({key:e,temporary:!0}).then(function(){return n.column.find(e)})}).then(function(e){var r=i.clone(n.filters,!0),s=e.complex?JSON.stringify(e.key):e.key;return r[s]=c(t,u,o),a(r)})}function t(){return a({})}function c(n,e,t){return i.isUndefined(n)?!1:i.isFunction(n)?{value:n,"function":n,replace:!0,type:"function"}:i.isObject(n)?{value:n,"function":d(n),replace:!0,type:"function"}:i.isArray(n)?{value:n,replace:e||t,type:e?"range":"inclusive"}:{value:n,replace:t,type:"exact"}}function a(e){var t=i.map(e,function(t,u){var o=n.filters[u];if(t.replace&&o&&i.isEqual(t,o))return r.resolve();var c;return c="["===u.charAt(0)?n.column.find(JSON.parse(u)):n.column.find(u),t&&o&&!t.replace&&(e[u]=t=s(t,o)),t?"exact"===t.type?r.resolve(c.dimension.filterExact(t.value)):"range"===t.type?r.resolve(c.dimension.filterRange(t.value)):"inclusive"===t.type?r.resolve(c.dimension.filterFunction(function(n){return t.value.indexOf(n)>-1})):"function"===t.type?r.resolve(c.dimension.filterFunction(t["function"])):r.resolve(c.dimension.filterAll()):r.resolve(c.dimension.filterAll())});return r.all(t).then(function(){n.filters=e;var t=[];return i.forEach(n.filters,function(e,r){e||(t.push({key:r,val:e}),delete n.filters[r])}),r.all(i.map(t,function(e){var t=n.column.find("["===e.key.charAt(0)?JSON.parse(e.key):e.key);return t.temporary&&!t.dynamicReference?n.clear(t.key):void 0}))}).then(function(){return r.all(i.map(n.filterListeners,function(n){return n()}))}).then(function(){return n})}function s(n,e){if("exact"===n.type&&"inclusive"===e.type)n.value=i.xor([n.value],e.value);else if("inclusive"===n.type&&"exact"===e.type)n.value=i.xor(n.value,[e.value]);else if("inclusive"===n.type&&"inclusive"===e.type)n.value=i.xor(n.value,e.value);else if("exact"===n.type&&"exact"===e.type){if(n.value===e.value)return!1;n.value=[n.value,e.value]}return n.value.length?1===n.value.length?(n.type="exact",n.value=n.value[0]):n.type="inclusive":n=!1,n}function f(n){function e(n){i.forEach(n,function(n,r){var u=l(n,r);u&&t.push(u),i.isString(n)&&(u=l(null,n),u&&t.push(u)),i.isObject(n)&&e(n)})}var t=[];return e(n.filter),t}function l(n,e){return"$data"===e?!0:e&&"$column"===e?i.isString(n)?n:(console.warn('The value for filter "$column" must be a valid column key',n),!1):void 0}function d(e,t){var r;if(i.isString(e)){var c=l(null,e);if(c){var a=n.cf.all();return function(n){return a}}}return i.isString(e)||i.isNumber(e)||i.isBoolean(e)?function(n){return"undefined"==typeof n?e:u.$eq(n,function(){return e})}:i.isArray(e)?(r=i.map(e,function(n){return d(n,t)}),function(n){return r.map(function(e){return e(n)})}):i.isObject(e)?(r=i.map(e,function(e,r){var i=d(e,t),c=l(e,r);if(c){var a=n.column.find(c),s=a.values;return function(n){return s}}if(u[r])return function(n){return u[r](n,i)};var f=o.parseAggregatorParams(r);return f?(t=!0,i=d(e,t),function(n){return f.aggregator.apply(null,[i()].concat(f.params))}):function(n){return n=n[r],i(n,i)}}),t?1===r.length?function(n){return r[0](n)}:function(n){return i.map(r,function(e){return e(n)})}:function(n){return u.$and(n,function(n){return i.map(r,function(e){return e(n)})})}):(console.log("no expression found for ",e),!1)}return{filter:e,filterAll:t,applyFilters:a,makeFunction:d,scanForDynamicFilters:f}}},{"./aggregation":31,"./expressions":36,"./lodash":38,q:4}],38:[function(n,e,t){"use strict";function r(n){n=n||{};for(var e=1;e1){var i=e.shift();r(n[i]="[object Object]"===Object.prototype.toString.call(n[i])?n[i]:{},e,t)}else n[e[0]]=t}function v(n,e){var t,r;if(l(e)){if(c(n)){t=[];for(r in n)n.hasOwnProperty(r)&&t.push(e(n[r],r,n));return t}return n.map(e)}if(c(n)){t=[];for(r in n)n.hasOwnProperty(r)&&t.push(n[r]);return t}return n.map(function(n,t){return n[e]})}function h(n){return Object.keys(n)}function m(n,e){return l(e)?n.sort(function(n,t){return e(n)>e(t)?1:e(n)r?n.splice(r,t-r):r>t&&n.push.apply(n,new Array(r-t)),y(n,function(t,r){n[r]=e[r]}),n}function A(n){var e=new Set;return n.filter(function(n){var t=!1;return e.has(n)||(e.add(n),t=!0),t})}function O(n){for(var e=[],t=0;tt;)n[r]=n[r-1],--r;n[r]=t}return n}function S(n){var e=[];for(var t in n)n.hasOwnProperty(t)&&e.push(n[t]);return e}function R(n,e){function t(n,r){for(var i in n){var u=b(r);if(u.push(i),"object"==typeof n[i]&&null!==n[i])t(n[i],u);else{if(!n.hasOwnProperty(i))continue;e(n[i],i,u)}}}return t(n,[]),n}e.exports={assign:r,find:i,remove:u,isArray:o,isObject:c,isBoolean:a,isString:s,isNumber:f,isFunction:l,get:d,set:p,map:v,keys:h,sortBy:m,forEach:y,isUndefined:g,pick:x,xor:k,clone:b,isEqual:j,replaceArray:w,uniq:A,flatten:O,sort:L,values:S,recurseObject:R}},{}],39:[function(n,e,t){"use strict";function r(n){return n.locked?u.clone(n.data):n.data}var i=n("q"),u=n("./lodash"),o=n("./aggregation");e.exports=function(n){function e(n,e,t){return n.data=r(e),i.resolve(t(n,e))}function t(n,e,t){n.data=r(e),n.data=u.sortBy(n.data,function(n){return n.key}),t&&n.data.reverse()}function c(n,e,t,i){n.data=r(e),u.isUndefined(i)?(i=t||0,t=0):(t=t||0,i=i||n.data.length),n.data=n.data.splice(t,i-t)}function a(n,e,t,i,c,a){n.data=r(e),t=t||0,i=i||n.data.length;var s=n.data.splice(t,i-t),f={key:a||"Other",value:{}};u.recurseObject(c,function(n,e,t){var r=[];u.forEach(s,function(n){r.push(u.get(n.value,t))}),u.set(f.value,t,o.aggregators[n](r))}),n.data.splice(t,0,f)}function s(n,e,t,i,o){n.data=r(e),t=t||0,i=i||n.data.length;var c={key:[n.data[t].key,n.data[i].key],value:{}};u.recurseObject(o,function(e,r,o){var a=u.clone(o);a.pop(),a.push(r+"Change"),u.set(c.value,a,u.get(n.data[i].value,o)-u.get(n.data[t].value,o))}),n.data=c}function f(n,e,t,i){i=u.isUndefined(i)?0:i,n.data=r(e),u.recurseObject(t,function(e,t,r){var o=u.clone(r),c=u.clone(r),a=u.clone(r); +o.pop(),c.pop(),a.pop(),o.push(t+"Change"),c.push(t+"ChangeFromStart"),a.push(t+"ChangeFromEnd");var s=u.get(n.data[0].value,r,i),f=u.get(n.data[n.data.length-1].value,r,i);u.forEach(n.data,function(e,t){var l=n.data[t-1]||n.data[0];u.set(n.data[t].value,o,u.get(e.value,r,i)-(l?u.get(l.value,r,i):i)),u.set(n.data[t].value,c,u.get(e.value,r,i)-s),u.set(n.data[t].value,a,u.get(e.value,r,i)-f)})})}return{post:e,sortByKey:t,limit:c,squash:a,change:s,changeMap:f}}},{"./aggregation":31,"./lodash":38,q:4}],40:[function(n,e,t){"use strict";function r(n){var e,t=new Error;return u.forEach(n,function(n,r){var u,c=n.success||n,a=n.fail,s=n.notify;if(e)u=e.then(function(n){if(!c)return n;var e=c(n);if(!o(e))throw t.message="Task "+r+" did not return a promise.",t;return e},function(n){if(!a)return i.reject(n);var e=a(n);if(!o(e))throw t.message="Fail for task "+r+" did not return a promise.",t;return e},s);else if(u=c(),!o(u))throw t.message="Task "+r+" did not return a promise.",t;e=u}),e||i.when()}var i=n("q"),u=n("./lodash");i.serial=r;var o=function(n){return n&&u.isFunction(n.then)}},{"./lodash":38,q:4}],41:[function(n,e,t){"use strict";var r=n("q"),i=n("./lodash");e.exports=function(e){var t=n("./reductiofy")(e),u=n("./filters")(e),o=n("./postAggregation")(e),c=i.keys(o);return function(n){function a(n){return e.column({key:n.original.groupBy,type:i.isUndefined(n.type)?null:n.type,array:!!n.array}).then(function(){var t=e.column.find(n.original.groupBy);return n.column=t,t.queries.push(n),t.removeListeners.push(function(){return n.clear()}),n})}function s(n){return r.resolve(n.column.dimension.group()).then(function(e){return n.group=e,n})}function f(n){var t=u.scanForDynamicFilters(n.original);return t.length?r.all(i.map(t,function(t){return e.column({key:t,dynamicReference:n.group})})).then(function(){var t=e.onDataChange(function(){return l(n)});return n.removeListeners.push(t),n}):n}function l(n){var t=e.onFilter(function(){return h(n)});return n.removeListeners.push(t),d(n).then(p).then(v).then(h)}function d(n){return t(n.original).then(function(e){return n.reducer=e,n})}function p(n){return r.resolve(n.reducer(n.group)).then(function(){return n})}function v(n){return r.resolve(n.group.all()).then(function(e){return n.data=e,n})}function h(n){return n.postAggregations.length>1&&(n.locked=!0),r.all(i.map(n.postAggregations,function(n){return n()})).then(function(){return n})}function m(n,t){function u(e){return i.isUndefined(e)?void(n.locked=!0):void(n.locked=!!e)}function a(){n.locked=!1}function s(){return i.forEach(n.removeListners,function(n){n()}),r["try"](function(){return n.group.dispose()}).then(function(){return n.column.queries.splice(n.column.queries.indexOf(n),1),n.column.queries.length?void 0:e.clear(n.column.key)}).then(function(){return e})}function f(e){return function(){function t(){return h(u).then(function(){return u})}var i=Array.prototype.slice.call(arguments),u={};return m(u,n),i.unshift(u,n),n.postAggregations.push(function(){r.resolve(e.apply(null,i)).then(t)}),r.resolve(e.apply(null,i)).then(t)}}var l=!1;return t||(t=n,n={},l=!0),i.assign(n,{universe:e,crossfilter:e.cf,parent:t,column:t.column,dimension:t.dimension,group:t.group,reducer:t.reducer,original:t.original,hash:t.hash,removeListeners:[],postAggregations:[],locked:l,lock:u,unlock:a,clear:s}),i.forEach(c,function(e){n[e]=f(o[e])}),n}for(var y=JSON.stringify(n),g=0;g