From 1c179ed3306cca9ed17b0e60cef4bcd75d4a4784 Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Sun, 19 Oct 2014 14:52:36 +0300 Subject: [PATCH] Delete old sandbox models, views and sub views --- TODO | 29 +- dist/js/app.js | 1228 ++++------------------------------ dist/js/binder.js | 4 +- dist/js/renderer.js | 1114 ++++-------------------------- dist/js/utils.js | 4 +- package.json | 1 - src/app.js | 2 +- src/models/input-diagrams.js | 62 -- src/models/output-diagram.js | 36 - src/models/utils.js | 80 +-- src/renderer.js | 34 +- src/views/completion.js | 22 +- src/views/input-diagram.js | 54 -- src/views/marble.js | 83 +-- src/views/new-sandbox.js | 41 -- src/views/operator-box.js | 16 - src/views/output-diagram.js | 47 -- src/views/sandbox.js | 81 +-- src/views/utils.js | 92 --- 19 files changed, 347 insertions(+), 2683 deletions(-) delete mode 100644 src/models/input-diagrams.js delete mode 100644 src/models/output-diagram.js delete mode 100644 src/views/input-diagram.js delete mode 100644 src/views/new-sandbox.js delete mode 100644 src/views/operator-box.js delete mode 100644 src/views/output-diagram.js delete mode 100644 src/views/utils.js diff --git a/TODO b/TODO index d559366..43a68d0 100644 --- a/TODO +++ b/TODO @@ -53,39 +53,12 @@ DONE New Model View Interpreter architecture, for OperatorsMenu DONE New MVI architecture for Sandbox DONE Rename interpreters to intents DONE Style and logic for tall/short completion element -TODO Delete old sandbox models, views and sub views - - models/input-diagrams - - models/output-diagram - - refactor models/utils - - views/input-diagram - - views/output-diagram - - views/sandbox - - rename views/new-sandbox - - Remove hyperscript everywhere - - Remove raw DOM manipulation +DONE Delete old sandbox models, views and sub views TODO Bug: slowly dragging should change marble time TODO Bug: some marbles can't be dragged, error 'invalid parent' is shown TODO Build scripts to replace gulp (?) ## v1.1.0 -TODO Use virtual-dom for all views - - See modules under Raynos/mercury - TODO Refactor to conform to MVC philosophy - - Model is the representation of data and state - - Input: interpreted interaction streams - - Output: data streams - - View renders to DOM and interfaces with the user - - Input: data streams - - Output: raw interaction streams - - Controller: interprets user interaction and notifies model of changes - - Input: raw interaction streams - - Output: interpreted interaction streams - - Marble should export only mouseDownStream, mouseMoveStream, mouseUpStream - - All the intelligent streams in Marble should go to some controller class - which observes Marble.mouse____Stream - - - TODO Fix referential transparency inconsistency Replace models/sandbox-ouput combineLatest with combinePrevious TODO Disambiguate simultaneous marbles diff --git a/dist/js/app.js b/dist/js/app.js index 84e0f2a..d75daff 100644 --- a/dist/js/app.js +++ b/dist/js/app.js @@ -2335,699 +2335,6 @@ process.chdir = function (dir) { }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/gulp-browserify/node_modules/browserify/node_modules/process/browser.js","/../node_modules/gulp-browserify/node_modules/browserify/node_modules/process") },{"1YiZ5S":19,"buffer":15}],20:[function(require,module,exports){ -(function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ -var split = require('browser-split') -var ClassList = require('class-list') -var DataSet = require('data-set') -require('html-element') - -function context () { - - var cleanupFuncs = [] - - function h() { - var args = [].slice.call(arguments), e = null - function item (l) { - var r - function parseClass (string) { - var m = split(string, /([\.#]?[a-zA-Z0-9_:-]+)/) - if(/^\.|#/.test(m[1])) - e = document.createElement('div') - forEach(m, function (v) { - var s = v.substring(1,v.length) - if(!v) return - if(!e) - e = document.createElement(v) - else if (v[0] === '.') - ClassList(e).add(s) - else if (v[0] === '#') - e.setAttribute('id', s) - }) - } - - if(l == null) - ; - else if('string' === typeof l) { - if(!e) - parseClass(l) - else - e.appendChild(r = document.createTextNode(l)) - } - else if('number' === typeof l - || 'boolean' === typeof l - || l instanceof Date - || l instanceof RegExp ) { - e.appendChild(r = document.createTextNode(l.toString())) - } - //there might be a better way to handle this... - else if (isArray(l)) - forEach(l, item) - else if(isNode(l)) - e.appendChild(r = l) - else if(l instanceof Text) - e.appendChild(r = l) - else if ('object' === typeof l) { - for (var k in l) { - if('function' === typeof l[k]) { - if(/^on\w+/.test(k)) { - if (e.addEventListener){ - e.addEventListener(k.substring(2), l[k], false) - cleanupFuncs.push(function(){ - e.removeEventListener(k.substring(2), l[k], false) - }) - }else{ - e.attachEvent(k, l[k]) - cleanupFuncs.push(function(){ - e.detachEvent(k, l[k]) - }) - } - } else { - // observable - e[k] = l[k]() - cleanupFuncs.push(l[k](function (v) { - e[k] = v - })) - } - } - else if(k === 'style') { - if('string' === typeof l[k]) { - e.style.cssText = l[k] - }else{ - for (var s in l[k]) (function(s, v) { - if('function' === typeof v) { - // observable - e.style.setProperty(s, v()) - cleanupFuncs.push(v(function (val) { - e.style.setProperty(s, val) - })) - } else - e.style.setProperty(s, l[k][s]) - })(s, l[k][s]) - } - } else if (k.substr(0, 5) === "data-") { - DataSet(e)[k.substr(5)] = l[k] - } else { - e[k] = l[k] - } - } - } else if ('function' === typeof l) { - //assume it's an observable! - var v = l() - e.appendChild(r = isNode(v) ? v : document.createTextNode(v)) - - cleanupFuncs.push(l(function (v) { - if(isNode(v) && r.parentElement) - r.parentElement.replaceChild(v, r), r = v - else - r.textContent = v - })) - } - - return r - } - while(args.length) - item(args.shift()) - - return e - } - - h.cleanup = function () { - for (var i = 0; i < cleanupFuncs.length; i++){ - cleanupFuncs[i]() - } - } - - return h -} - -var h = module.exports = context() -h.context = context - -function isNode (el) { - return el && el.nodeName && el.nodeType -} - -function isText (el) { - return el && el.nodeName === '#text' && el.nodeType == 3 -} - -function forEach (arr, fn) { - if (arr.forEach) return arr.forEach(fn) - for (var i = 0; i < arr.length; i++) fn(arr[i], i) -} - -function isArray (arr) { - return Object.prototype.toString.call(arr) == '[object Array]' -} - -}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/hyperscript/index.js","/../node_modules/hyperscript") -},{"1YiZ5S":19,"browser-split":21,"buffer":15,"class-list":22,"data-set":24,"html-element":14}],21:[function(require,module,exports){ -(function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ -/*! - * Cross-Browser Split 1.1.1 - * Copyright 2007-2012 Steven Levithan - * Available under the MIT License - * ECMAScript compliant, uniform cross-browser split method - */ - -/** - * Splits a string into an array of strings using a regex or string separator. Matches of the - * separator are not included in the result array. However, if `separator` is a regex that contains - * capturing groups, backreferences are spliced into the result each time `separator` is matched. - * Fixes browser bugs compared to the native `String.prototype.split` and can be used reliably - * cross-browser. - * @param {String} str String to split. - * @param {RegExp|String} separator Regex or string to use for separating the string. - * @param {Number} [limit] Maximum number of items to include in the result array. - * @returns {Array} Array of substrings. - * @example - * - * // Basic use - * split('a b c d', ' '); - * // -> ['a', 'b', 'c', 'd'] - * - * // With limit - * split('a b c d', ' ', 2); - * // -> ['a', 'b'] - * - * // Backreferences in result array - * split('..word1 word2..', /([a-z]+)(\d+)/i); - * // -> ['..', 'word', '1', ' ', 'word', '2', '..'] - */ -module.exports = (function split(undef) { - - var nativeSplit = String.prototype.split, - compliantExecNpcg = /()??/.exec("")[1] === undef, - // NPCG: nonparticipating capturing group - self; - - self = function(str, separator, limit) { - // If `separator` is not a regex, use `nativeSplit` - if (Object.prototype.toString.call(separator) !== "[object RegExp]") { - return nativeSplit.call(str, separator, limit); - } - var output = [], - flags = (separator.ignoreCase ? "i" : "") + (separator.multiline ? "m" : "") + (separator.extended ? "x" : "") + // Proposed for ES6 - (separator.sticky ? "y" : ""), - // Firefox 3+ - lastLastIndex = 0, - // Make `global` and avoid `lastIndex` issues by working with a copy - separator = new RegExp(separator.source, flags + "g"), - separator2, match, lastIndex, lastLength; - str += ""; // Type-convert - if (!compliantExecNpcg) { - // Doesn't need flags gy, but they don't hurt - separator2 = new RegExp("^" + separator.source + "$(?!\\s)", flags); - } - /* Values for `limit`, per the spec: - * If undefined: 4294967295 // Math.pow(2, 32) - 1 - * If 0, Infinity, or NaN: 0 - * If positive number: limit = Math.floor(limit); if (limit > 4294967295) limit -= 4294967296; - * If negative number: 4294967296 - Math.floor(Math.abs(limit)) - * If other: Type-convert, then use the above rules - */ - limit = limit === undef ? -1 >>> 0 : // Math.pow(2, 32) - 1 - limit >>> 0; // ToUint32(limit) - while (match = separator.exec(str)) { - // `separator.lastIndex` is not reliable cross-browser - lastIndex = match.index + match[0].length; - if (lastIndex > lastLastIndex) { - output.push(str.slice(lastLastIndex, match.index)); - // Fix browsers whose `exec` methods don't consistently return `undefined` for - // nonparticipating capturing groups - if (!compliantExecNpcg && match.length > 1) { - match[0].replace(separator2, function() { - for (var i = 1; i < arguments.length - 2; i++) { - if (arguments[i] === undef) { - match[i] = undef; - } - } - }); - } - if (match.length > 1 && match.index < str.length) { - Array.prototype.push.apply(output, match.slice(1)); - } - lastLength = match[0].length; - lastLastIndex = lastIndex; - if (output.length >= limit) { - break; - } - } - if (separator.lastIndex === match.index) { - separator.lastIndex++; // Avoid an infinite loop - } - } - if (lastLastIndex === str.length) { - if (lastLength || !separator.test("")) { - output.push(""); - } - } else { - output.push(str.slice(lastLastIndex)); - } - return output.length > limit ? output.slice(0, limit) : output; - }; - - return self; -})(); - -}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/hyperscript/node_modules/browser-split/index.js","/../node_modules/hyperscript/node_modules/browser-split") -},{"1YiZ5S":19,"buffer":15}],22:[function(require,module,exports){ -(function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ -// contains, add, remove, toggle -var indexof = require('indexof') - -module.exports = ClassList - -function ClassList(elem) { - var cl = elem.classList - - if (cl) { - return cl - } - - var classList = { - add: add - , remove: remove - , contains: contains - , toggle: toggle - , toString: $toString - , length: 0 - , item: item - } - - return classList - - function add(token) { - var list = getTokens() - if (indexof(list, token) > -1) { - return - } - list.push(token) - setTokens(list) - } - - function remove(token) { - var list = getTokens() - , index = indexof(list, token) - - if (index === -1) { - return - } - - list.splice(index, 1) - setTokens(list) - } - - function contains(token) { - return indexof(getTokens(), token) > -1 - } - - function toggle(token) { - if (contains(token)) { - remove(token) - return false - } else { - add(token) - return true - } - } - - function $toString() { - return elem.className - } - - function item(index) { - var tokens = getTokens() - return tokens[index] || null - } - - function getTokens() { - var className = elem.className - - return filter(className.split(" "), isTruthy) - } - - function setTokens(list) { - var length = list.length - - elem.className = list.join(" ") - classList.length = length - - for (var i = 0; i < list.length; i++) { - classList[i] = list[i] - } - - delete list[length] - } -} - -function filter (arr, fn) { - var ret = [] - for (var i = 0; i < arr.length; i++) { - if (fn(arr[i])) ret.push(arr[i]) - } - return ret -} - -function isTruthy(value) { - return !!value -} - -}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/hyperscript/node_modules/class-list/index.js","/../node_modules/hyperscript/node_modules/class-list") -},{"1YiZ5S":19,"buffer":15,"indexof":23}],23:[function(require,module,exports){ -(function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ - -var indexOf = [].indexOf; - -module.exports = function(arr, obj){ - if (indexOf) return arr.indexOf(obj); - for (var i = 0; i < arr.length; ++i) { - if (arr[i] === obj) return i; - } - return -1; -}; -}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/hyperscript/node_modules/class-list/node_modules/indexof/index.js","/../node_modules/hyperscript/node_modules/class-list/node_modules/indexof") -},{"1YiZ5S":19,"buffer":15}],24:[function(require,module,exports){ -(function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ -var Weakmap = require("weakmap") -var Individual = require("individual") - -var datasetMap = Individual("__DATA_SET_WEAKMAP", Weakmap()) - -module.exports = DataSet - -function DataSet(elem) { - if (elem.dataset) { - return elem.dataset - } - - var hash = datasetMap.get(elem) - - if (!hash) { - hash = createHash(elem) - datasetMap.set(elem, hash) - } - - return hash -} - -function createHash(elem) { - var attributes = elem.attributes - var hash = {} - - if (attributes === null || attributes === undefined) { - return hash - } - - for (var i = 0; i < attributes.length; i++) { - var attr = attributes[i] - - if (attr.name.substr(0,5) !== "data-") { - continue - } - - hash[attr.name.substr(5)] = attr.value - } - - return hash -} - -}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/hyperscript/node_modules/data-set/index.js","/../node_modules/hyperscript/node_modules/data-set") -},{"1YiZ5S":19,"buffer":15,"individual":25,"weakmap":27}],25:[function(require,module,exports){ -(function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ -var root = require("global") - -module.exports = Individual - -function Individual(key, value) { - if (root[key]) { - return root[key] - } - - Object.defineProperty(root, key, { - value: value - , configurable: true - }) - - return value -} - -}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/hyperscript/node_modules/data-set/node_modules/individual/index.js","/../node_modules/hyperscript/node_modules/data-set/node_modules/individual") -},{"1YiZ5S":19,"buffer":15,"global":26}],26:[function(require,module,exports){ -(function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ -/*global window, global*/ -if (typeof global !== "undefined") { - module.exports = global -} else if (typeof window !== "undefined") { - module.exports = window -} - -}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/hyperscript/node_modules/data-set/node_modules/individual/node_modules/global/index.js","/../node_modules/hyperscript/node_modules/data-set/node_modules/individual/node_modules/global") -},{"1YiZ5S":19,"buffer":15}],27:[function(require,module,exports){ -(function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ -/* (The MIT License) - * - * Copyright (c) 2012 Brandon Benvie - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and - * associated documentation files (the 'Software'), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included with all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -// Original WeakMap implementation by Gozala @ https://gist.github.com/1269991 -// Updated and bugfixed by Raynos @ https://gist.github.com/1638059 -// Expanded by Benvie @ https://github.com/Benvie/harmony-collections - -void function(global, undefined_, undefined){ - var getProps = Object.getOwnPropertyNames, - defProp = Object.defineProperty, - toSource = Function.prototype.toString, - create = Object.create, - hasOwn = Object.prototype.hasOwnProperty, - funcName = /^\n?function\s?(\w*)?_?\(/; - - - function define(object, key, value){ - if (typeof key === 'function') { - value = key; - key = nameOf(value).replace(/_$/, ''); - } - return defProp(object, key, { configurable: true, writable: true, value: value }); - } - - function nameOf(func){ - return typeof func !== 'function' - ? '' : 'name' in func - ? func.name : toSource.call(func).match(funcName)[1]; - } - - // ############ - // ### Data ### - // ############ - - var Data = (function(){ - var dataDesc = { value: { writable: true, value: undefined } }, - datalock = 'return function(k){if(k===s)return l}', - uids = create(null), - - createUID = function(){ - var key = Math.random().toString(36).slice(2); - return key in uids ? createUID() : uids[key] = key; - }, - - globalID = createUID(), - - storage = function(obj){ - if (hasOwn.call(obj, globalID)) - return obj[globalID]; - - if (!Object.isExtensible(obj)) - throw new TypeError("Object must be extensible"); - - var store = create(null); - defProp(obj, globalID, { value: store }); - return store; - }; - - // common per-object storage area made visible by patching getOwnPropertyNames' - define(Object, function getOwnPropertyNames(obj){ - var props = getProps(obj); - if (hasOwn.call(obj, globalID)) - props.splice(props.indexOf(globalID), 1); - return props; - }); - - function Data(){ - var puid = createUID(), - secret = {}; - - this.unlock = function(obj){ - var store = storage(obj); - if (hasOwn.call(store, puid)) - return store[puid](secret); - - var data = create(null, dataDesc); - defProp(store, puid, { - value: new Function('s', 'l', datalock)(secret, data) - }); - return data; - } - } - - define(Data.prototype, function get(o){ return this.unlock(o).value }); - define(Data.prototype, function set(o, v){ this.unlock(o).value = v }); - - return Data; - }()); - - - var WM = (function(data){ - var validate = function(key){ - if (key == null || typeof key !== 'object' && typeof key !== 'function') - throw new TypeError("Invalid WeakMap key"); - } - - var wrap = function(collection, value){ - var store = data.unlock(collection); - if (store.value) - throw new TypeError("Object is already a WeakMap"); - store.value = value; - } - - var unwrap = function(collection){ - var storage = data.unlock(collection).value; - if (!storage) - throw new TypeError("WeakMap is not generic"); - return storage; - } - - var initialize = function(weakmap, iterable){ - if (iterable !== null && typeof iterable === 'object' && typeof iterable.forEach === 'function') { - iterable.forEach(function(item, i){ - if (item instanceof Array && item.length === 2) - set.call(weakmap, iterable[i][0], iterable[i][1]); - }); - } - } - - - function WeakMap(iterable){ - if (this === global || this == null || this === WeakMap.prototype) - return new WeakMap(iterable); - - wrap(this, new Data); - initialize(this, iterable); - } - - function get(key){ - validate(key); - var value = unwrap(this).get(key); - return value === undefined_ ? undefined : value; - } - - function set(key, value){ - validate(key); - // store a token for explicit undefined so that "has" works correctly - unwrap(this).set(key, value === undefined ? undefined_ : value); - } - - function has(key){ - validate(key); - return unwrap(this).get(key) !== undefined; - } - - function delete_(key){ - validate(key); - var data = unwrap(this), - had = data.get(key) !== undefined; - data.set(key, undefined); - return had; - } - - function toString(){ - unwrap(this); - return '[object WeakMap]'; - } - - try { - var src = ('return '+delete_).replace('e_', '\\u0065'), - del = new Function('unwrap', 'validate', src)(unwrap, validate); - } catch (e) { - var del = delete_; - } - - var src = (''+Object).split('Object'); - var stringifier = function toString(){ - return src[0] + nameOf(this) + src[1]; - }; - - define(stringifier, stringifier); - - var prep = { __proto__: [] } instanceof Array - ? function(f){ f.__proto__ = stringifier } - : function(f){ define(f, stringifier) }; - - prep(WeakMap); - - [toString, get, set, has, del].forEach(function(method){ - define(WeakMap.prototype, method); - prep(method); - }); - - return WeakMap; - }(new Data)); - - var defaultCreator = Object.create - ? function(){ return Object.create(null) } - : function(){ return {} }; - - function createStorage(creator){ - var weakmap = new WM; - creator || (creator = defaultCreator); - - function storage(object, value){ - if (value || arguments.length === 2) { - weakmap.set(object, value); - } else { - value = weakmap.get(object); - if (value === undefined) { - value = creator(object); - weakmap.set(object, value); - } - } - return value; - } - - return storage; - } - - - if (typeof module !== 'undefined') { - module.exports = WM; - } else if (typeof exports !== 'undefined') { - exports.WeakMap = WM; - } else if (!('WeakMap' in global)) { - global.WeakMap = WM; - } - - WM.createStorage = createStorage; - if (global.WeakMap) - global.WeakMap.createStorage = createStorage; -}((0, eval)('this')); - -}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/hyperscript/node_modules/data-set/node_modules/weakmap/weakmap.js","/../node_modules/hyperscript/node_modules/data-set/node_modules/weakmap") -},{"1YiZ5S":19,"buffer":15}],28:[function(require,module,exports){ module.exports={ "name": "rxmarbles", "version": "1.0.2", @@ -3042,7 +2349,6 @@ module.exports={ "rx": "2.3.12", "virtual-dom": "0.0.19", "virtual-hyperscript": "4.4.0", - "hyperscript": "1.4.0", "dom-delegator": "^9.0.1" }, "devDependencies": { @@ -3063,7 +2369,7 @@ module.exports={ } } -},{}],29:[function(require,module,exports){ +},{}],21:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. @@ -12350,7 +11656,7 @@ module.exports={ }.call(this)); }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rx/dist/rx.all.js","/../node_modules/rx/dist") -},{"1YiZ5S":19,"buffer":15}],30:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],22:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. @@ -12834,7 +12140,7 @@ module.exports={ })); }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rx/dist/rx.testing.js","/../node_modules/rx/dist") -},{"./rx.all":29,"1YiZ5S":19,"buffer":15}],31:[function(require,module,exports){ +},{"./rx.all":21,"1YiZ5S":19,"buffer":15}],23:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var Rx = require('./dist/rx.all'); require('./dist/rx.testing'); @@ -13011,7 +12317,7 @@ Rx.Node = { module.exports = Rx; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rx/index.js","/../node_modules/rx") -},{"./dist/rx.all":29,"./dist/rx.testing":30,"1YiZ5S":19,"buffer":15,"events":18}],32:[function(require,module,exports){ +},{"./dist/rx.all":21,"./dist/rx.testing":22,"1YiZ5S":19,"buffer":15,"events":18}],24:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ /* * Important Model-View-Intent binding function. @@ -13023,7 +12329,7 @@ module.exports = function(model, view, intent) { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/binder.js","/../node_modules/rxmarbles") -},{"1YiZ5S":19,"buffer":15}],33:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],25:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var Rx = require('rx'); @@ -13075,7 +12381,7 @@ module.exports = { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/data/boolean-examples.js","/../node_modules/rxmarbles/data") -},{"1YiZ5S":19,"buffer":15,"rx":31}],34:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"rx":23}],26:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var Rx = require('rx'); @@ -13151,7 +12457,7 @@ module.exports = { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/data/combine-examples.js","/../node_modules/rxmarbles/data") -},{"1YiZ5S":19,"buffer":15,"rx":31}],35:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"rx":23}],27:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var Rx = require('rx'); @@ -13170,7 +12476,7 @@ module.exports = { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/data/conditional-examples.js","/../node_modules/rxmarbles/data") -},{"1YiZ5S":19,"buffer":15,"rx":31}],36:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"rx":23}],28:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ /* * The database of all predefined examples in the app. @@ -13214,7 +12520,7 @@ module.exports = merge( ); }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/data/examples.js","/../node_modules/rxmarbles/data") -},{"1YiZ5S":19,"buffer":15,"rx":31,"rxmarbles/data/boolean-examples":33,"rxmarbles/data/combine-examples":34,"rxmarbles/data/conditional-examples":35,"rxmarbles/data/filter-examples":37,"rxmarbles/data/math-examples":38,"rxmarbles/data/transform-examples":39}],37:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"rx":23,"rxmarbles/data/boolean-examples":25,"rxmarbles/data/combine-examples":26,"rxmarbles/data/conditional-examples":27,"rxmarbles/data/filter-examples":29,"rxmarbles/data/math-examples":30,"rxmarbles/data/transform-examples":31}],29:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var Rx = require('rx'); @@ -13381,7 +12687,7 @@ module.exports = { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/data/filter-examples.js","/../node_modules/rxmarbles/data") -},{"1YiZ5S":19,"buffer":15,"rx":31}],38:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"rx":23}],30:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var Rx = require('rx'); @@ -13477,7 +12783,7 @@ module.exports = { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/data/math-examples.js","/../node_modules/rxmarbles/data") -},{"1YiZ5S":19,"buffer":15,"rx":31}],39:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"rx":23}],31:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var Rx = require('rx'); @@ -13562,7 +12868,7 @@ module.exports = { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/data/transform-examples.js","/../node_modules/rxmarbles/data") -},{"1YiZ5S":19,"buffer":15,"rx":31}],40:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"rx":23}],32:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ /* * OperatorsMenuIntent @@ -13590,7 +12896,7 @@ module.exports = { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/intents/operators-menu.js","/../node_modules/rxmarbles/intents") -},{"1YiZ5S":19,"buffer":15,"rx":31,"rxmarbles/utils":48}],41:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"rx":23,"rxmarbles/utils":40}],33:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ /* * SandboxIntent @@ -13669,7 +12975,7 @@ module.exports = { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/intents/sandbox.js","/../node_modules/rxmarbles/intents") -},{"1YiZ5S":19,"buffer":15,"rx":31,"rxmarbles/utils":48}],42:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"rx":23,"rxmarbles/utils":40}],34:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ /* * OperatorsMenuModel @@ -13704,7 +13010,7 @@ module.exports = { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/models/operators-menu.js","/../node_modules/rxmarbles/models") -},{"1YiZ5S":19,"buffer":15,"rx":31,"rxmarbles/data/examples":36,"rxmarbles/utils":48}],43:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"rx":23,"rxmarbles/data/examples":28,"rxmarbles/utils":40}],35:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ /* * Functions to handle data of input diagrams in the example shown in the @@ -13842,7 +13148,7 @@ module.exports = { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/models/sandbox-input.js","/../node_modules/rxmarbles/models") -},{"1YiZ5S":19,"buffer":15,"rx":31,"rxmarbles/models/utils":46}],44:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"rx":23,"rxmarbles/models/utils":38}],36:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ /* * Functions to handle data of the output diagram in the example shown in the @@ -13948,7 +13254,7 @@ module.exports = { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/models/sandbox-output.js","/../node_modules/rxmarbles/models") -},{"1YiZ5S":19,"buffer":15,"rx":31,"rxmarbles/models/utils":46}],45:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"rx":23,"rxmarbles/models/utils":38}],37:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ /* * SandboxModel @@ -13981,26 +13287,12 @@ module.exports = { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/models/sandbox.js","/../node_modules/rxmarbles/models") -},{"1YiZ5S":19,"buffer":15,"rx":31,"rxmarbles/models/operators-menu":42,"rxmarbles/models/sandbox-input":43,"rxmarbles/models/sandbox-output":44,"rxmarbles/utils":48}],46:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"rx":23,"rxmarbles/models/operators-menu":34,"rxmarbles/models/sandbox-input":35,"rxmarbles/models/sandbox-output":36,"rxmarbles/utils":40}],38:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ /* * Conversion from virtual time streams out to diagram data, and * vice-versa, and related functions. */ -var Rx = require('rx'); - -// DEPRECATED. Used only in old output-diagram.js -function makeScheduler() { - var scheduler = new Rx.VirtualTimeScheduler(0, function(x, y) { - if (x > y) { return 1; } - if (x < y) { return -1; } - return 0; - }); - scheduler.add = function(absolute, relative) { return absolute + relative; }; - scheduler.toDateTimeOffset = function(absolute) { return Math.floor(absolute); }; - scheduler.toRelative = function(timeSpan) { return timeSpan; }; - return scheduler; -}; function calculateNotificationContentHash(content) { var SOME_PRIME_NUMBER = 877; @@ -14023,92 +13315,52 @@ function calculateNotificationHash(marbleData) { return ((marbleData.time + contentHash + SMALL_PRIME) * LARGE_PRIME) % MAX; }; -// DEPRECATED. Used only in old output-diagram.js -function justIncomplete(item, scheduler) { - return new Rx.AnonymousObservable(function(observer) { - return scheduler.schedule(function() { - observer.onNext(item); - }); - }); -}; - -// DEPRECATED. Used only in old output-diagram.js -/** - * Creates an (virtual time) Rx.Observable from diagram - * data (array of data items). - */ -function toVTStream(diagramData, scheduler) { - var singleMarbleStreams = []; - for (var i = 0; i < diagramData.length; i++) { - var item = diagramData[i]; - singleMarbleStreams.push( - justIncomplete(item, scheduler).delay(item.t || item.time, scheduler) - ); - } - // Necessary correction to include marbles at time exactly diagramData.end: - var correctedEndTime = diagramData.end + 0.01; - return Rx.Observable.merge(singleMarbleStreams) - .takeUntilWithTime(correctedEndTime, scheduler) - .publish().refCount(); -}; - -// DEPRECATED. Used only in old output-diagram.js -function getDiagramPromise(stream, scheduler, maxTime) { - var diagram = []; - var subject = new Rx.BehaviorSubject([]); - stream - .observeOn(scheduler) - .timestamp(scheduler) - .map(function(x) { - if (typeof x.value !== "object") { - x.value = {content: x.value, id: calculateNotificationContentHash(x.value)}; - } - return { - time: (x.timestamp / maxTime) * 100, // converts timestamp to % of maxTime - content: x.value.content, - id: x.value.id - }; - }) - .reduce(function(acc, x) { - acc.push(x); - return acc; - },[]) - .subscribe(function onNext(x) { - diagram = x; - subject.onNext(diagram); - }, function onError() { - console.warn("Error in the diagram promise stream"); - }, function onComplete() { - diagram.end = scheduler.now(); - }); - return subject.asObservable(); -}; - module.exports = { - makeScheduler: makeScheduler, - toVTStream: toVTStream, calculateNotificationHash: calculateNotificationHash, - calculateNotificationContentHash: calculateNotificationContentHash, - getDiagramPromise: getDiagramPromise + calculateNotificationContentHash: calculateNotificationContentHash }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/models/utils.js","/../node_modules/rxmarbles/models") -},{"1YiZ5S":19,"buffer":15,"rx":31}],47:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],39:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ /* * Renderer component. * Subscribes to vtree observables of all view components * and renders them as real DOM elements to the browser. */ -var Package = require('package.json'); -//var Sandbox = require('rxmarbles/views/sandbox'); -var OperatorsMenuView = require('rxmarbles/views/operators-menu'); -var SandboxView = require('rxmarbles/views/new-sandbox'); -var renderVTreeStream = require('rxmarbles/views/utils').renderVTreeStream; +var h = require('virtual-hyperscript'); +var VDOM = { + diff: require('virtual-dom/diff'), + patch: require('virtual-dom/patch') +}; var DOMDelegator = require('dom-delegator'); +var OperatorsMenuView = require('rxmarbles/views/operators-menu'); +var SandboxView = require('rxmarbles/views/sandbox'); +var Package = require('package.json'); var domDelegator; +function renderVTreeStream(vtree$, containerSelector) { + // Find and prepare the container + var container = document.querySelector(containerSelector); + if (container === null) { + console.error("Couldn't render into unknown '" + containerSelector + "'"); + return false; + } + container.innerHTML = ""; + // Make the DOM node bound to the VDOM node + var rootNode = document.createElement("div"); + container.appendChild(rootNode); + vtree$.startWith(h()) + .bufferWithCount(2, 1) + .subscribe(function(buffer) { + var oldVTree = buffer[0]; + var newVTree = buffer[1]; + rootNode = VDOM.patch(rootNode, VDOM.diff(oldVTree, newVTree)); + }); + return true; +}; + function renderAppVersionOnce() { var versionElement = document.querySelector("a.js-appVersion"); versionElement.textContent = "v" + Package.version; @@ -14135,7 +13387,7 @@ module.exports = { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/renderer.js","/../node_modules/rxmarbles") -},{"1YiZ5S":19,"buffer":15,"dom-delegator":3,"package.json":28,"rxmarbles/views/new-sandbox":52,"rxmarbles/views/operators-menu":53,"rxmarbles/views/utils":57}],48:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"dom-delegator":3,"package.json":20,"rxmarbles/views/operators-menu":44,"rxmarbles/views/sandbox":48,"virtual-dom/diff":49,"virtual-dom/patch":68,"virtual-hyperscript":73}],40:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ /* * Utility functions @@ -14164,30 +13416,15 @@ module.exports = { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/utils.js","/../node_modules/rxmarbles") -},{"1YiZ5S":19,"buffer":15}],49:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],41:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ /* * Renders a marker for the completion notification of a stream diagram. */ -var h = require('hyperscript'); -var vh = require('virtual-hyperscript'); -var Utils = require('rxmarbles/views/utils'); +var h = require('virtual-hyperscript'); var MARBLE_WIDTH = 5; // estimate of a marble width, in percentages -function render(completionTime) { - var element = h('div.diagramCompletion.is-draggable.js-completion', {}, [ - h('div.diagramCompletion-inner') - ]); - element.dataStream = Utils.getInteractiveLeftPosStream(element, completionTime); - element.dataStream - .subscribe(function(leftPos) { - element.style.left = leftPos + '%'; - return true; - }); - return element; -} - function vrender(completionData, isDraggable, diagramData, mouseDown$) { if (typeof isDraggable === 'undefined') { isDraggable = false; @@ -14200,22 +13437,21 @@ function vrender(completionData, isDraggable, diagramData, mouseDown$) { } }); var isTallClass = (isTall) ? '.is-tall' : ''; - return vh('div.diagramCompletion' + isDraggableClass + isTallClass, { + return h('div.diagramCompletion' + isDraggableClass + isTallClass, { style: {'left': completionData.time + '%'}, attributes: {'data-diagram-id': completionData.diagramId}, 'ev-mousedown': function(ev) { if (mouseDown$) { mouseDown$.onNext(ev); } } },[ - vh('div.diagramCompletion-inner') + h('div.diagramCompletion-inner') ]); } module.exports = { - render: render, vrender: vrender }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/views/completion.js","/../node_modules/rxmarbles/views") -},{"1YiZ5S":19,"buffer":15,"hyperscript":20,"rxmarbles/views/utils":57,"virtual-hyperscript":83}],50:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"virtual-hyperscript":73}],42:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ /* * Virtually renders a stream diagram. @@ -14249,92 +13485,24 @@ module.exports = { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/views/diagram.js","/../node_modules/rxmarbles/views") -},{"1YiZ5S":19,"buffer":15,"rx":31,"rxmarbles/views/completion":49,"rxmarbles/views/marble":51,"virtual-hyperscript":83}],51:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"rx":23,"rxmarbles/views/completion":41,"rxmarbles/views/marble":43,"virtual-hyperscript":73}],43:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ /* * Renders a circle or similar shape to represent an emitted item on a stream. */ -var Rx = require('rx'); -var Utils = require('rxmarbles/views/utils'); -var vh = require('virtual-hyperscript'); +var h = require('virtual-hyperscript'); var svg = require('virtual-hyperscript/svg'); -var XMLNS = 'http://www.w3.org/2000/svg'; var NUM_COLORS = 4; -var SVG_VIEWBOX = '0 0 1 1'; -var SVG_CX = 0.5; -var SVG_CY = 0.5; -var SVG_R = 0.47; -var SVG_BORDER_WIDTH = '0.06px'; - -function createRootElement(draggable) { - var container = document.createElement('div'); - container.className = 'marble js-marble'; - if (draggable) { - container.className += ' is-draggable'; - } - return container; -} - -function createMarbleSvg(item) { - var colornum = (item.id % NUM_COLORS) + 1; - var marble = document.createElementNS(XMLNS, 'svg'); - marble.setAttribute('class', 'marble-inner'); - marble.setAttribute('viewBox', SVG_VIEWBOX); - var circle = document.createElementNS(XMLNS, 'circle'); - circle.setAttribute('cx', SVG_CX); - circle.setAttribute('cy', SVG_CY); - circle.setAttribute('r', SVG_R); - circle.setAttribute('class', 'marble-shape marble-shape--color' + colornum); - circle.setAttribute('stroke-width', SVG_BORDER_WIDTH); - marble.appendChild(circle); - return marble; -} - -function createContentElement(item) { - var content = document.createElement('p'); - content.className = 'marble-content'; - content.textContent = (item != null) ? item.content : ''; - return content; -} - -function getLeftPosStream(item, draggable, element) { - if (draggable) { - return Utils.getInteractiveLeftPosStream(element, item.time); - } else { - return Rx.Observable.just(item.time); - } -} - -function render(item, draggable) { - if (draggable == null) { - draggable = false; - } - // Create DOM elements - var marble = createRootElement(draggable); - marble.appendChild(createMarbleSvg(item)); - marble.appendChild(createContentElement(item)); - // Define public and private streams - var leftPosStream = getLeftPosStream(item, draggable, marble); - marble.dataStream = leftPosStream - .map(function(leftPos) { - return {time: leftPos, content: item.content, id: item.id}; - }); - leftPosStream - .subscribe(function(leftPos) { - marble.style.left = leftPos + '%'; - }); - return marble; -} function vrender(marbleData, isDraggable, mouseDown$) { if (typeof isDraggable === 'undefined') { isDraggable = false; } - var colornum = (marbleData.id % 4) + 1; + var colornum = (marbleData.id % NUM_COLORS) + 1; var leftPos = '' + marbleData.time + '%'; var content = '' + marbleData.content; - return vh('div.marble.js-marble'+(isDraggable ? '.is-draggable' :''), { + return h('div.marble.js-marble'+(isDraggable ? '.is-draggable' :''), { style: {'left': leftPos}, attributes: { 'data-marble-id': marbleData.id, @@ -14346,71 +13514,25 @@ function vrender(marbleData, isDraggable, mouseDown$) { } } },[ - svg('svg', {attributes: {'class': 'marble-inner', viewBox: SVG_VIEWBOX}}, [ + svg('svg', {attributes: {'class': 'marble-inner', viewBox: '0 0 1 1'}}, [ svg('circle', { attributes: { 'class': 'marble-shape marble-shape--color' + colornum, - cx: SVG_CX, cy: SVG_CY, r: SVG_R, - 'stroke-width': SVG_BORDER_WIDTH + cx: 0.5, cy: 0.5, r: 0.47, + 'stroke-width': '0.06px' } }) ]), - vh('p.marble-content', {}, content) + h('p.marble-content', {}, content) ]); } module.exports = { - render: render, vrender: vrender }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/views/marble.js","/../node_modules/rxmarbles/views") -},{"1YiZ5S":19,"buffer":15,"rx":31,"rxmarbles/views/utils":57,"virtual-hyperscript":83,"virtual-hyperscript/svg":102}],52:[function(require,module,exports){ -(function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ -/* - * Renders a scrollable list of operators to be demonstrated on the sandbox. - */ -var Rx = require('rx'); -var h = require('virtual-hyperscript'); -var SandboxInput = require('rxmarbles/views/sandbox-input'); -var SandboxOperator = require('rxmarbles/views/sandbox-operator'); -var SandboxOutput = require('rxmarbles/views/sandbox-output'); -var replicate = require('rxmarbles/utils').replicate; - -var modelExample$ = new Rx.BehaviorSubject(); -var modelInputDiagrams$ = new Rx.BehaviorSubject(); -var modelOutputDiagram$ = new Rx.BehaviorSubject(); -var marbleMouseDown$ = new Rx.Subject(); -var completionMouseDown$ = new Rx.Subject(); - -function observe(model) { - replicate(model.example$, modelExample$); - replicate(model.inputDiagrams$, modelInputDiagrams$); - replicate(model.outputDiagram$, modelOutputDiagram$); -} - -var vtree$ = Rx.Observable - .combineLatest(modelExample$, modelInputDiagrams$, modelOutputDiagram$, - function(example, inputDiagrams, outputDiagram) { - return h("div.sandbox", [ - SandboxInput.vrender(inputDiagrams, marbleMouseDown$, completionMouseDown$), - SandboxOperator.vrender(example), - SandboxOutput.vrender(outputDiagram) - ]); - } - ); - -//marbleMouseDown$.subscribe(function(ev) { console.log("LOOK!"); console.log(ev); }); - -module.exports = { - observe: observe, - vtree$: vtree$, - marbleMouseDown$: marbleMouseDown$, - completionMouseDown$: completionMouseDown$ -}; - -}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/views/new-sandbox.js","/../node_modules/rxmarbles/views") -},{"1YiZ5S":19,"buffer":15,"rx":31,"rxmarbles/utils":48,"rxmarbles/views/sandbox-input":54,"rxmarbles/views/sandbox-operator":55,"rxmarbles/views/sandbox-output":56,"virtual-hyperscript":83}],53:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"virtual-hyperscript":73,"virtual-hyperscript/svg":92}],44:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ /* * Renders a scrollable list of operators to be demonstrated on the sandbox. @@ -14495,7 +13617,7 @@ module.exports = { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/views/operators-menu.js","/../node_modules/rxmarbles/views") -},{"1YiZ5S":19,"buffer":15,"rx":31,"rxmarbles/utils":48,"virtual-hyperscript":83}],54:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"rx":23,"rxmarbles/utils":40,"virtual-hyperscript":73}],45:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ /* * Virtually renders stream diagrams meant as inputs to the sandbox. @@ -14517,7 +13639,7 @@ module.exports = { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/views/sandbox-input.js","/../node_modules/rxmarbles/views") -},{"1YiZ5S":19,"buffer":15,"rx":31,"rxmarbles/views/diagram":50,"virtual-hyperscript":83}],55:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"rx":23,"rxmarbles/views/diagram":42,"virtual-hyperscript":73}],46:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ /* * Renders a box representing the Rx operator being applied on the input @@ -14540,7 +13662,7 @@ module.exports = { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/views/sandbox-operator.js","/../node_modules/rxmarbles/views") -},{"1YiZ5S":19,"buffer":15,"rx":31,"virtual-hyperscript":83}],56:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"rx":23,"virtual-hyperscript":73}],47:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ /* * Virtually renders a stream diagram meant as the output of the sandbox. @@ -14558,117 +13680,57 @@ module.exports = { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/views/sandbox-output.js","/../node_modules/rxmarbles/views") -},{"1YiZ5S":19,"buffer":15,"rx":31,"rxmarbles/views/diagram":50,"virtual-hyperscript":83}],57:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"rx":23,"rxmarbles/views/diagram":42,"virtual-hyperscript":73}],48:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ /* - * Util functions for rendering to the DOM. + * SandboxView */ var Rx = require('rx'); var h = require('virtual-hyperscript'); -var VDOM = { - createElement: require('virtual-dom/create-element'), - diff: require('virtual-dom/diff'), - patch: require('virtual-dom/patch') -}; +var SandboxInput = require('rxmarbles/views/sandbox-input'); +var SandboxOperator = require('rxmarbles/views/sandbox-operator'); +var SandboxOutput = require('rxmarbles/views/sandbox-output'); +var replicate = require('rxmarbles/utils').replicate; -function getDxDragStream(element) { - return Rx.Observable.fromEvent(element, "mousedown") - .map(function() { - var moveStream = Rx.Observable.fromEvent(document, "mousemove"); - var upStream = Rx.Observable.fromEvent(document, "mouseup"); - var dxStream = moveStream - .map(function(ev) { - ev.stopPropagation; - ev.preventDefault(); - return ev.pageX; - }) - .windowWithCount(2, 1) - .flatMap(function(result) { return result.toArray(); }) - .map(function(array) { return array[1] - array[0]; }); - return dxStream.takeUntil(upStream); - }) - .concatAll(); -} +var modelExample$ = new Rx.BehaviorSubject(); +var modelInputDiagrams$ = new Rx.BehaviorSubject(); +var modelOutputDiagram$ = new Rx.BehaviorSubject(); +var marbleMouseDown$ = new Rx.Subject(); +var completionMouseDown$ = new Rx.Subject(); -function getInteractiveLeftPosStream(element, initialPos) { - return getDxDragStream(element) - .scan(initialPos, function(acc, dx) { - var pxToPercentage = 1; - try { - pxToPercentage = 100.0 / element.parentElement.clientWidth; - } catch (err) { - console.warn(err); - } - return acc + (dx * pxToPercentage); - }) - .map(function(pos) { - if (pos < 0) { return 0; } - if (pos > 100) { return 100; } - return pos; - }) - .map(Math.round) - .startWith(initialPos) - .distinctUntilChanged(); +function observe(model) { + replicate(model.example$, modelExample$); + replicate(model.inputDiagrams$, modelInputDiagrams$); + replicate(model.outputDiagram$, modelOutputDiagram$); } -function renderVTreeStream(vtree$, containerSelector) { - // Find and prepare the container - var container = document.querySelector(containerSelector); - if (container === null) { - console.error("Couldn't render into unknown '" + containerSelector + "'"); - return false; - } - container.innerHTML = ""; - // Make the DOM node bound to the VDOM node - var rootNode = document.createElement("div"); - container.appendChild(rootNode); - vtree$.startWith(h()) - .bufferWithCount(2, 1) - .subscribe(function(buffer) { - var oldVTree = buffer[0]; - var newVTree = buffer[1]; - rootNode = VDOM.patch(rootNode, VDOM.diff(oldVTree, newVTree)); - }); - return true; -}; - -function renderObservableDOMElement(elementStream) { - var wrapper = document.createElement("div"); - elementStream.subscribe(function(thing) { - wrapper.innerHTML = ""; - if (Array.isArray(thing)) { - for (i = 0; i < thing.length; i++) { - wrapper.appendChild(thing[i]); - } - } else if (thing instanceof Element) { - wrapper.appendChild(thing); +var vtree$ = Rx.Observable + .combineLatest(modelExample$, modelInputDiagrams$, modelOutputDiagram$, + function(example, inputDiagrams, outputDiagram) { + return h("div.sandbox", [ + SandboxInput.vrender(inputDiagrams, marbleMouseDown$, completionMouseDown$), + SandboxOperator.vrender(example), + SandboxOutput.vrender(outputDiagram) + ]); } - }); - return wrapper; -}; + ); module.exports = { - renderVTreeStream: renderVTreeStream, - renderObservableDOMElement: renderObservableDOMElement, - getInteractiveLeftPosStream: getInteractiveLeftPosStream + observe: observe, + vtree$: vtree$, + marbleMouseDown$: marbleMouseDown$, + completionMouseDown$: completionMouseDown$ }; -}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/views/utils.js","/../node_modules/rxmarbles/views") -},{"1YiZ5S":19,"buffer":15,"rx":31,"virtual-dom/create-element":58,"virtual-dom/diff":59,"virtual-dom/patch":78,"virtual-hyperscript":83}],58:[function(require,module,exports){ -(function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ -var createElement = require("vdom/create-element") - -module.exports = createElement - -}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/create-element.js","/../node_modules/virtual-dom") -},{"1YiZ5S":19,"buffer":15,"vdom/create-element":62}],59:[function(require,module,exports){ +}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/views/sandbox.js","/../node_modules/rxmarbles/views") +},{"1YiZ5S":19,"buffer":15,"rx":23,"rxmarbles/utils":40,"rxmarbles/views/sandbox-input":45,"rxmarbles/views/sandbox-operator":46,"rxmarbles/views/sandbox-output":47,"virtual-hyperscript":73}],49:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var diff = require("vtree/diff") module.exports = diff }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/diff.js","/../node_modules/virtual-dom") -},{"1YiZ5S":19,"buffer":15,"vtree/diff":68}],60:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"vtree/diff":58}],50:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ module.exports = isObject @@ -14677,7 +13739,7 @@ function isObject(x) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/is-object/index.js","/../node_modules/virtual-dom/node_modules/is-object") -},{"1YiZ5S":19,"buffer":15}],61:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],51:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var isObject = require("is-object") var isHook = require("vtree/is-vhook") @@ -14773,7 +13835,7 @@ function getPrototype(value) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vdom/apply-properties.js","/../node_modules/virtual-dom/node_modules/vdom") -},{"1YiZ5S":19,"buffer":15,"is-object":60,"vtree/is-vhook":71}],62:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"is-object":50,"vtree/is-vhook":61}],52:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var document = require("global/document") @@ -14823,7 +13885,7 @@ function createElement(vnode, opts) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vdom/create-element.js","/../node_modules/virtual-dom/node_modules/vdom") -},{"./apply-properties":61,"1YiZ5S":19,"buffer":15,"global/document":64,"vtree/handle-thunk":69,"vtree/is-vnode":72,"vtree/is-vtext":73,"vtree/is-widget":74}],63:[function(require,module,exports){ +},{"./apply-properties":51,"1YiZ5S":19,"buffer":15,"global/document":54,"vtree/handle-thunk":59,"vtree/is-vnode":62,"vtree/is-vtext":63,"vtree/is-widget":64}],53:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ // Maps a virtual DOM tree onto a real DOM tree in an efficient manner. // We don't want to read all of the DOM nodes in the tree so we use @@ -14912,7 +13974,7 @@ function ascending(a, b) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vdom/dom-index.js","/../node_modules/virtual-dom/node_modules/vdom") -},{"1YiZ5S":19,"buffer":15}],64:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],54:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var topLevel = typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : {} @@ -14931,7 +13993,7 @@ if (typeof document !== 'undefined') { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vdom/node_modules/global/document.js","/../node_modules/virtual-dom/node_modules/vdom/node_modules/global") -},{"1YiZ5S":19,"buffer":15,"min-document":14}],65:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"min-document":14}],55:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var applyProperties = require("./apply-properties") @@ -15103,7 +14165,7 @@ function replaceRoot(oldRoot, newRoot) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vdom/patch-op.js","/../node_modules/virtual-dom/node_modules/vdom") -},{"./apply-properties":61,"./create-element":62,"./update-widget":67,"1YiZ5S":19,"buffer":15,"vtree/is-widget":74,"vtree/vpatch":76}],66:[function(require,module,exports){ +},{"./apply-properties":51,"./create-element":52,"./update-widget":57,"1YiZ5S":19,"buffer":15,"vtree/is-widget":64,"vtree/vpatch":66}],56:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var document = require("global/document") var isArray = require("x-is-array") @@ -15183,7 +14245,7 @@ function patchIndices(patches) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vdom/patch.js","/../node_modules/virtual-dom/node_modules/vdom") -},{"./dom-index":63,"./patch-op":65,"1YiZ5S":19,"buffer":15,"global/document":64,"x-is-array":77}],67:[function(require,module,exports){ +},{"./dom-index":53,"./patch-op":55,"1YiZ5S":19,"buffer":15,"global/document":54,"x-is-array":67}],57:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var isWidget = require("vtree/is-widget") @@ -15202,7 +14264,7 @@ function updateWidget(a, b) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vdom/update-widget.js","/../node_modules/virtual-dom/node_modules/vdom") -},{"1YiZ5S":19,"buffer":15,"vtree/is-widget":74}],68:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"vtree/is-widget":64}],58:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var isArray = require("x-is-array") var isObject = require("is-object") @@ -15551,7 +14613,7 @@ function appendPatch(apply, patch) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vtree/diff.js","/../node_modules/virtual-dom/node_modules/vtree") -},{"./handle-thunk":69,"./is-thunk":70,"./is-vnode":72,"./is-vtext":73,"./is-widget":74,"./vpatch":76,"1YiZ5S":19,"buffer":15,"is-object":60,"x-is-array":77}],69:[function(require,module,exports){ +},{"./handle-thunk":59,"./is-thunk":60,"./is-vnode":62,"./is-vtext":63,"./is-widget":64,"./vpatch":66,"1YiZ5S":19,"buffer":15,"is-object":50,"x-is-array":67}],59:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var isVNode = require("./is-vnode") var isVText = require("./is-vtext") @@ -15595,7 +14657,7 @@ function renderThunk(thunk, previous) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vtree/handle-thunk.js","/../node_modules/virtual-dom/node_modules/vtree") -},{"./is-thunk":70,"./is-vnode":72,"./is-vtext":73,"./is-widget":74,"1YiZ5S":19,"buffer":15}],70:[function(require,module,exports){ +},{"./is-thunk":60,"./is-vnode":62,"./is-vtext":63,"./is-widget":64,"1YiZ5S":19,"buffer":15}],60:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ module.exports = isThunk @@ -15604,7 +14666,7 @@ function isThunk(t) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vtree/is-thunk.js","/../node_modules/virtual-dom/node_modules/vtree") -},{"1YiZ5S":19,"buffer":15}],71:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],61:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ module.exports = isHook @@ -15614,7 +14676,7 @@ function isHook(hook) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vtree/is-vhook.js","/../node_modules/virtual-dom/node_modules/vtree") -},{"1YiZ5S":19,"buffer":15}],72:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],62:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var version = require("./version") @@ -15625,7 +14687,7 @@ function isVirtualNode(x) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vtree/is-vnode.js","/../node_modules/virtual-dom/node_modules/vtree") -},{"./version":75,"1YiZ5S":19,"buffer":15}],73:[function(require,module,exports){ +},{"./version":65,"1YiZ5S":19,"buffer":15}],63:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var version = require("./version") @@ -15636,7 +14698,7 @@ function isVirtualText(x) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vtree/is-vtext.js","/../node_modules/virtual-dom/node_modules/vtree") -},{"./version":75,"1YiZ5S":19,"buffer":15}],74:[function(require,module,exports){ +},{"./version":65,"1YiZ5S":19,"buffer":15}],64:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ module.exports = isWidget @@ -15645,12 +14707,12 @@ function isWidget(w) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vtree/is-widget.js","/../node_modules/virtual-dom/node_modules/vtree") -},{"1YiZ5S":19,"buffer":15}],75:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],65:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ module.exports = "1" }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vtree/version.js","/../node_modules/virtual-dom/node_modules/vtree") -},{"1YiZ5S":19,"buffer":15}],76:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],66:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var version = require("./version") @@ -15676,7 +14738,7 @@ VirtualPatch.prototype.version = version VirtualPatch.prototype.type = "VirtualPatch" }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vtree/vpatch.js","/../node_modules/virtual-dom/node_modules/vtree") -},{"./version":75,"1YiZ5S":19,"buffer":15}],77:[function(require,module,exports){ +},{"./version":65,"1YiZ5S":19,"buffer":15}],67:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var nativeIsArray = Array.isArray var toString = Object.prototype.toString @@ -15688,14 +14750,14 @@ function isArray(obj) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/x-is-array/index.js","/../node_modules/virtual-dom/node_modules/x-is-array") -},{"1YiZ5S":19,"buffer":15}],78:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],68:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var patch = require("vdom/patch") module.exports = patch }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/patch.js","/../node_modules/virtual-dom") -},{"1YiZ5S":19,"buffer":15,"vdom/patch":66}],79:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"vdom/patch":56}],69:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ module.exports = AttributeHook; @@ -15716,7 +14778,7 @@ AttributeHook.prototype.hook = function (node, prop, prev) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/hooks/attribute-hook.js","/../node_modules/virtual-hyperscript/hooks") -},{"1YiZ5S":19,"buffer":15}],80:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],70:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var DataSet = require("data-set") @@ -15738,7 +14800,7 @@ DataSetHook.prototype.hook = function (node, propertyName) { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/hooks/data-set-hook.js","/../node_modules/virtual-hyperscript/hooks") -},{"1YiZ5S":19,"buffer":15,"data-set":85}],81:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"data-set":75}],71:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var DataSet = require("data-set") @@ -15760,7 +14822,7 @@ DataSetHook.prototype.hook = function (node, propertyName) { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/hooks/ev-hook.js","/../node_modules/virtual-hyperscript/hooks") -},{"1YiZ5S":19,"buffer":15,"data-set":85}],82:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"data-set":75}],72:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ module.exports = SoftSetHook; @@ -15779,7 +14841,7 @@ SoftSetHook.prototype.hook = function (node, propertyName) { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/hooks/soft-set-hook.js","/../node_modules/virtual-hyperscript/hooks") -},{"1YiZ5S":19,"buffer":15}],83:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],73:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var VNode = require("vtree/vnode.js") var VText = require("vtree/vtext.js") @@ -15909,7 +14971,7 @@ function isChildren(x) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/index.js","/../node_modules/virtual-hyperscript") -},{"./hooks/data-set-hook.js":80,"./hooks/ev-hook.js":81,"./hooks/soft-set-hook.js":82,"./parse-tag.js":101,"1YiZ5S":19,"buffer":15,"error/typed":92,"vtree/is-thunk":93,"vtree/is-vhook":94,"vtree/is-vnode":95,"vtree/is-vtext":96,"vtree/is-widget":97,"vtree/vnode.js":99,"vtree/vtext.js":100}],84:[function(require,module,exports){ +},{"./hooks/data-set-hook.js":70,"./hooks/ev-hook.js":71,"./hooks/soft-set-hook.js":72,"./parse-tag.js":91,"1YiZ5S":19,"buffer":15,"error/typed":82,"vtree/is-thunk":83,"vtree/is-vhook":84,"vtree/is-vnode":85,"vtree/is-vtext":86,"vtree/is-widget":87,"vtree/vnode.js":89,"vtree/vtext.js":90}],74:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ module.exports = createHash @@ -15935,7 +14997,7 @@ function createHash(elem) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/data-set/create-hash.js","/../node_modules/virtual-hyperscript/node_modules/data-set") -},{"1YiZ5S":19,"buffer":15}],85:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],75:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var createStore = require("weakmap-shim/create-store") var Individual = require("individual") @@ -15957,7 +15019,7 @@ function DataSet(elem) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/data-set/index.js","/../node_modules/virtual-hyperscript/node_modules/data-set") -},{"./create-hash.js":84,"1YiZ5S":19,"buffer":15,"individual":86,"weakmap-shim/create-store":87}],86:[function(require,module,exports){ +},{"./create-hash.js":74,"1YiZ5S":19,"buffer":15,"individual":76,"weakmap-shim/create-store":77}],76:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var root = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? @@ -15979,7 +15041,7 @@ function Individual(key, value) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/data-set/node_modules/individual/index.js","/../node_modules/virtual-hyperscript/node_modules/data-set/node_modules/individual") -},{"1YiZ5S":19,"buffer":15}],87:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],77:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var hiddenStore = require('./hidden-store.js'); @@ -16000,7 +15062,7 @@ function createStore() { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/data-set/node_modules/weakmap-shim/create-store.js","/../node_modules/virtual-hyperscript/node_modules/data-set/node_modules/weakmap-shim") -},{"./hidden-store.js":88,"1YiZ5S":19,"buffer":15}],88:[function(require,module,exports){ +},{"./hidden-store.js":78,"1YiZ5S":19,"buffer":15}],78:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ module.exports = hiddenStore; @@ -16020,7 +15082,7 @@ function hiddenStore(obj, key) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/data-set/node_modules/weakmap-shim/hidden-store.js","/../node_modules/virtual-hyperscript/node_modules/data-set/node_modules/weakmap-shim") -},{"1YiZ5S":19,"buffer":15}],89:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],79:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ module.exports = function(obj) { if (typeof obj === 'string') return camelCase(obj); @@ -16083,7 +15145,7 @@ function reduce (xs, f, acc) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/error/node_modules/camelize/index.js","/../node_modules/virtual-hyperscript/node_modules/error/node_modules/camelize") -},{"1YiZ5S":19,"buffer":15}],90:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],80:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var nargs = /\{([0-9a-zA-Z]+)\}/g var slice = Array.prototype.slice @@ -16121,7 +15183,7 @@ function template(string) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/error/node_modules/string-template/index.js","/../node_modules/virtual-hyperscript/node_modules/error/node_modules/string-template") -},{"1YiZ5S":19,"buffer":15}],91:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],81:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ module.exports = extend @@ -16140,7 +15202,7 @@ function extend(target) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/error/node_modules/xtend/mutable.js","/../node_modules/virtual-hyperscript/node_modules/error/node_modules/xtend") -},{"1YiZ5S":19,"buffer":15}],92:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],82:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var camelize = require("camelize") var template = require("string-template") @@ -16192,7 +15254,7 @@ function TypedError(args) { }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/error/typed.js","/../node_modules/virtual-hyperscript/node_modules/error") -},{"1YiZ5S":19,"buffer":15,"camelize":89,"string-template":90,"xtend/mutable":91}],93:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"camelize":79,"string-template":80,"xtend/mutable":81}],83:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ module.exports = isThunk @@ -16201,7 +15263,7 @@ function isThunk(t) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/vtree/is-thunk.js","/../node_modules/virtual-hyperscript/node_modules/vtree") -},{"1YiZ5S":19,"buffer":15}],94:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],84:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ module.exports = isHook @@ -16211,7 +15273,7 @@ function isHook(hook) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/vtree/is-vhook.js","/../node_modules/virtual-hyperscript/node_modules/vtree") -},{"1YiZ5S":19,"buffer":15}],95:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],85:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var version = require("./version") @@ -16222,7 +15284,7 @@ function isVirtualNode(x) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/vtree/is-vnode.js","/../node_modules/virtual-hyperscript/node_modules/vtree") -},{"./version":98,"1YiZ5S":19,"buffer":15}],96:[function(require,module,exports){ +},{"./version":88,"1YiZ5S":19,"buffer":15}],86:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var version = require("./version") @@ -16233,7 +15295,7 @@ function isVirtualText(x) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/vtree/is-vtext.js","/../node_modules/virtual-hyperscript/node_modules/vtree") -},{"./version":98,"1YiZ5S":19,"buffer":15}],97:[function(require,module,exports){ +},{"./version":88,"1YiZ5S":19,"buffer":15}],87:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ module.exports = isWidget @@ -16242,12 +15304,12 @@ function isWidget(w) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/vtree/is-widget.js","/../node_modules/virtual-hyperscript/node_modules/vtree") -},{"1YiZ5S":19,"buffer":15}],98:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],88:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ module.exports = "1" }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/vtree/version.js","/../node_modules/virtual-hyperscript/node_modules/vtree") -},{"1YiZ5S":19,"buffer":15}],99:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],89:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var version = require("./version") var isVNode = require("./is-vnode") @@ -16314,7 +15376,7 @@ VirtualNode.prototype.version = version VirtualNode.prototype.type = "VirtualNode" }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/vtree/vnode.js","/../node_modules/virtual-hyperscript/node_modules/vtree") -},{"./is-vhook":94,"./is-vnode":95,"./is-widget":97,"./version":98,"1YiZ5S":19,"buffer":15}],100:[function(require,module,exports){ +},{"./is-vhook":84,"./is-vnode":85,"./is-widget":87,"./version":88,"1YiZ5S":19,"buffer":15}],90:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var version = require("./version") @@ -16328,7 +15390,7 @@ VirtualText.prototype.version = version VirtualText.prototype.type = "VirtualText" }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/vtree/vtext.js","/../node_modules/virtual-hyperscript/node_modules/vtree") -},{"./version":98,"1YiZ5S":19,"buffer":15}],101:[function(require,module,exports){ +},{"./version":88,"1YiZ5S":19,"buffer":15}],91:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var classIdSplit = /([\.#]?[a-zA-Z0-9_:-]+)/ var notClassId = /^\.|#/ @@ -16381,7 +15443,7 @@ function parseTag(tag, props) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/parse-tag.js","/../node_modules/virtual-hyperscript") -},{"1YiZ5S":19,"buffer":15}],102:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],92:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var attributeHook = require("./hooks/attribute-hook.js") var h = require("./index.js") @@ -16436,7 +15498,7 @@ function isChildren(x) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/svg.js","/../node_modules/virtual-hyperscript") -},{"./hooks/attribute-hook.js":79,"./index.js":83,"1YiZ5S":19,"buffer":15}],103:[function(require,module,exports){ +},{"./hooks/attribute-hook.js":69,"./index.js":73,"1YiZ5S":19,"buffer":15}],93:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ /* * App entry-point. @@ -16446,7 +15508,7 @@ var OperatorsMenuModel = require('rxmarbles/models/operators-menu'); var OperatorsMenuView = require('rxmarbles/views/operators-menu'); var OperatorsMenuIntent = require('rxmarbles/intents/operators-menu'); var SandboxModel = require('rxmarbles/models/sandbox'); -var SandboxView = require('rxmarbles/views/new-sandbox'); +var SandboxView = require('rxmarbles/views/sandbox'); var SandboxIntent = require('rxmarbles/intents/sandbox'); var renderer = require('rxmarbles/renderer'); @@ -16454,6 +15516,6 @@ binder(OperatorsMenuModel, OperatorsMenuView, OperatorsMenuIntent); binder(SandboxModel, SandboxView, SandboxIntent); renderer.init(); -}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/fake_195b528e.js","/") -},{"1YiZ5S":19,"buffer":15,"rxmarbles/binder":32,"rxmarbles/intents/operators-menu":40,"rxmarbles/intents/sandbox":41,"rxmarbles/models/operators-menu":42,"rxmarbles/models/sandbox":45,"rxmarbles/renderer":47,"rxmarbles/views/new-sandbox":52,"rxmarbles/views/operators-menu":53}]},{},[103]) -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi9Vc2Vycy9hbWVkL0hvYmJ5L3J4bWFyYmxlcy9ub2RlX21vZHVsZXMvZ3VscC1icm93c2VyaWZ5L25vZGVfbW9kdWxlcy9icm93c2VyaWZ5L25vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCIvVXNlcnMvYW1lZC9Ib2JieS9yeG1hcmJsZXMvbm9kZV9tb2R1bGVzL2RvbS1kZWxlZ2F0b3IvYWRkLWV2ZW50LmpzIiwiL1VzZXJzL2FtZWQvSG9iYn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gZS5hcHBlbmRDaGlsZChyID0gbClcbiAgICAgIGVsc2UgaWYobCBpbnN0YW5jZW9mIFRleHQpXG4gICAgICAgIGUuYXBwZW5kQ2hpbGQociA9IGwpXG4gICAgICBlbHNlIGlmICgnb2JqZWN0JyA9PT0gdHlwZW9mIGwpIHtcbiAgICAgICAgZm9yICh2YXIgayBpbiBsKSB7XG4gICAgICAgICAgaWYoJ2Z1bmN0aW9uJyA9PT0gdHlwZW9mIGxba10pIHtcbiAgICAgICAgICAgIGlmKC9eb25cXHcrLy50ZXN0KGspKSB7XG4gICAgICAgICAgICAgIGlmIChlLmFkZEV2ZW50TGlzdGVuZXIpe1xuICAgICAgICAgICAgICAgIGUuYWRkRXZlbnRMaXN0ZW5lcihrLnN1YnN0cmluZygyKSwgbFtrXSwgZmFsc2UpXG4gICAgICAgICAgICAgICAgY2xlYW51cEZ1bmNzLnB1c2goZnVuY3Rpb24oKXtcbiAgICAgICAgICAgICAgICAgIGUucmVtb3ZlRXZlbnRMaXN0ZW5lcihrLnN1YnN0cmluZygyKSwgbFtrXSwgZmFsc2UpXG4gICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgICAgfWVsc2V7XG4gICAgICAgICAgICAgICAgZS5hdHRhY2hFdmVudChrLCBsW2tdKVxuICAgICAgICAgICAgICAgIGNsZWFudXBGdW5jcy5wdXNoKGZ1bmN0aW9uKCl7XG4gICAgICAgICAgICAgICAgICBlLmRldGFjaEV2ZW50KGssIGxba10pXG4gICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgLy8gb2JzZXJ2YWJsZVxuICAgICAgICAgICAgICBlW2tdID0gbFtrXSgpXG4gICAgICAgICAgICAgIGNsZWFudXBGdW5jcy5wdXNoKGxba10oZnVuY3Rpb24gKHYpIHtcbiAgICAgICAgICAgICAgICBlW2tdID0gdlxuICAgICAgICAgICAgICB9KSlcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgICAgZWxzZSBpZihrID09PSAnc3R5bGUnKSB7XG4gICAgICAgICAgICBpZignc3RyaW5nJyA9PT0gdHlwZW9mIGxba10pIHtcbiAgICAgICAgICAgICAgZS5zdHlsZS5jc3NUZXh0ID0gbFtrXVxuICAgICAgICAgICAgfWVsc2V7XG4gICAgICAgICAgICAgIGZvciAodmFyIHMgaW4gbFtrXSkgKGZ1bmN0aW9uKHMsIHYpIHtcbiAgICAgICAgICAgICAgICBpZignZnVuY3Rpb24nID09PSB0eXBlb2Ygdikge1xuICAgICAgICAgICAgICAgICAgLy8gb2JzZXJ2YWJsZVxuICAgICAgICAgICAgICAgICAgZS5zdHlsZS5zZXRQcm9wZXJ0eShzLCB2KCkpXG4gICAgICAgICAgICAgICAgICBjbGVhbnVwRnVuY3MucHVzaCh2KGZ1bmN0aW9uICh2YWwpIHtcbiAgICAgICAgICAgICAgICAgICAgZS5zdHlsZS5zZXRQcm9wZXJ0eShzLCB2YWwpXG4gICAgICAgICAgICAgICAgICB9KSlcbiAgICAgICAgICAgICAgICB9IGVsc2VcbiAgICAgICAgICAgICAgICAgIGUuc3R5bGUuc2V0UHJvcGVydHkocywgbFtrXVtzXSlcbiAgICAgICAgICAgICAgfSkocywgbFtrXVtzXSlcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9IGVsc2UgaWYgKGsuc3Vic3RyKDAsIDUpID09PSBcImRhdGEtXCIpIHtcbiAgICAgICAgICAgIERhdGFTZXQoZSlbay5zdWJzdHIoNSldID0gbFtrXVxuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBlW2tdID0gbFtrXVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfSBlbHNlIGlmICgnZnVuY3Rpb24nID09PSB0eXBlb2YgbCkge1xuICAgICAgICAvL2Fzc3VtZSBpdCdzIGFuIG9ic2VydmFibGUhXG4gICAgICAgIHZhciB2ID0gbCgpXG4gICAgICAgIGUuYXBwZW5kQ2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xpc3QpXG4gICAgfVxuXG4gICAgZnVuY3Rpb24gcmVtb3ZlKHRva2VuKSB7XG4gICAgICAgIHZhciBsaXN0ID0gZ2V0VG9rZW5zKClcbiAgICAgICAgICAgICwgaW5kZXggPSBpbmRleG9mKGxpc3QsIHRva2VuKVxuXG4gICAgICAgIGlmIChpbmRleCA9PT0gLTEpIHtcbiAgICAgICAgICAgIHJldHVyblxuICAgICAgICB9XG5cbiAgICAgICAgbGlzdC5zcGxpY2UoaW5kZXgsIDEpXG4gICAgICAgIHNldFRva2VucyhsaXN0KVxuICAgIH1cblxuICAgIGZ1bmN0aW9uIGNvbnRhaW5zKHRva2VuKSB7XG4gICAgICAgIHJldHVybiBpbmRleG9mKGdldFRva2VucygpLCB0b2tlbikgPiAtMVxuICAgIH1cblxuICAgIGZ1bmN0aW9uIHRvZ2dsZSh0b2tlbikge1xuICAgICAgICBpZiAoY29udGFpbnModG9rZW4pKSB7XG4gICAgICAgICAgICByZW1vdmUodG9rZW4pXG4gICAgICAgICAgICByZXR1cm4gZmFsc2VcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGFkZCh0b2tlbilcbiAgICAgICAgICAgIHJldHVybiB0cnVlXG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBmdW5jdGlvbiAkdG9TdHJpbmcoKSB7XG4gICAgICAgIHJldHVybiBlbGVtLmNsYXNzTmFtZVxuICAgIH1cblxuICAgIGZ1bmN0aW9uIGl0ZW0oaW5kZXgpIHtcbiAgICAgICAgdmFyIHRva2VucyA9IGdldFRva2VucygpXG4gICAgICAgIHJldHVybiB0b2tlbnNbaW5kZXhdIHx8IG51bGxcbiAgICB9XG5cbiAgICBmdW5jdGlvbiBnZXRUb2tlbnMoKSB7XG4gICAgICAgIHZhciBjbGFzc05hbWUgPSBlbGVtLmNsYXNzTmFtZVxuXG4gICAgICAgIHJldHVybiBmaWx0ZXIoY2xhc3NOYW1lLnNwbGl0KFwiIFwiKSwgaXNUcnV0aHkpXG4gIC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HRoaXMuaXNJbm5lckRpc3Bvc2VkID0gZmFsc2U7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBJbm5lckRpc3Bvc2FibGUucHJvdG90eXBlLmRpc3Bvc2UgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIGlmICghdGhpcy5kaXNwb3NhYmxlLmlzRGlzcG9zZWQpIHtcclxuICAgICAgICAgICAgICAgIGlmICghdGhpcy5pc0lubmVyRGlzcG9zZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmlzSW5uZXJEaXNwb3NlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5kaXNwb3NhYmxlLmNvdW50LS07XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMuZGlzcG9zYWJsZS5jb3VudCA9PT0gMCAmJiB0aGlzLmRpc3Bvc2FibGUuaXNQcmltYXJ5RGlzcG9zZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5kaXNwb3NhYmxlLmlzRGlzcG9zZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLmRpc3Bvc2FibGUudW5kZXJseWluZ0Rpc3Bvc2FibGUuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEluaXRpYWxpemVzIGEgbmV3IGluc3RhbmNlIG9mIHRoZSBSZWZDb3VudERpc3Bvc2FibGUgd2l0aCB0aGUgc3BlY2lmaWVkIGRpc3Bvc2FibGUuXHJcbiAgICAgICAgICogQGNvbnN0cnVjdG9yXHJcbiAgICAgICAgICogQHBhcmFtIHtEaXNwb3NhYmxlfSBkaXNwb3NhYmxlIFVuZGVybHlpbmcgZGlzcG9zYWJsZS5cclxuICAgICAgICAgICovXHJcbiAgICAgICAgZnVuY3Rpb24gUmVmQ291bnREaXNwb3NhYmxlKGRpc3Bvc2FibGUpIHtcclxuICAgICAgICAgICAgdGhpcy51bmRlcmx5aW5nRGlzcG9zYWJsZSA9IGRpc3Bvc2FibGU7XHJcbiAgICAgICAgICAgIHRoaXMuaXNEaXNwb3NlZCA9IGZhbHNlO1xyXG4gICAgICAgICAgICB0aGlzLmlzUHJpbWFyeURpc3Bvc2VkID0gZmFsc2U7XHJcbiAgICAgICAgICAgIHRoaXMuY291bnQgPSAwO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogRGlzcG9zZXMgdGhlIHVuZGVybHlpbmcgZGlzcG9zYWJsZSBvbmx5IHdoZW4gYWxsIGRlcGVuZGVudCBkaXNwb3NhYmxlcyBoYXZlIGJlZW4gZGlzcG9zZWRcclxuICAgICAgICAgKi9cclxuICAgICAgICBSZWZDb3VudERpc3Bvc2FibGUucHJvdG90eXBlLmRpc3Bvc2UgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIGlmICghdGhpcy5pc0Rpc3Bvc2VkKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuaXNQcmltYXJ5RGlzcG9zZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmlzUHJpbWFyeURpc3Bvc2VkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5jb3VudCA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLmlzRGlzcG9zZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLnVuZGVybHlpbmdEaXNwb3NhYmxlLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBSZXR1cm5z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W5kbGVyKTtcclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICAvKiogQHByaXZhdGUgKi9cclxuICAgICAgICBDYXRjaFNjaGVkdWxlci5wcm90b3R5cGUuX3dyYXAgPSBmdW5jdGlvbiAoYWN0aW9uKSB7XHJcbiAgICAgICAgICAgIHZhciBwYXJlbnQgPSB0aGlzO1xyXG4gICAgICAgICAgICByZXR1cm4gZnVuY3Rpb24gKHNlbGYsIHN0YXRlKSB7XHJcbiAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBhY3Rpb24ocGFyZW50Ll9nZXRSZWN1cnNpdmVXcmFwcGVyKHNlbGYpLCBzdGF0ZSk7XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKCFwYXJlbnQuX2hhbmRsZXIoZSkpIHsgdGhyb3cgZTsgfVxyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBkaXNwb3NhYmxlRW1wdHk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH07XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgLyoqIEBwcml2YXRlICovXHJcbiAgICAgICAgQ2F0Y2hTY2hlZHVsZXIucHJvdG90eXBlLl9nZXRSZWN1cnNpdmVXcmFwcGVyID0gZnVuY3Rpb24gKHNjaGVkdWxlcikge1xyXG4gICAgICAgICAgICBpZiAodGhpcy5fcmVjdXJzaXZlT3JpZ2luYWwgIT09IHNjaGVkdWxlcikge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5fcmVjdXJzaXZlT3JpZ2luYWwgPSBzY2hlZHVsZXI7XHJcbiAgICAgICAgICAgICAgICB2YXIgd3JhcHBlciA9IHRoaXMuX2Nsb25lKHNjaGVkdWxlcik7XHJcbiAgICAgICAgICAgICAgICB3cmFwcGVyLl9yZWN1cnNpdmVPcmlnaW5hbCA9IHNjaGVkdWxlcjtcclxuICAg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4gICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgIH1cclxuICAgICAgICAgIHJldHVybjtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIC8vIENoZWNrIGlmIHByb21pc2VcclxuICAgICAgICB2YXIgY3VycmVudFZhbHVlID0gY3VycmVudEl0ZW0udmFsdWU7XHJcbiAgICAgICAgaXNQcm9taXNlKGN1cnJlbnRWYWx1ZSkgJiYgKGN1cnJlbnRWYWx1ZSA9IG9ic2VydmFibGVGcm9tUHJvbWlzZShjdXJyZW50VmFsdWUpKTtcclxuXHJcbiAgICAgICAgdmFyIGQgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICBzdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZShkKTtcclxuICAgICAgICBkLnNldERpc3Bvc2FibGUoY3VycmVudFZhbHVlLnN1YnNjcmliZShcclxuICAgICAgICAgIG9ic2VydmVyLm9uTmV4dC5iaW5kKG9ic2VydmVyKSxcclxuICAgICAgICAgIGZ1bmN0aW9uIChleG4pIHtcclxuICAgICAgICAgICAgbGFzdEV4Y2VwdGlvbiA9IGV4bjtcclxuICAgICAgICAgICAgc2VsZigpO1xyXG4gICAgICAgICAgfSxcclxuICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkLmJpbmQob2JzZXJ2ZXIpKSk7XHJcbiAgICAgIH0pO1xyXG4gICAgICByZXR1cm4gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUoc3Vic2NyaXB0aW9uLCBjYW5jZWxhYmxlLCBkaXNwb3NhYmxlQ3JlYXRlKGZ1bmN0aW9uICgpIHtcclxuICAgICAgICBpc0Rpc3Bvc2VkID0gdHJ1ZTtcclxuICAgICAgfSkpO1xyXG4gICAgfSk7XHJcbiAgfTtcclxuXHJcbiAgdmFyIGVudW1lcmFibGVSZXBlYXQgPSBFbnVtZXJ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XHJcblxyXG4gICAgdmFyIENoZWNrZWRPYnNlcnZlciA9IChmdW5jdGlvbiAoX3N1cGVyKSB7XHJcbiAgICAgICAgaW5oZXJpdHMoQ2hlY2tlZE9ic2VydmVyLCBfc3VwZXIpO1xyXG5cclxuICAgICAgICBmdW5jdGlvbiBDaGVja2VkT2JzZXJ2ZXIob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgX3N1cGVyLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgIHRoaXMuX29ic2VydmVyID0gb2JzZXJ2ZXI7XHJcbiAgICAgICAgICAgIHRoaXMuX3N0YXRlID0gMDsgLy8gMCAtIGlkbGUsIDEgLSBidXN5LCAyIC0gZG9uZVxyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgdmFyIENoZWNrZWRPYnNlcnZlclByb3RvdHlwZSA9IENoZWNrZWRPYnNlcnZlci5wcm90b3R5cGU7XHJcblxyXG4gICAgICAgIENoZWNrZWRPYnNlcnZlclByb3RvdHlwZS5vbk5leHQgPSBmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgdGhpcy5jaGVja0FjY2VzcygpO1xyXG4gICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5fb2JzZXJ2ZXIub25OZXh0KHZhbHVlKTtcclxuICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgdGhyb3cgZTtcclxuICAgICAgICAgICAgfSBmaW5hbGx5IHtcclxuICAgICAgICAgICAgICAgIHRoaXMuX3N0YXRlID0gMDtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIENoZWNrZWRPYnNlcnZlclByb3RvdHlwZS5vbkVycm9yID0gZnVuY3Rpb24gKGVycikge1xyXG4gICAgICAgICAgICB0aGlzLmNoZWNrQWNjZXNzKCk7XHJcbiAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLl9vYnNlcnZlci5vbkVycm9yKGVycik7XHJcbiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgIHRocm93IGU7XHJcbiAgICAgICAgICAgIH0gZmluYWxseSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLl9zdGF0ZSA9IDI7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICBDaGVja2VkT2JzZXJ2ZXJQcm90b3R5cGUub25Db21wbGV0ZWQgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIHRoaXMuY2hlY2tBY2Nlc3MoKTtcclxuICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgIHRoaXMuX29ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgIHRocm93IGU7XHJcbiAgICAgICAgICAgIH0gZmluYWxseSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLl9zdGF0ZSA9IDI7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICBDaGVja2VkT2JzZXJ2ZXJQcm90b3R5cGUuY2hlY2tBY2Nlc3MgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIGlmICh0aGlzLl9zdGF0ZSA9PT0gMSkgeyB0aHJvdyBuZXcgRXJyb3IoJ1JlLWVudHJhbmN5IGRldGVjdGVkJyk7IH1cclxuICAgICAgICAgICAgaWYgKHRoaXMuX3N0YXRlID09PSAyKSB7IHRocm93IG5ldyBFcnJvcignT2JzZXJ2ZXIgY29tcGxldGVkJyk7IH1cclxuICAgICAgICAgICAgaWYgKHRoaXMuX3N0YXRlID09PSAwKSB7IHRoaXMuX3N0YXRlID0gMTsgfVxyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIHJldHVybiBDaGVja2VkT2JzZXJ2ZXI7XHJcbiAgICB9KE9ic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XJhYmxlKGxpc3QpLFxyXG4gICAgICAgIGxlbiA9IG9iaklzSXRlcmFibGUgPyAwIDogdG9MZW5ndGgobGlzdCksXHJcbiAgICAgICAgaXQgPSBvYmpJc0l0ZXJhYmxlID8gbGlzdFskaXRlcmF0b3IkXSgpIDogbnVsbCxcclxuICAgICAgICBpID0gMDtcclxuICAgICAgcmV0dXJuIHNjaGVkdWxlci5zY2hlZHVsZVJlY3Vyc2l2ZShmdW5jdGlvbiAoc2VsZikge1xyXG4gICAgICAgIGlmIChpIDwgbGVuIHx8IG9iaklzSXRlcmFibGUpIHtcclxuICAgICAgICAgIHZhciByZXN1bHQ7XHJcbiAgICAgICAgICBpZiAob2JqSXNJdGVyYWJsZSkge1xyXG4gICAgICAgICAgICB2YXIgbmV4dCA9IGl0Lm5leHQoKTtcclxuICAgICAgICAgICAgaWYgKG5leHQuZG9uZSkge1xyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICByZXN1bHQgPSBuZXh0LnZhbHVlO1xyXG4gICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgcmVzdWx0ID0gbGlzdFtpXTtcclxuICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICBpZiAobWFwRm4gJiYgaXNDYWxsYWJsZShtYXBGbikpIHtcclxuICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICByZXN1bHQgPSB0aGlzQXJnID8gbWFwRm4uY2FsbCh0aGlzQXJnLCByZXN1bHQsIGkpIDogbWFwRm4ocmVzdWx0LCBpKTtcclxuICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICB9XHJcblxyXG4g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AgICAgICAgY2hvaWNlTCgpO1xyXG4gICAgICAgIGlmIChjaG9pY2UgPT09IGxlZnRDaG9pY2UpIHtcclxuICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChsZWZ0KTtcclxuICAgICAgICB9XHJcbiAgICAgIH0sIGZ1bmN0aW9uIChlcnIpIHtcclxuICAgICAgICBjaG9pY2VMKCk7XHJcbiAgICAgICAgaWYgKGNob2ljZSA9PT0gbGVmdENob2ljZSkge1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlcnIpO1xyXG4gICAgICAgIH1cclxuICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIGNob2ljZUwoKTtcclxuICAgICAgICBpZiAoY2hvaWNlID09PSBsZWZ0Q2hvaWNlKSB7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgIH1cclxuICAgICAgfSkpO1xyXG5cclxuICAgICAgcmlnaHRTdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZShyaWdodFNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHJpZ2h0KSB7XHJcbiAgICAgICAgY2hvaWNlUigpO1xyXG4gICAgICAgIGlmIChjaG9pY2UgPT09IHJpZ2h0Q2hvaWNlKSB7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmlnaHQpO1xyXG4gICAgICAgIH1cclxuICAgICAgfSwgZnVuY3Rpb24gKGVycikge1xyXG4gICAgICAgIGNob2ljZVIoKTtcclxuICAgICAgICBpZiAoY2hvaWNlID09PSByaWdodENob2ljZSkge1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlcnIpO1xyXG4gICAgICAgIH1cclxuICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIGNob2ljZVIoKTtcclxuICAgICAgICBpZiAoY2hvaWNlID09PSByaWdodENob2ljZSkge1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25Db21w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1bmN0aW9uICh4LCBqKSB7IHJldHVybiBqICE9PSBpOyB9KS5ldmVyeShpZGVudGl0eSkpIHtcclxuICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgfVxyXG4gICAgICB9XHJcblxyXG4gICAgICBmdW5jdGlvbiBkb25lIChpKSB7XHJcbiAgICAgICAgaXNEb25lW2ldID0gdHJ1ZTtcclxuICAgICAgICBpZiAoaXNEb25lLmV2ZXJ5KGlkZW50aXR5KSkge1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICB9XHJcbiAgICAgIH1cclxuXHJcbiAgICAgIHZhciBzdWJzY3JpcHRpb25zID0gbmV3IEFycmF5KG4pO1xyXG4gICAgICBmb3IgKHZhciBpZHggPSAwOyBpZHggPCBuOyBpZHgrKykge1xyXG4gICAgICAgIChmdW5jdGlvbiAoaSkge1xyXG4gICAgICAgICAgdmFyIHNvdXJjZSA9IGFyZ3NbaV0sIHNhZCA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgaXNQcm9taXNlKHNvdXJjZSkgJiYgKHNvdXJjZSA9IG9ic2VydmFibGVGcm9tUHJvbWlzZShzb3VyY2UpKTtcclxuICAgICAgICAgIHNhZC5zZXREaXNwb3NhYmxlKHNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgdmFsdWVzW2ldID0geDtcclxuICAgICAgICAgICAgbmV4dChpKTtcclxuICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgZG9uZShpKTtcclxuICAgICAgICAgIH0pKTtcclxuICAgICAgICAgIHN1YnNjcmlwdGlvbnNbaV0gPSBzYWQ7XHJcbiAgICAgICAgfShpZHgpKTtcclxuICAgICAgfVxyXG5cclxuICAgIC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24gYSBjb21wdXRlZCBrZXkgdmFsdWUsIGZyb20gdGhlIHNvdXJjZSBzZXF1ZW5jZS5cclxuICAgICAqL1xyXG4gICAgb2JzZXJ2YWJsZVByb3RvLmRpc3RpbmN0VW50aWxDaGFuZ2VkID0gZnVuY3Rpb24gKGtleVNlbGVjdG9yLCBjb21wYXJlcikge1xyXG4gICAgICAgIHZhciBzb3VyY2UgPSB0aGlzO1xyXG4gICAgICAgIGtleVNlbGVjdG9yIHx8IChrZXlTZWxlY3RvciA9IGlkZW50aXR5KTtcclxuICAgICAgICBjb21wYXJlciB8fCAoY29tcGFyZXIgPSBkZWZhdWx0Q29tcGFyZXIpO1xyXG4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIGhhc0N1cnJlbnRLZXkgPSBmYWxzZSwgY3VycmVudEtleTtcclxuICAgICAgICAgICAgcmV0dXJuIHNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgY29tcGFyZXJFcXVhbHMgPSBmYWxzZSwga2V5O1xyXG4gICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICBrZXkgPSBrZXlTZWxlY3Rvcih2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaWYgKGhhc0N1cnJlbnRLZXkpIHtcclxuICAgICAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBjb21wYXJlckVxdWFscyA9IGNvbXBhcmVyKGN1cnJlbnRLZXksIGtleSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZXhjZXB0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGlmICghaGFzQ3VycmVudEtleSB8fCAhY29tcGFyZXJFcXVhbHMpIHtcclxuICAgICAgICAgICAgICAgICAgICBoYXNDdXJyZW50S2V5ID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICBjdXJyZW50S2V5ID0ga2V5O1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIG9ic2VydmVyLm9uQ29tcGxldGVkLmJpbmQob2JzZXJ2ZXIpKTtcclxuICAgICAgICB9KTtcclxuICAgIH07XHJcblxyXG4gIC8qKlxyXG4gICAqICBJbnZva2VzIGFuIGFjdGlvbiBmb3IgZWFjaCBlbGVtZW50IGluIHRoZSBvYnNlcnZhYmxlIHNlcXVlbmNlIGFuZCBpbnZva2VzIGFuIGFjdGlvbiB1cG9uIGdyYWNlZnVsIG9yIGV4Y2VwdGlvbmFsIHRlcm1pbmF0aW9uIG9mIHRoZSBvYnNlcnZhYmxlIHNlcXVlbmNlLlxyXG4gICAqICBUaGlzIG1ldGhvZCBjYW4gYmUgdXNlZCBmb3IgZGVidWdnaW5nLCBsb2dnaW5nLCBldGMuIG9mIHF1ZXJ5IGJlaGF2aW9yIGJ5IGludGVyY2VwdGluZyB0aGUgbWVzc2FnZSBzdHJlYW0gdG8gcnVuIGFyYml0cmFyeSBhY3Rpb25zIGZvciBtZXNzYWdl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nVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgIHZhciBoYXNBY2N1bXVsYXRpb24sIGFjY3VtdWxhdGlvbiwgaGFzVmFsdWU7XHJcbiAgICAgIHJldHVybiBzb3VyY2Uuc3Vic2NyaWJlIChcclxuICAgICAgICBmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgIWhhc1ZhbHVlICYmIChoYXNWYWx1ZSA9IHRydWUpO1xyXG4gICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgaWYgKGhhc0FjY3VtdWxhdGlvbikge1xyXG4gICAgICAgICAgICAgIGFjY3VtdWxhdGlvbiA9IGFjY3VtdWxhdG9yKGFjY3VtdWxhdGlvbiwgeCk7XHJcbiAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgYWNjdW11bGF0aW9uID0gaGFzU2VlZCA/IGFjY3VtdWxhdG9yKHNlZWQsIHgpIDogeDtcclxuICAgICAgICAgICAgICBoYXNBY2N1bXVsYXRpb24gPSB0cnVlO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICBvYnNlcnZlci5vbk5leHQoYWNjdW11bGF0aW9uKTtcclxuICAgICAgICB9LFxyXG4gICAgICAgIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksXHJcbiAgICAgICAgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgIWhhc1ZhbHVlICYmIGhhc1NlZWQgJiYgb2JzZXJ2ZXIub25OZXh0KHNlZWQpO1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICB9XHJcbiAgICAgICk7XHJcbiAgICB9KTtcclxuICB9O1xyXG5cclxuICAvKipcclxuICAgKiAgQnlwY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BiYXNlZCBvbiBlbGVtZW50IGNvdW50IGluZm9ybWF0aW9uLlxyXG4gICAqXHJcbiAgICogIHZhciByZXMgPSB4cy53aW5kb3dXaXRoQ291bnQoMTApO1xyXG4gICAqICB2YXIgcmVzID0geHMud2luZG93V2l0aENvdW50KDEwLCAxKTtcclxuICAgKiBAcGFyYW0ge051bWJlcn0gY291bnQgTGVuZ3RoIG9mIGVhY2ggd2luZG93LlxyXG4gICAqIEBwYXJhbSB7TnVtYmVyfSBbc2tpcF0gTnVtYmVyIG9mIGVsZW1lbnRzIHRvIHNraXAgYmV0d2VlbiBjcmVhdGlvbiBvZiBjb25zZWN1dGl2ZSB3aW5kb3dzLiBJZiBub3Qgc3BlY2lmaWVkLCBkZWZhdWx0cyB0byB0aGUgY291bnQuXHJcbiAgICogQHJldHVybnMge09ic2VydmFibGV9IEFuIG9ic2VydmFibGUgc2VxdWVuY2Ugb2Ygd2luZG93cy5cclxuICAgKi9cclxuICBvYnNlcnZhYmxlUHJvdG8ud2luZG93V2l0aENvdW50ID0gZnVuY3Rpb24gKGNvdW50LCBza2lwKSB7XHJcbiAgICB2YXIgc291cmNlID0gdGhpcztcclxuICAgICtjb3VudCB8fCAoY291bnQgPSAwKTtcclxuICAgIE1hdGguYWJzKGNvdW50KSA9PT0gSW5maW5pdHkgJiYgKGNvdW50ID0gMCk7XHJcbiAgICBpZiAoY291bnQgPD0gMCkgeyB0aHJvdyBuZXcgRXJyb3IoYXJndW1lbnRPdXRPZlJhbmdlKTsgfVxyXG4gICAgc2tpcCA9PSBudWxsICYmIChza2lwID0gY291bnQpO1xyXG4gICAgK3NraXAgfHwgKHNraXAgPSAwKTtcclxuICAgIE1hdGguYWJzKHNraXApID09PSBJbmZpbml0eSAmJiAoc2tpcCA9IDApO1xyXG5cclxuICAgIGlmIChza2lwIDw9IDApIHsgdGhyb3cgbmV3IEVycm9yKGFyZ3VtZW50T3V0T2ZSYW5nZSk7IH1cclxuICAgIHJldHVybiBuZXcgQW5vbnltb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2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgICAgaXNQcm9taXNlKHJlc3VsdCkgJiYgKHJlc3VsdCA9IG9ic2VydmFibGVGcm9tUHJvbWlzZShyZXN1bHQpKTtcclxuICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChyZXN1bHQpO1xyXG4gICAgICAgIH0sXHJcbiAgICAgICAgZnVuY3Rpb24gKGVycikge1xyXG4gICAgICAgICAgdmFyIHJlc3VsdDtcclxuICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgIHJlc3VsdCA9IG9uRXJyb3IuY2FsbCh0aGlzQXJnLCBlcnIpO1xyXG4gICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgICBpc1Byb21pc2UocmVzdWx0KSAmJiAocmVzdWx0ID0gb2JzZXJ2YWJsZUZyb21Qcm9taXNlKHJlc3VsdCkpO1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdCk7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgIH0sXHJcbiAgICAgICAgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgdmFyIHJlc3VsdDtcclxuICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgIHJlc3VsdCA9IG9uQ29tcGxldGVkLmNhbGwodGhpc0FyZyk7XHJcbiAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgIH1cclxuICAgICAgICAgIGlzUHJvbWlzZShyZXN1bHQpICYmIChyZXN1bHQgPSBvYnNlcnZhYmxlR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JjZSA9IHRoaXM7XHJcbiAgICAgICAgaWYgKGRlZmF1bHRWYWx1ZSA9PT0gdW5kZWZpbmVkKSB7XHJcbiAgICAgICAgICAgIGRlZmF1bHRWYWx1ZSA9IG51bGw7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIGZvdW5kID0gZmFsc2U7XHJcbiAgICAgICAgICAgIHJldHVybiBzb3VyY2Uuc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICBmb3VuZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIGlmICghZm91bmQpIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoZGVmYXVsdFZhbHVlKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgLy8gU3dhcCBvdXQgZm9yIEFycmF5LmZpbmRJbmRleFxyXG4gIGZ1bmN0aW9uIGFycmF5SW5kZXhPZkNvbXBhcmVyKGFycmF5LCBpdGVtLCBjb21wYXJlcikge1xyXG4gICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IGFycmF5Lmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgIGlmIChjb21wYXJlcihhcnJheVtpXSwgaXRlbSkpIHsgcmV0dXJuIGk7IH1cclxuICAgIH1cclxuICAgIHJldHVybiAtMTtcclxuICB9XHJcblxyXG4gI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Vycm9yKGUpIHsgcmV0dXJuIGZ1bmN0aW9uIChpdGVtKSB7IGl0ZW0ub25FcnJvcihlKTsgfTsgfVxyXG4gICAgICAgIHZhciBtYXAgPSBuZXcgRGljdGlvbmFyeSgwLCBjb21wYXJlciksXHJcbiAgICAgICAgICBncm91cERpc3Bvc2FibGUgPSBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZSgpLFxyXG4gICAgICAgICAgcmVmQ291bnREaXNwb3NhYmxlID0gbmV3IFJlZkNvdW50RGlzcG9zYWJsZShncm91cERpc3Bvc2FibGUpO1xyXG5cclxuICAgICAgICBncm91cERpc3Bvc2FibGUuYWRkKHNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgIHZhciBrZXk7XHJcbiAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICBrZXkgPSBrZXlTZWxlY3Rvcih4KTtcclxuICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgbWFwLmdldFZhbHVlcygpLmZvckVhY2goaGFuZGxlRXJyb3IoZSkpO1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgdmFyIGZpcmVOZXdNYXBFbnRyeSA9IGZhbHNlLFxyXG4gICAgICAgICAgICB3cml0ZXIgPSBtYXAudHJ5R2V0VmFsdWUoa2V5KTtcclxuICAgICAgICAgIGlmICghd3JpdGVyKSB7XHJcbiAgICAgICAgICAgIHdyaXRlciA9IG5ldyBTdWJqZWN0KCk7XHJcbiAgICAgICAgICAgIG1hcC5zZXQoa2V5LCB3cml0ZXIpO1xyXG4gICAgICAgICAgICBmaXJlTmV3TWFwRW50cnkgPSB0cnVlO1xyXG4gICAgICAgICAgfVxyXG5cclxuICAgICAgICAgIGlmIChmaXJlTmV3TWFwRW50cnkpIHtcclxuICAgICAgICAgICAgdmFyIGdyb3VwID0gbmV3IEdyb3VwZWRPYnNlcnZhYmxlKGtleSwgd3JpdGVyLCByZWZDb3VudERpc3Bvc2FibGUpLFxyXG4gICAgICAgICAgICAgIGR1cmF0aW9uR3JvdXAgPSBuZXcgR3JvdXBlZE9ic2VydmFibGUoa2V5LCB3cml0ZXIpO1xyXG4gICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgIGR1cmF0aW9uID0gZHVyYXRpb25TZWxlY3RvcihkdXJhdGlvbkdyb3VwKTtcclxuICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgIG1hcC5nZXRWYWx1ZXMoKS5mb3JFYWNoKGhhbmRsZUVycm9yKGUpKTtcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGdyb3VwKTtcclxuXHJcbiAgICAgICAgICAgIHZhciBtZCA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgICBncm91cERpc3Bvc2FibGUuYWRkKG1kKTtcclxuXHJcbiAgICAgICAgICAgIHZhciBleHBpcmUgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgbWFwLnJlbW92ZShrZXkpICYmIHdyaXRlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgIGdyb3VwRGlzcG9zYWJsZS5yZW1vdmUobWQpO1xyXG4gICAgICAgICAgICB9O1xyXG5cclxuICAgICAgICAgICAgbWQuc2V0RGlzcG9zYWJsZShkdXJhdGlvbi50YWtlKDEpLnN1YnNjcmliZShcclxuICAgICAgICAgICAgICBub29wLFxyXG4gICAgICAgICAgICAgIGZ1bmN0aW9uIChleG4pIHtcclxuICAgICAgICAgICAgICAgIG1hcC5nZXRWYWx1ZXMoKS5mb3JFYWNoKGhhbmRsZUVycm9yKGV4bikpO1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleG4pO1xyXG4gICAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgICAgZXhwaXJlKVxyXG4gICAgICAgICAgICApO1xyXG4gICAgICAgICAgfVxyXG5cclxuICAgICAgICAgIHZhciBlbGVtZW50O1xyXG4gICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgZWxlbWVudCA9IGVsZW1lbnRTZWxlY3Rvcih4KTtcclxuICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgbWFwLmdldFZhbHVlcygpLmZvckVhY2goaGFuZGxlRXJyb3IoZSkpO1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgd3JpdGVyLm9uTmV4dChlbGVtZW50KTtcclxuICAgICAgfSwgZnVuY3Rpb24gKGV4KSB7XHJcbiAgICAgICAgbWFwLmdldFZhbHVlcygpLmZvckVhY2goaGFuZGxlRXJyb3IoZXgpKTtcclxuICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4KTtcclxuICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIG1hcC5nZXRWYWx1ZXMoKS5mb3JFYWNoKGZ1bmN0aW9uIChpdGVtKSB7IGl0ZW0ub25Db21wbGV0ZWQoKTsgfSk7XHJcbiAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgfSkpO1xyXG5cclxuICAgICAgcmV0dXJuIHJlZkNvdW50RGlzcG9zYWJsZTtcclxuICAgIH0pO1xyXG4gIH07XHJcblxyXG4gIC8qKlxyXG4gICAqICBQcm9qZWN0cyBlYWNoIGVsZW1lbnQgb2YgYW4gb2JzZXJ2YWJsZSBzZXF1ZW5jZSBpbnRvIGEgbmV3IGZvcm0gYnkgaW5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lzb24gPSAwO1xyXG4gICAgICAgIGlmICghaGFzVmFsdWUpIHtcclxuICAgICAgICAgIGhhc1ZhbHVlID0gdHJ1ZTtcclxuICAgICAgICAgIGxhc3RLZXkgPSBrZXk7XHJcbiAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgIGNvbXBhcmlzb24gPSBjb21wYXJlcihrZXksIGxhc3RLZXkpO1xyXG4gICAgICAgICAgfSBjYXRjaCAoZXgxKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXgxKTtcclxuICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgIH1cclxuICAgICAgICBpZiAoY29tcGFyaXNvbiA+IDApIHtcclxuICAgICAgICAgIGxhc3RLZXkgPSBrZXk7XHJcbiAgICAgICAgICBsaXN0ID0gW107XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGlmIChjb21wYXJpc29uID49IDApIHsgbGlzdC5wdXNoKHgpOyB9XHJcbiAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICBvYnNlcnZlci5vbk5leHQobGlzdCk7XHJcbiAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgfSk7XHJcbiAgICB9KTtcclxuICB9XHJcblxyXG4gICAgZnVuY3Rpb24gZmlyc3RPbmx5KHgpIHtcclxuICAgICAgICBpZiAoeC5sZW5ndGggPT09IDApIHtcclxuICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKHNlcXVlbmNlQ29udGFpbnNOb0VsZW1lbnRzKTtcclxuICAgICAgICB9XHJcbiAgICAgICAgcmV0dXJuIHhbMF07XHJcbiAgICB9XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiBBcHBsaWVzIGFuIGFjY3VtdWxhdG9yIGZ1bmN0aW9uIG92ZXIgYW4gb2J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yXG4gICAgICAgICAgICAgICAgY291bnQ6IDBcclxuICAgICAgICAgICAgfSwgZnVuY3Rpb24gKHByZXYsIGN1cikge1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuIHtcclxuICAgICAgICAgICAgICAgICAgICBzdW06IHByZXYuc3VtICsgY3VyLFxyXG4gICAgICAgICAgICAgICAgICAgIGNvdW50OiBwcmV2LmNvdW50ICsgMVxyXG4gICAgICAgICAgICAgICAgfTtcclxuICAgICAgICAgICAgfSkuZmluYWxWYWx1ZSgpLnNlbGVjdChmdW5jdGlvbiAocykge1xyXG4gICAgICAgICAgICAgICAgaWYgKHMuY291bnQgPT09IDApIHtcclxuICAgICAgICAgICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoJ1RoZSBpbnB1dCBzZXF1ZW5jZSB3YXMgZW1wdHknKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIHJldHVybiBzLnN1bSAvIHMuY291bnQ7XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgZnVuY3Rpb24gc2VxdWVuY2VFcXVhbEFycmF5KGZpcnN0LCBzZWNvbmQsIGNvbXBhcmVyKSB7XHJcbiAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgIHZhciBjb3VudCA9IDAsIGxlbiA9IHNlY29uZC5sZW5ndGg7XHJcbiAgICAgIHJldHVybiBmaXJzdC5zdWJzY3JpYmUoZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgdmFyIGVxdWFsID0gZmFsc2U7XHJcbiAgICAgICAgdHJ5IHtcclxuICAgICAgICAgIGNvdW50IDwgbGVuICYmIChlcXVhbCA9IGNvbXBhcmVyKHZhbHVlLCBzZWNvbmRbY291bnQrK10pKTtcclxuICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyX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uICAgICAgdmFyIHN1YnNjcmlwdGlvbjEgPSBmaXJzdC5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICB2YXIgZXF1YWwsIHY7XHJcbiAgICAgICAgaWYgKHFyLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgIHYgPSBxci5zaGlmdCgpO1xyXG4gICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgZXF1YWwgPSBjb21wYXJlcih2LCB4KTtcclxuICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgICAgaWYgKCFlcXVhbCkge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoZmFsc2UpO1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgIH0gZWxzZSBpZiAoZG9uZXIpIHtcclxuICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChmYWxzZSk7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICBxbC5wdXNoKHgpO1xyXG4gICAgICAgIH1cclxuICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIGRvbmVsID0gdHJ1ZTtcclxuICAgICAgICBpZiAocWwubGVuZ3RoID09PSAwKSB7XHJcbiAgICAgICAgICBpZiAocXIubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoZmFsc2UpO1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgfSBlbHNlIGlmIChkb25lcikge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQodHJ1ZSk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgfVxyXG4gICAgICB9KTtcclxuXHJcbiAgICAgIGlzUHJvbWlzZShzZWNvbmQpICYmIChzZWNvbmQgPSBvYnNlcnZhYmxlRnJvbVByb21pc2Uoc2Vjb25kKSk7XHJcbiAgICAgIHZhciBzdWJzY3JpcHRpb24yID0gc2Vjb25kLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgIHZhciBlcXVhbDtcclxuICAgICAgICBpZiAocWwubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgdmFyIHYgPSBxbC5zaGlmdCgpO1xyXG4gICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgZXF1YWwgPSBjb21wYXJlcih2LCB4KTtcclxuICAgICAgICAgIH0gY2F0Y2ggKGV4Y2VwdGlvbikge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgIH1cclxuICAgICAgICAgIGlmICghZXF1YWwpIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGZhbHNlKTtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgIH1cclxuICAgICAgICB9IGVsc2UgaWYgKGRvbmVsKSB7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbk5leHQoZmFsc2UpO1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgcXIucHVzaCh4KTtcclxuICAgICAgICB9XHJcbiAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICBkb25lciA9IHRydWU7XHJcbiAgICAgICAgaWYgKHFyLmxlbmd0aCA9PT0gMCkge1xyXG4gICAgICAgICAgaWYgKHFsLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGZhbHNlKTtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgIH0gZWxzZSBpZiAoZG9uZWwpIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHRydWUpO1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgIH1cclxuICAgICAgfSk7XHJcbiAgICAgIHJldHVybiBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZShzdWJzY3JpcHRpb24xLCBzdWJzY3JpcHRpb24yKTtcclxuICAgIH0pO1xyXG4gIH07XHJcblxyXG4gICAgZnVuY3Rpb24gZWxlbWVudEF0T3JEZWZhdWx0KHNvdXJjZSwgaW5kZXgsIGhhc0RlZmF1bHQsIGRlZmF1bHRWYWx1ZSkge1xyXG4gICAgICAgIGlmIChpbmRleCA8IDApIHtcclxuICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKGFyZ3VtZW50T3V0T2ZSYW5nZSk7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIGkgPSBpbmRleDtcclxuICAgICAgICAgICAgcmV0dXJuIHNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgIGlmIChpID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHgpO1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBpLS07XHJcbiAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIGlmICghaGFzRGVmYXVsdCkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IobmV3IEVycm9yKGFyZ3VtZW50T3V0T2ZSYW5nZSkpO1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoZGVmYXVsdFZhbHVlKTtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICB9KTtcclxuICAgIH1cclxuXHJcbiAgICAvKipcclxuICAgICAqIFJldHVybnMgdGhlIGVsZW1lbnQgYXQgYSBzcGVjaWZpZWQgaW5kZXggaW4gYSBzZXF1ZW5jZS5cclxuICAgICAqIEBleGFtcGxlXHJcbiAgICAgKiB2YXIgcmVzID0gc291cmNlLmVsZW1lbnRBdCg1KTtcclxuICAgICAqIEBwYXJhbSB7TnVtYmVyfSBpbmRleCBUaGUgemVyby1iYXNlZCBpbmRleCBvZiB0aGUgZWxlbWVudCB0byByZXRyaWV2ZS5cclxuICAgICAqIEByZXR1cm5zIHtPYnNlcnZhYmxlfSBBbiBvYnNlcnZhYmxlIHNlcXVlbmNlIHRoYXQgcHJvZHVjZXMgdGhlIGVsZW1lbnQgYXQgdGhlIHNwZWNpZmllZCBwb3NpdGlvbiBpbiB0aGUgc291cmNlIHNlcXVlbmNlLlxyXG4gICAgICovXHJcbiAgICBvYnNlcnZhYmxlUHJvdG8uZWxlbWVudEF0ID0gIGZ1bmN0aW9uIChpbmRleCkge1xyXG4gICAgICAgIHJldHVybiBlbG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BvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGlmIChzaG91bGRSdW4pIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoeWllbGRJbmRleCA/IGkgOiB4KTtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICBpKys7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh5aWVsZEluZGV4ID8gLTEgOiB1bmRlZmluZWQpO1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgfSk7XHJcbiAgICB9XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiBTZWFyY2hlcyBmb3IgYW4gZWxlbWVudCB0aGF0IG1hdGNoZXMgdGhlIGNvbmRpdGlvbnMgZGVmaW5lZCBieSB0aGUgc3BlY2lmaWVkIHByZWRpY2F0ZSwgYW5kIHJldHVybnMgdGhlIGZpcnN0IG9jY3VycmVuY2Ugd2l0aGluIHRoZSBlbnRpcmUgT2JzZXJ2YWJsZSBzZXF1ZW5jZS5cclxuICAgICAqIEBwYXJhbSB7RnVuY3Rpb259IHByZWRpY2F0ZSBUaGUgcHJlZGljYXRlIHRoYXQgZGVmaW5lcyB0aGUgY29uZGl0aW9ucyBvZiB0aGUgZWxlbWVudCB0byBzZWFyY2ggZm9yLlxyXG4gICAgICogQHBhcmFtIHtBbnl9IFt0aGlzQXJnXSBPYmplY3QgdG8gdXNlIG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V3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgdmFyIG0gPSBuZXcgcm9vdC5NYXAoKTtcclxuICAgICAgICByZXR1cm4gc291cmNlLnN1YnNjcmliZShcclxuICAgICAgICAgIGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgIHZhciBrZXk7XHJcbiAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAga2V5ID0ga2V5U2VsZWN0b3IoeCk7XHJcbiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgdmFyIGVsZW1lbnQgPSB4O1xyXG4gICAgICAgICAgICBpZiAoZWxlbWVudFNlbGVjdG9yKSB7XHJcbiAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgIGVsZW1lbnQgPSBlbGVtZW50U2VsZWN0b3IoeCk7XHJcbiAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgIG0uc2V0KGtleSwgZWxlbWVudCk7XHJcbiAgICAgICAgICB9LFxyXG4gICAgICAgICAgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSxcclxuICAgICAgICAgIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KG0pO1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgfSk7XHJcbiAgICAgIH0pO1xyXG4gICAgfTtcclxuICB9XHJcblxyXG4gIHZhciBmblN0cmluZyA9ICdmdW5jdGlvbic7XHJcblxyXG4gIGZ1bmN0aW9uIHRvVGh1bmsob2JqLCBjdHgpIHtcclxuICAgIGlmIChBcnJheS5pc0FycmF5KG9iaikpIHtcclxuICAgICAgcmV0dXJuIG9iamVjdFRvVGh1bmsuY2FsbChjdHgsIG9iaik7XHJcbiAgICB9XHJcblxyXG4gICAgaWYgKGlzR2VuZXJhdG9yRnVuY3Rpb24ob2JqKSkge1xyXG4gICAgICByZXR1cm4gb2JzZXJ2YWJsZVNwYXduKG9iai5jYWxsKGN0eCkpO1xyXG4gICAgfVxyXG5cclxuICAgIGlmIChpc0dlbmVyYXRvcihvYmopKSB7XHJcbiAgICAgIHJldHVybiBvYnNlcnZhYmxlU3Bhd24ob2JqKTtcclxuICAgIH1cclxuXHJcbiAgICBpZiAoaXNPYnNlcnZhYmxlKG9iaikpIHtcclxuICAgICAgcmV0dXJuIG9ic2VydmFibGVUb1RodW5rKG9iaik7XHJcbiAgICB9XHJcblxyXG4gICAgaWYgKGlzUHJvbWlzZShvYmopKSB7XHJcbiAgICAgIHJldHVybiBwcm9taXNlVG9UaHVuayhvYmopO1xyXG4gICAgfVxyXG5cclxuICAgIGlmICh0eXBlb2Ygb2JqID09PSBmblN0cmluZykge1xyXG4gICAgICByZXR1cm4gb2JqO1xyXG4gICAgfVxyXG5cclxuICAgIGlmIChpc09iamVjdChvYmopIHx8IEFycmF5LmlzQXJyYXkob2JqKSkge1xyXG4gICAgICByZXR1cm4gb2JqZWN0VG9UaHVuay5jYWxsKGN0eCwgb2JqKTtcclxuICAgIH1cclxuXHJcbiAgICByZXR1cm4gb2JqO1xyXG4gIH1cclxuXHJcbiAgZnVuY3Rpb24gb2JqZWN0VG9UaHVuayhvYmopIHtcclxuICAgIHZhciBjdHggPSB0aGlzO1xyXG5cclxuICAgIHJldHVybiBmdW5jdGlvbiAoZG9uZSkge1xyXG4gICAgICB2YXIga2V5cyA9IE9iamVjdC5rZXlzKG9iaiksXHJcbiAgICAgICAgICBwZW5kaW5nID0ga2V5cy5sZW5ndGgsXHJcbiAgICAgICAgICByZXN1bHRzID0gbmV3IG9iai5jb25zdHJ1Y3RvcigpLFxyXG4gICAgICAgICAgZmluaXNoZWQ7XHJcblxyXG4gICAgICBpZiAoIXBlbmRpbmcpIHtcclxuICAgICAgICB0aW1lb3V0U2NoZWR1bGVyLnNjaGVkdWxlKGZ1bmN0aW9uICgpIHsgZG9uZShudWxsLCByZXN1bHRzKTsgfSk7XHJcbiAgICAgICAgcmV0dXJuO1xyXG4gICAgICB9XHJcblxyXG4gICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0ga2V5cy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgIHJ1bihvYmpba2V5c1tpXV0sIGtleXNbaV0pO1xyXG4gICAgICB9XHJcblxyXG4gICAgICBmdW5jdGlvbiBydW4oZm4sIGtleSkge1xyXG4gICAgICAgIGlmIChmaW5pc2hlZCkgeyByZXR1cm47IH1cclxuICAgICAgICB0cnkge1xyXG4gICAgICAgICAgZm4gPSB0b1RodW5rKGZuLCBjdHgpO1xyXG5cclxuICAgICAgICAgIGlmICh0eXBlb2YgZm4gIT09IGZuU3RyaW5nKSB7XHJcbiAgICAgICAgICAgIHJlc3VsdHNba2V5XSA9IGZuO1xyXG4gICAgICAgICAgICByZXR1cm4gLS1wZW5kaW5nIHx8IGRvbmUobnVsbCwgcmVzdWx0cyk7XHJcbiAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgZm4uY2FsbChjdHgsIGZ1bmN0aW9uKGVyciwgcmVzKXtcclxuICAgICAgICAgICAgaWYgKGZpbmlzaGVkKSB7IHJldHVybjsgfVxyXG5cclxuICAgICAgICAgICAgaWYgKGVycikge1xyXG4gICAgICAgICAgICAgIGZpbmlzaGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICByZXR1cm4gZG9uZShlcnIpO1xyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAg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ZW4ubmV4dChyZXMpO1xyXG4gICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICByZXR1cm4gZXhpdChlKTtcclxuICAgICAgICAgIH1cclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGlmIChyZXQuZG9uZSkgIHtcclxuICAgICAgICAgIHJldHVybiBleGl0KG51bGwsIHJldC52YWx1ZSk7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICByZXQudmFsdWUgPSB0b1RodW5rKHJldC52YWx1ZSwgY3R4KTtcclxuXHJcbiAgICAgICAgaWYgKHR5cGVvZiByZXQudmFsdWUgPT09IGZuU3RyaW5nKSB7XHJcbiAgICAgICAgICB2YXIgY2FsbGVkID0gZmFsc2U7XHJcbiAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICByZXQudmFsdWUuY2FsbChjdHgsIGZ1bmN0aW9uKCl7XHJcbiAgICAgICAgICAgICAgaWYgKGNhbGxlZCkge1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgY2FsbGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICBuZXh0LmFwcGx5KGN0eCwgYXJndW1lbnRzKTtcclxuICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgIHRpbWVvdXRTY2hlZHVsZXIuc2NoZWR1bGUoZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgIGlmIChjYWxsZWQpIHtcclxuICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgIGNhbGxlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgbmV4dC5jYWxsKGN0eCwgZSk7XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgIH1cclxuXHJcb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gICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdHMpO1xyXG4gICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgaWYgKHJlc3VsdHMubGVuZ3RoIDw9IDEpIHtcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQuYXBwbHkob2JzZXJ2ZXIsIHJlc3VsdHMpO1xyXG4gICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChyZXN1bHRzKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgfVxyXG5cclxuICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBhcmdzLnB1c2goaGFuZGxlcik7XHJcbiAgICAgICAgZnVuYy5hcHBseShjb250ZXh0LCBhcmdzKTtcclxuICAgICAgfSkucHVibGlzaExhc3QoKS5yZWZDb3VudCgpO1xyXG4gICAgfTtcclxuICB9O1xyXG5cclxuICBmdW5jdGlvbiBjcmVhdGVMaXN0ZW5lciAoZWxlbWVudCwgbmFtZSwgaGFuZGxlcikge1xyXG4gICAgaWYgKGVsZW1lbnQuYWRkRXZlbnRMaXN0ZW5lcikge1xyXG4gICAgICBlbGVtZW50LmFkZEV2ZW50TGlzdGVuZXIobmFtZSwgaGFuZGxlciwgZmFsc2UpO1xyXG4gICAgICByZXR1cm4gZGlzcG9zYWJsZUNyZWF0ZShmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgZWxlbWVudC5yZW1vdmVFdmVudExpc3RlbmVyKG5hbWUsIGhhbmRsZXIsIGZhbHNlKTtcclxuICAgICAgfSk7XHJcbiAgICB9XHJcbiAgICB0aHJvdyBuZXcgRX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WxzZV0sXHJcbiAgICAgICAgaGFzVmFsdWVBbGwgPSBmYWxzZSxcclxuICAgICAgICBpc0RvbmUgPSBmYWxzZSxcclxuICAgICAgICB2YWx1ZXMgPSBuZXcgQXJyYXkobik7XHJcblxyXG4gICAgICBmdW5jdGlvbiBuZXh0KHgsIGkpIHtcclxuICAgICAgICB2YWx1ZXNbaV0gPSB4XHJcbiAgICAgICAgdmFyIHJlcztcclxuICAgICAgICBoYXNWYWx1ZVtpXSA9IHRydWU7XHJcbiAgICAgICAgaWYgKGhhc1ZhbHVlQWxsIHx8IChoYXNWYWx1ZUFsbCA9IGhhc1ZhbHVlLmV2ZXJ5KGlkZW50aXR5KSkpIHtcclxuICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgIHJlcyA9IHJlc3VsdFNlbGVjdG9yLmFwcGx5KG51bGwsIHZhbHVlcyk7XHJcbiAgICAgICAgICB9IGNhdGNoIChleCkge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4KTtcclxuICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlcyk7XHJcbiAgICAgICAgfSBlbHNlIGlmIChpc0RvbmUpIHtcclxuICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgfVxyXG4gICAgICB9XHJcblxyXG4gICAgICByZXR1cm4gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUoXHJcbiAgICAgICAgc291cmNlLnN1YnNjcmliZShcclxuICAgICAgICAgIGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgIG5leHQoeCwgMCk7XHJcbiAgICAgICAgICB9LFxyXG4gICAgICAgICAgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSxcclxuICAgICAgICAgIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgaXNEb25lID0gdHJ1ZTtcclxuICAgICA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EZpcmUgIT0gcHJldmlvdXNTaG91bGRGaXJlKSB7XHJcbiAgICAgICAgICAgICAgICBwcmV2aW91c1Nob3VsZEZpcmUgPSByZXN1bHRzLnNob3VsZEZpcmU7XHJcbiAgICAgICAgICAgICAgICAvLyBjaGFuZ2UgaW4gc2hvdWxkRmlyZVxyXG4gICAgICAgICAgICAgICAgaWYgKHJlc3VsdHMuc2hvdWxkRmlyZSkge1xyXG4gICAgICAgICAgICAgICAgICB3aGlsZSAocS5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHEuc2hpZnQoKSk7XHJcbiAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgcHJldmlvdXNTaG91bGRGaXJlID0gcmVzdWx0cy5zaG91bGRGaXJlO1xyXG4gICAgICAgICAgICAgICAgLy8gbmV3IGRhdGFcclxuICAgICAgICAgICAgICAgIGlmIChyZXN1bHRzLnNob3VsZEZpcmUpIHtcclxuICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdHMuZGF0YSk7XHJcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICBxLnB1c2gocmVzdWx0cy5kYXRhKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIGZ1bmN0aW9uIChlcnIpIHtcclxuICAgICAgICAgICAgICAvLyBFbXB0eSBidWZmZXIgYmVmb3JlIHNlbmRpbmcgZXJyb3JcclxuICAgICAgICAgICAgICB3aGlsZSAocS5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocS5zaGlmdCgpKTtcclxuICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlcnIpO1xyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgLy8gRW1wdHkgYnVmZmVyIGJlZm9yZSBzZW5kaW5nIGNvbXBsZXRpb25cclxuICAgICAgICAgICAgICB3aGlsZSAocS5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocS5zaGlmdCgpKTtcclxuICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgKTtcclxuICAgICAgcmV0dXJuIHN1YnNjcmlwdGlvbjtcclxuICAgIH1cclxuXHJcbiAgICBmdW5jdGlvbiBQYXVzYWJsZUJ1ZmZlcmVkT2JzZXJ2YWJsZShzb3VyY2UsIHBhdXNlcikge1xyXG4gICAgICB0aGlzLnNvdXJjZSA9IHNvdXJjZTtcclxuICAgICAgdGhpcy5jb250cm9sbGVyID0gbmV3IFN1YmplY3QoKTtcclxuXHJcbiAgICAgIGlmIChwYXVzZXIgJiYgcGF1c2VyLnN1YnNjcmliZSkge1xyXG4gICAgICAgIHRoaXMucGF1c2VyID0gdGhpcy5jb250cm9sbGVyLm1lcmdlKHBhdXNlcik7XHJcbiAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgdGhpcy5wYXVzZXIgPSB0aGlzLmNvbnRyb2xsZXI7XHJcbiAgICAgIH1cclxuXHJcbiAgICAgIF9zdXBlci5jYWxsKHRoaXMsIHN1YnNjcmliZSk7XHJcbiAgICB9XHJcblxyXG4gICAgUGF1c2FibGVCdWZmZXJlZE9ic2VydmFibGUucHJvdG90eXBlLnBhdXNlID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICB0aGlzLmNvbnRyb2xsZXIub25OZXh0KGZhbHNlKTtcclxuICAgIH07XHJcblxyXG4gICAgUGF1c2FibGVC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RoID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5zdWJqZWN0Lm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIG9uRXJyb3I6IGZ1bmN0aW9uIChlcnJvcikge1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgdGhpcy5oYXNGYWlsZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgdGhpcy5lcnJvciA9IGVycm9yO1xyXG5cclxuICAgICAgICAgICAgICAgIGlmICghdGhpcy5lbmFibGVRdWV1ZSB8fCB0aGlzLnF1ZXVlLmxlbmd0aCA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuc3ViamVjdC5vbkVycm9yKGVycm9yKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgb25OZXh0OiBmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgICAgIHZhciBoYXNSZXF1ZXN0ZWQgPSBmYWxzZTtcclxuXHJcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5yZXF1ZXN0ZWRDb3VudCA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLmVuYWJsZVF1ZXVlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMucXVldWUucHVzaCh2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5yZXF1ZXN0ZWRDb3VudCAhPT0gLTEpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMucmVxdWVzdGVkQ291bnQtLSA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5kaXNwb3NlQ3VycmVudFJlcXVlc3QoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBoYXNSZXF1ZXN0ZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgIGlmIChoYXNSZXF1ZXN0ZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLnN1YmplY3Qub25OZXh0KHZhbHVlKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgX3Byb2Nlc3NSZXF1ZXN0OiBmdW5jdGlvbiAobnVtYmVyT2ZJdGVtcykge1xyXG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuZW5hYmxlUXVldWUpIHtcclxuICAgICAgICAgICAgICAgICAgICAvL2NvbnNvbGUubG9nKCdxdWV1ZSBsZW5ndGgnLCB0aGlzLnF1ZXVlLmxlbmd0aCk7XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHdoaWxlICh0aGlzLnF1ZXVlLmxlbmd0aCA+PSBudW1iZXJPZkl0ZW1zICYmIG51bWJlck9mSXRlbXMgPiAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIC8vY29uc29sZS5sb2coJ251bWJlciBvZiBpdGVtcycsIG51bWJlck9mSXRlbXMpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLnN1YmplY3Qub25OZXh0KHRoaXMucXVldWUuc2hpZnQoKSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG51bWJlck9mSXRlbXMtLTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLnF1ZXVlLmxlbmd0aCAhPT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4geyBudW1iZXJPZkl0ZW1zOiBudW1iZXJPZkl0ZW1zLCByZXR1cm5WYWx1ZTogdHJ1ZSB9O1xyXG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiB7IG51bWJlck9mSXRlbXM6IG51bWJlck9mSXRlbXMsIHJldHVyblZhbHVlOiBmYWxzZSB9O1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5oYXNGYWlsZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLnN1YmplY3Qub25FcnJvcih0aGlzLmVycm9yKTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmNvbnRyb2xsZWREaXNwb3NhYmxlLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmNvbnRyb2xsZWREaXNwb3NhYmxlID0gZGlzcG9zYWJsZUVtcHR5O1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIGlmICh0aGlzLmhhc0NvbXBsZXRlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuc3ViamVjdC5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuY29udHJvbGxlZERpc3Bvc2FibGUuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuY29udHJvbGxlZERpc3Bvc2FibGUgPSBkaXNwb3NhYmxlRW1wdHk7XHJcbiAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgcmV0dXJuIHsgbnVtYmVyT2ZJdGVtczogbnVtYmVyT2ZJdGVtcywgcmV0dXJuVmFsdWU6IGZhbHNlIH07XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIHJlcXVlc3Q6IGZ1bmN0aW9uIChudW1iZXIpIHtcclxuICAgICAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgICAgIHRoaXMuZGlzcG9zZUN1cnJlbnRSZXF1ZXN0KCk7XHJcbiAgICAgICAgICAgICAgICB2YXIgc2VsZiA9IHRoaXMsXHJcbiAgICAgICAgICAgICAgICAgICAgciA9IHRoaXMuX3Byb2Nlc3NSZXF1ZXN0KG51bWJlcik7XHJcblxyXG4gICAgICAgICAgICAgICAgbnVtYmVyID0gci5udW1iZXJPZkl0ZW1zO1xyXG4gICAgICAgICAgICAgICAgaWYgKCFyLnJldHVyblZhbHVlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5yZXF1ZXN0ZWRDb3VudCA9IG51bWJlcjtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLnJlcXVlc3RlZERpc3Bvc2FibGUgPSBkaXNwb3NhYmxlQ3JlYXRlKGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgc2VsZi5yZXF1ZXN0ZWRDb3VudCA9IDA7XHJcbiAgICAgICAgICAgICAgICAgICAgfSk7XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLnJlcXVlc3RlZERpc3Bvc2FibGVcclxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGRpc3Bvc2FibGVFbXB0eTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgZGlzcG9zZUN1cnJlbnRSZXF1ZXN0OiBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLnJlcXVlc3RlZERpc3Bvc2FibGUuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICAgICAgdGhpcy5yZXF1ZXN0ZWREaXNwb3NhYmxlID0gZGlzcG9zYWJsZUVtcHR5O1xyXG4gIC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0gdGhpcy5mcmVlTGlzdDtcclxuICAgICAgICB0aGlzLmZyZWVMaXN0ID0gdGhpcy5lbnRyaWVzW2luZGV4M10ubmV4dDtcclxuICAgICAgICAtLXRoaXMuZnJlZUNvdW50O1xyXG4gICAgICB9IGVsc2Uge1xyXG4gICAgICAgIGlmICh0aGlzLnNpemUgPT09IHRoaXMuZW50cmllcy5sZW5ndGgpIHtcclxuICAgICAgICAgIHRoaXMuX3Jlc2l6ZSgpO1xyXG4gICAgICAgICAgaW5kZXgxID0gbnVtICUgdGhpcy5idWNrZXRzLmxlbmd0aDtcclxuICAgICAgICB9XHJcbiAgICAgICAgaW5kZXgzID0gdGhpcy5zaXplO1xyXG4gICAgICAgICsrdGhpcy5zaXplO1xyXG4gICAgICB9XHJcbiAgICAgIHRoaXMuZW50cmllc1tpbmRleDNdLmhhc2hDb2RlID0gbnVtO1xyXG4gICAgICB0aGlzLmVudHJpZXNbaW5kZXgzXS5uZXh0ID0gdGhpcy5idWNrZXRzW2luZGV4MV07XHJcbiAgICAgIHRoaXMuZW50cmllc1tpbmRleDNdLmtleSA9IGtleTtcclxuICAgICAgdGhpcy5lbnRyaWVzW2luZGV4M10udmFsdWUgPSB2YWx1ZTtcclxuICAgICAgdGhpcy5idWNrZXRzW2luZGV4MV0gPSBpbmRleDM7XHJcbiAgICB9O1xyXG5cclxuICAgIGRpY3Rpb25hcnlQcm90by5fcmVzaXplID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICB2YXIgcHJpbWUgPSBnZXRQcmltZSh0aGlzLnNpemUgKiAyKSxcclxuICAgICAgICBudW1BcnJheSA9IG5ldyBBcnJheShwcmltZSk7XHJcbiAgICAgIGZvciAoaW5kZXggPSAwOyBpbmRleCA8IG51bUFycmF5Lmxlbmd0aDsgKytpbmRleCkgeyAgbnVtQXJyYXlbaW5kZXhdID0gLTE7IH1cclxuICAgICAgdmFyIGVudHJ5QXJyYXkgPSBuZXcgQXJyYXkocHJpbWUpO1xyXG4gICAgICBmb3I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DNdLmhhc2hDb2RlID09PSBudW0gJiYgdGhpcy5jb21wYXJlcih0aGlzLmVudHJpZXNbaW5kZXgzXS5rZXksIGtleSkpIHtcclxuICAgICAgICAgICAgaWYgKGluZGV4MiA8IDApIHtcclxuICAgICAgICAgICAgICB0aGlzLmJ1Y2tldHNbaW5kZXgxXSA9IHRoaXMuZW50cmllc1tpbmRleDNdLm5leHQ7XHJcbiAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgdGhpcy5lbnRyaWVzW2luZGV4Ml0ubmV4dCA9IHRoaXMuZW50cmllc1tpbmRleDNdLm5leHQ7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgdGhpcy5lbnRyaWVzW2luZGV4M10uaGFzaENvZGUgPSAtMTtcclxuICAgICAgICAgICAgdGhpcy5lbnRyaWVzW2luZGV4M10ubmV4dCA9IHRoaXMuZnJlZUxpc3Q7XHJcbiAgICAgICAgICAgIHRoaXMuZW50cmllc1tpbmRleDNdLmtleSA9IG51bGw7XHJcbiAgICAgICAgICAgIHRoaXMuZW50cmllc1tpbmRleDNdLnZhbHVlID0gbnVsbDtcclxuICAgICAgICAgICAgdGhpcy5mcmVlTGlzdCA9IGluZGV4MztcclxuICAgICAgICAgICAgKyt0aGlzLmZyZWVDb3VudDtcclxuICAgICAgICAgICAgcmV0dXJuIHRydWU7XHJcbiAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICBpbmRleDIgPSBpbmRleDM7XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgfVxyXG4gICAgICB9XHJcbiAgICAgIHJldHVybiBmYWxzZTtcclxuICAgIH07XHJcblxyXG4gICAgZGljdGlvbmFyeVByb3RvLmNsZWFyID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICB2YXIgaW5kZXgsIGxlbjtcclxuICAgICAgaWYgKHRoaXMuc2l6ZSA8PSAwKSB7IHJldHVybjsgfVxyXG4gICAgICBmb3IgKGluZGV4ID0gMCwgbG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dDtcclxuICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICByZXN1bHQgPSByZXN1bHRTZWxlY3Rvcih2YWx1ZSwgdik7XHJcbiAgICAgICAgICAgIH0gY2F0Y2ggKGV4bikge1xyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXhuKTtcclxuICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChyZXN1bHQpO1xyXG4gICAgICAgICAgfSk7XHJcbiAgICAgICAgfSxcclxuICAgICAgICBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLFxyXG4gICAgICAgIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgIGxlZnREb25lID0gdHJ1ZTtcclxuICAgICAgICAgIChyaWdodERvbmUgfHwgbGVmdE1hcC5jb3VudCgpID09PSAwKSAmJiBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgIH0pXHJcbiAgICAgICk7XHJcblxyXG4gICAgICBncm91cC5hZGQocmlnaHQuc3Vic2NyaWJlKFxyXG4gICAgICAgIGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgdmFyIGlkID0gcmlnaHRJZCsrO1xyXG4gICAgICAgICAgdmFyIG1kID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcblxyXG4gICAgICAgICAgcmlnaHRNYXAuYWRkKGlkLCB2YWx1ZSk7XHJcbiAgICAgICAgICBncm91cC5hZGQobWQpO1xyXG5cclxuICAgICAgICAgIHZhciBleHBpcmUgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIHJpZ2h0TWFwLnJlbW92ZShpZCkgJiYgcmlnaHRNYXAuY291bnQoKSA9PT0gMCAmJiByaWdodERvbmUgJiYgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgZ3JvdXAucmVtb3ZlKG1kKTtcclxuICAgICAgICAgIH07XHJcblxyXG4gICAgICAgICAgdmFyIGR1cmF0aW9uO1xyXG4gICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgZHVyYXRpb24gPSByaWdodER1cmF0aW9uU2VsZWN0b3IodmFsdWUpO1xyXG4gICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgbWQuc2V0RGlzcG9zYWJsZShkdXJhdGlvbi50YWtlKDEpLnN1YnNjcmliZShub29wLCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBleHBpcmUpKTtcclxuXHJcbiAgICAgICAgICBsZWZ0TWFwLmdldFZhbHVlcygpLmZvckVhY2goZnVuY3Rpb24gKHYpIHtcclxuICAgICAgICAgICAgdmFyIHJlc3VsdDtcclxuICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICByZXN1bHQgPSByZXN1bHRTZWxlY3Rvcih2LCB2YWx1ZSk7XHJcbiAgICAgICAgICAgIH0gY2F0Y2goZXhuKSB7XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleG4pO1xyXG4gICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdCk7XHJcbiAgICAgICAgICB9KTtcclxuICAgICAgICB9LFxyXG4gICAgICAgIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksXHJcbiAgICAgICAgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgcmlnaHREb25lID0gdHJ1ZTtcclxuICAgICAgICAgIChsZWZ0RG9uZSB8fCByaWdodE1hcC5jb3VudCgpID09PSAwKSAmJiBvYnNlcnZlci5vbkNvb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HJcbiAgICAgICAgICAgIGxlZnRNYXAucmVtb3ZlKGlkKSAmJiBzLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIGdyb3VwLnJlbW92ZShtZCk7XHJcbiAgICAgICAgICB9O1xyXG5cclxuICAgICAgICAgIHZhciBkdXJhdGlvbjtcclxuICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgIGR1cmF0aW9uID0gbGVmdER1cmF0aW9uU2VsZWN0b3IodmFsdWUpO1xyXG4gICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICBsZWZ0TWFwLmdldFZhbHVlcygpLmZvckVhY2goaGFuZGxlRXJyb3IoZSkpO1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgbWQuc2V0RGlzcG9zYWJsZShkdXJhdGlvbi50YWtlKDEpLnN1YnNjcmliZShcclxuICAgICAgICAgICAgbm9vcCxcclxuICAgICAgICAgICAgZnVuY3Rpb24gKGUpIHtcclxuICAgICAgICAgICAgICBsZWZ0TWFwLmdldFZhbHVlcygpLmZvckVhY2goaGFuZGxlRXJyb3IoZSkpO1xyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIGV4cGlyZSlcclxuICAgICAgICAgICk7XHJcbiAgICAgICAgfSxcclxuICAgICAgICBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgbGVmdE1hcC5nZXRWYWx1ZXMoKS5mb3JFYWNoKGhhbmRsZUVycm9yKGUpKTtcclxuICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgfSxcclxuICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZC5iaW5kKG9ic2VydmVyKSlcclxuICAgICAgKTtcclxuXHJcbiAgICAgIGdyb3VwLmFkZChyaWdodC5zdWJzY3JpYmUoXHJcbiAgICAgICAgZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgICB2YXIgaWQgPSByaWdodElkKys7XHJcbiAgICAgICAgICByaWdodE1hcC5hZGQoaWQsIHZhbHVlKTtcclxuXHJcbiAgICAgICAgICB2YXIgbWQgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgIGdyb3VwLmFkZChtZCk7XHJcblxyXG4gICAgICAgICAgdmFyIGV4cGlyZSA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgcmlnaHRNYXAucmVtb3ZlKGlkKTtcclxuICAgICAgICAgICAgZ3JvdXAucmVtb3ZlKG1kKTtcclxuICAgICAgICAgIH07XHJcblxyXG4gICAgICAgICAgdmFyIGR1cmF0aW9uO1xyXG4gICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgZHVyYXRpb24gPSByaWdodER1cmF0aW9uU2VsZWN0b3IodmFsdWUpO1xyXG4gICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICBsZWZ0TWFwLmdldFZhbHVlcygpLmZvckVhY2goaGFuZGxlRXJyb3IoZSkpO1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgICBtZC5zZXREaXNwb3NhYmxlKGR1cmF0aW9uLnRha2UoMSkuc3Vic2NyaWJlKFxyXG4gICAgICAgICAgICBub29wLFxyXG4gICAgICAgICAgICBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgICAgIGxlZnRNYXAuZ2V0VmFsdWVzKCkuZm9yRWFjaChoYW5kbGVFcnJvcihlKSk7XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgZXhwaXJlKVxy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luID0gbmV3IFN1YmplY3QoKTtcclxuICAgICAgb2JzZXJ2ZXIub25OZXh0KGFkZFJlZih3aW4sIHIpKTtcclxuICAgICAgZC5hZGQoc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgd2luLm9uTmV4dCh4KTtcclxuICAgICAgfSwgZnVuY3Rpb24gKGVycikge1xyXG4gICAgICAgICAgd2luLm9uRXJyb3IoZXJyKTtcclxuICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXJyKTtcclxuICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgd2luLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICB9KSk7XHJcbiAgICAgIFxyXG4gICAgICBmdW5jdGlvbiBjcmVhdGVXaW5kb3dDbG9zZSAoKSB7XHJcbiAgICAgICAgdmFyIHdpbmRvd0Nsb3NlO1xyXG4gICAgICAgIHRyeSB7XHJcbiAgICAgICAgICB3aW5kb3dDbG9zZSA9IHdpbmRvd0Nsb3NpbmdTZWxlY3RvcigpO1xyXG4gICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBpc1Byb21pc2Uod2luZG93Q2xvc2UpICYmICh3aW5kb3dDbG9zZSA9IG9ic2VydmFibGVGcm9tUHJvbWlzZSh3aW5kb3dDbG9zZSkpO1xyXG5cclxuICAgICAgICB2YXIgbTEgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICBtLnNldERpc3Bvc2FibGUobTEpO1xyXG4gICAgICAgIG0xLnNldERpc3Bvc2FibGUod2luZG93Q2xvc2UudGFrZSgxKS5zdWJzY3JpYmUobm9vcCwgZnVuY3Rpb24gKGVycikge1xy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cG9zYWJsZShtKSxcclxuICAgICAgICBhY3RpdmVDb3VudCA9IDAsXHJcbiAgICAgICAgaXNBY3F1aXJlZCA9IGZhbHNlO1xyXG5cclxuICAgICAgdmFyIGVuc3VyZUFjdGl2ZSA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICB2YXIgaXNPd25lciA9IGZhbHNlO1xyXG4gICAgICAgIGlmIChxLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgaXNPd25lciA9ICFpc0FjcXVpcmVkO1xyXG4gICAgICAgICAgICBpc0FjcXVpcmVkID0gdHJ1ZTtcclxuICAgICAgICB9XHJcbiAgICAgICAgaWYgKGlzT3duZXIpIHtcclxuICAgICAgICAgIG0uc2V0RGlzcG9zYWJsZShzY2hlZHVsZXIuc2NoZWR1bGVSZWN1cnNpdmUoZnVuY3Rpb24gKHNlbGYpIHtcclxuICAgICAgICAgICAgdmFyIHdvcms7XHJcbiAgICAgICAgICAgIGlmIChxLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgICB3b3JrID0gcS5zaGlmdCgpO1xyXG4gICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgIGlzQWNxdWlyZWQgPSBmYWxzZTtcclxuICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgdmFyIG0xID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgICAgIGQuYWRkKG0xKTtcclxuICAgICAgICAgICAgbTEuc2V0RGlzcG9zYWJsZSh3b3JrLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh4KTtcclxuICAgICAgICAgICAgICB2YXIgcmVzdWx0ID0gbnVsbDtcclxuICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgcmVzdWx0ID0gc2VsZWN0b3IoeCk7XHJcbiAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgcS5wdXNoKHJlc3VsdCk7XHJcbiAgICAgICAgICAgICAgYWN0aXZlQ291bnQrKztcclxuICAgICAgICAgICAgICBlbnN1cmVBY3RpdmUoKTtcclxuICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgIGQucmVtb3ZlKG0xKTtcclxuICAgICAgICAgICAgICBhY3RpdmVDb3VudC0tO1xyXG4gICAgICAgICAgICAgIGlmIChhY3RpdmVDb3VudCA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgc2VsZigpO1xyXG4gICAgICAgICAgfSkpO1xyXG4gICAgICAgIH1cclxuICAgICAgfTtcclxuXHJcbiAgICAgIHEucHVzaChzb3VyY2UpO1xyXG4gICAgICBhY3RpdmVDb3VudCsrO1xyXG4gICAgICBlbnN1cmVBY3RpdmUoKTtcclxuICAgICAgcmV0dXJuIGQ7XHJcbiAgICB9KTtcclxuICB9O1xyXG5cclxuICAgLyoqXHJcbiAgICogIFJ1bnMgYWxsIG9ic2VydmFibGUgc2VxdWVuY2VzIGluIHBhcmFsbGVsIGFuZCBjb2xsZWN0IHRoZWlyIGxhc3QgZWxlbWVudHMuXHJcbiAgICpcclxuICAgKiBAZXhhbXBsZVxyXG4gICAqICAxIC0gcmVzID0gUnguT2JzZXJ2YWJsZS5mb3JrSm9pbihbb2JzMSwgb2JzMl0pO1xyXG4gICAqICAxIC0gcmVzID0gUnguT2JzZXJ2YWJsZS5mb3JrSm9pbihvYnMxLCBvYnMyLCAuLi4pO1xyXG4gICAq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G4gICAgICAgICAgZ3JvdXAuYWRkKFxyXG4gICAgICAgICAgICBzb3VyY2Uuc3Vic2NyaWJlKFxyXG4gICAgICAgICAgICAgIGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgICAgIGlmICghZmluaXNoZWQpIHtcclxuICAgICAgICAgICAgICAgIGhhc1Jlc3VsdHNbaV0gPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgcmVzdWx0c1tpXSA9IHZhbHVlO1xyXG4gICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgZnVuY3Rpb24gKGUpIHtcclxuICAgICAgICAgICAgICBmaW5pc2hlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgc3Vic2NyaWJlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgIGdyb3VwLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgIGlmICghZmluaXNoZWQpIHtcclxuICAgICAgICAgICAgICAgIGlmICghaGFzUmVzdWx0c1tpXSkge1xyXG4gICAgICAgICAgICAgICAgICAgIHN1YnNjcmliZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBoYXNDb21wbGV0ZWRbaV0gPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgZm9yICh2YXIgaXggPSAwOyBpeCA8IGNvdW50OyBpeCsrKSB7XHJcbiAgICAgICAgICAgICAgICAgIGlmICghaGFzQ29tcGxldGVkW2l4XSkgeyByZXR1cm47IH1cclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGZpbmlzaGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIHN1YnNjcmliZXIub25OZXh0KHJlc3VsdHMpO1xyXG4gICAgICAgICAgICAgICAgc3V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IHZhciByZXN1bHQ7XHJcbiAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICByZXN1bHQgPSByZXN1bHRTZWxlY3RvcihsYXN0TGVmdCwgbGFzdFJpZ2h0KTtcclxuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdCk7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgfSlcclxuICAgICAgKTtcclxuXHJcbiAgICAgIHJpZ2h0U3Vic2NyaXB0aW9uLnNldERpc3Bvc2FibGUoXHJcbiAgICAgICAgc2Vjb25kLnN1YnNjcmliZShmdW5jdGlvbiAocmlnaHQpIHtcclxuICAgICAgICAgIGhhc1JpZ2h0ID0gdHJ1ZTtcclxuICAgICAgICAgIGxhc3RSaWdodCA9IHJpZ2h0O1xyXG4gICAgICAgIH0sIGZ1bmN0aW9uIChlcnIpIHtcclxuICAgICAgICAgIGxlZnRTdWJzY3JpcHRpb24uZGlzcG9zZSgpO1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlcnIpO1xyXG4gICAgICAgIH0sIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgIHJpZ2h0U3RvcHBlZCA9IHRydWU7XHJcbiAgICAgICAgICBpZiAobGVmdFN0b3BwZWQpIHtcclxuICAgICAgICAgICAgaWYgKCFoYXNMZWZ0KSB7XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfSBlbHNlIGlmICghaGFzUmlnaHQpIHtcclxuICAgIC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lc3VsdCwgc2hvdWxkUmVjdXJzZTtcclxuICAgICAgICAgICAgICBpZiAoZXhjZXB0aW9uICE9PSBudWxsKSB7XHJcbiAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgIHJ1bm5pbmcgPSB0cnVlO1xyXG4gICAgICAgICAgICAgIGRvIHtcclxuICAgICAgICAgICAgICAgIHJlc3VsdCA9IG51bGw7XHJcbiAgICAgICAgICAgICAgICBpZiAocS5sZW5ndGggPiAwICYmIHFbMF0udGltZXN0YW1wIC0gc2NoZWR1bGVyLm5vdygpIDw9IDApIHtcclxuICAgICAgICAgICAgICAgICAgcmVzdWx0ID0gcS5zaGlmdCgpLnZhbHVlO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaWYgKHJlc3VsdCAhPT0gbnVsbCkge1xyXG4gICAgICAgICAgICAgICAgICByZXN1bHQuYWNjZXB0KG9ic2VydmVyKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICB9IHdoaWxlIChyZXN1bHQgIT09IG51bGwpO1xyXG4gICAgICAgICAgICAgIHNob3VsZFJlY3Vyc2UgPSBmYWxzZTtcclxuICAgICAgICAgICAgICByZWN1cnNlRHVlVGltZSA9IDA7XHJcbiAgICAgICAgICAgICAgaWYgKHEubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgICAgICAgc2hvdWxkUmVjdXJzZSA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICByZWN1cnNlRHVlVGltZSA9IE1hdGgubWF4KDAsIHFbMF0udGltZXN0YW1wIC0gc2NoZWR1bGVyLm5vdygpKTtcclxuICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgYWN0aXZlID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgIGUgPSBleGNlcHRpb247XHJcbiAgICAgICAgICAgICAgcnVubmluZyA9IGZhb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cyA9IG5ldyBTdWJqZWN0KCk7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbk5leHQoYWRkUmVmKHMsIHJlZkNvdW50RGlzcG9zYWJsZSkpO1xyXG4gICAgICAgICAgY3JlYXRlVGltZXIobmV3SWQpO1xyXG4gICAgICAgIH0pKTtcclxuICAgICAgfVxyXG4gICAgICBcclxuICAgICAgb2JzZXJ2ZXIub25OZXh0KGFkZFJlZihzLCByZWZDb3VudERpc3Bvc2FibGUpKTtcclxuICAgICAgY3JlYXRlVGltZXIoMCk7XHJcblxyXG4gICAgICBncm91cERpc3Bvc2FibGUuYWRkKHNvdXJjZS5zdWJzY3JpYmUoXHJcbiAgICAgICAgZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgIHZhciBuZXdJZCA9IDAsIG5ld1dpbmRvdyA9IGZhbHNlO1xyXG4gICAgICAgICAgcy5vbk5leHQoeCk7XHJcbiAgICAgICAgICBpZiAoKytuID09PSBjb3VudCkge1xyXG4gICAgICAgICAgICBuZXdXaW5kb3cgPSB0cnVlO1xyXG4gICAgICAgICAgICBuID0gMDtcclxuICAgICAgICAgICAgbmV3SWQgPSArK3dpbmRvd0lkO1xyXG4gICAgICAgICAgICBzLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIHMgPSBuZXcgU3ViamVjdCgpO1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoYWRkUmVmKHMsIHJlZkNvdW50RGlzcG9zYWJsZSkpO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgICAgbmV3V2luZG93ICYmIGNyZWF0ZVRpbWVyKG5ld0lkKTtcclxuICAgICAgICB9LCBcclxuICAgICAgICBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgcy5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICBzLm9uQ29tcGxldGVkKCk7X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XG4gICAgICAgIGlmICh0eXBlb2Ygc3Vic2NyaXB0aW9uRGVsYXkgPT09ICdmdW5jdGlvbicpIHtcclxuICAgICAgICAgICAgc2VsZWN0b3IgPSBzdWJzY3JpcHRpb25EZWxheTtcclxuICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICBzdWJEZWxheSA9IHN1YnNjcmlwdGlvbkRlbGF5O1xyXG4gICAgICAgICAgICBzZWxlY3RvciA9IGRlbGF5RHVyYXRpb25TZWxlY3RvcjtcclxuICAgICAgICB9XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgZGVsYXlzID0gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUoKSwgYXRFbmQgPSBmYWxzZSwgZG9uZSA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIGlmIChhdEVuZCAmJiBkZWxheXMubGVuZ3RoID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSwgc3Vic2NyaXB0aW9uID0gbmV3IFNlcmlhbERpc3Bvc2FibGUoKSwgc3RhcnQgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBzdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZShzb3VyY2Uuc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIGRlbGF5O1xyXG4gICAgICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGRlbGF5ID0gc2VsZWN0b3IoeCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZXJyb3IpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlcnJvcik7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIGQgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgICAgICAgICBkZWxheXMuYWRkKGQpO1xyXG4gICAgICAgICAgICAgICAgICAgIGQuc2V0RGlzcG9zYWJsZShkZWxheS5zdWJzY3JpYmUoZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGRlbGF5cy5yZW1vdmUoZCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGRvbmUoKTtcclxuICAgICAgICAgICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh4KTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZGVsYXlzLnJlbW92ZShkKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZG9uZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICBhdEVuZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgc3Vic2NyaXB0aW9uLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgICAgICAgICBkb25lKCk7XHJcbiAgICAgICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICAgIH07XHJcblxyXG4gICAgICAgICAgICBpZiAoIXN1YkRlbGF5KSB7XHJcbiAgICAgICAgICAgICAgICBzdGFydCg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JlcyA9ICFzd2l0Y2hlZDtcclxuICAgICAgICAgIGlmIChyZXMpIHsgaWQrKzsgfVxyXG4gICAgICAgICAgcmV0dXJuIHJlcztcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIG9yaWdpbmFsLnNldERpc3Bvc2FibGUoc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgaWYgKG9ic2VydmVyV2lucygpKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh4KTtcclxuICAgICAgICAgICAgdmFyIHRpbWVvdXQ7XHJcbiAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgdGltZW91dCA9IHRpbWVvdXRkdXJhdGlvblNlbGVjdG9yKHgpO1xyXG4gICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgc2V0VGltZXIoaXNQcm9taXNlKHRpbWVvdXQpID8gb2JzZXJ2YWJsZUZyb21Qcm9taXNlKHRpbWVvdXQpIDogdGltZW91dCk7XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgfSwgZnVuY3Rpb24gKGUpIHtcclxuICAgICAgICAgIG9ic2VydmVyV2lucygpICYmIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgb2JzZXJ2ZXJXaW5zKCkgJiYgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICB9KSk7XHJcbiAgICAgICAgcmV0dXJuIG5ldyBDb21wb3NpdGVEaXNwb3NhYmxlKHN1YnNjcmlwdGlvbiwgdGltZXIpO1xyXG4gICAgICB9KTtcclxuICAgIH07XHJcblxyXG4gIC8qKlxyXG4gICAqICBJZ25vcmVzIHZhbHVlcyBmcm9tIG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XG5cclxuICAgICAgICAgICAgdmFyIGlubmVyU3Vic2NyaXB0aW9uID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgICAgIGcuYWRkKGlubmVyU3Vic2NyaXB0aW9uKTtcclxuXHJcbiAgICAgICAgICAgIGlubmVyU3Vic2NyaXB0aW9uLnNldERpc3Bvc2FibGUoaW5uZXJTb3VyY2Uuc3Vic2NyaWJlKFxyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dC5iaW5kKG9ic2VydmVyKSxcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLFxyXG4gICAgICAgICAgICAgIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIGcucmVtb3ZlKGlubmVyU3Vic2NyaXB0aW9uKTtcclxuICAgICAgICAgICAgICAgIGhhc0N1cnJlbnQgPSBmYWxzZTtcclxuICAgICAgICAgICAgICAgIGlmIChpc1N0b3BwZWQgJiYgZy5sZW5ndGggPT09IDEpIHtcclxuICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgIH0sXHJcbiAgICAgICAgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSxcclxuICAgICAgICBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICBpc1N0b3BwZWQgPSB0cnVlO1xyXG4gICAgICAgICAgaWYgKCFoYXNDdXJyZW50ICYmIGcubGVuZ3RoID09PSAxKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgfSkpO1xyXG5cclxuICAgICAgcmV0dXJuIGc7XHJcbiAgICB9KTtcclxuICB9O1xyXG5cclxuICAvKlxyXG4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oKTtcclxuXHJcbiAgICAgIGcuYWRkKG0pO1xyXG5cclxuICAgICAgbS5zZXREaXNwb3NhYmxlKHNvdXJjZXMuc3Vic2NyaWJlKFxyXG4gICAgICAgIGZ1bmN0aW9uIChpbm5lclNvdXJjZSkge1xyXG5cclxuICAgICAgICAgIGlmICghaGFzQ3VycmVudCkge1xyXG4gICAgICAgICAgICBoYXNDdXJyZW50ID0gdHJ1ZTtcclxuXHJcbiAgICAgICAgICAgIGlubmVyU3Vic2NyaXB0aW9uID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgICAgIGcuYWRkKGlubmVyU3Vic2NyaXB0aW9uKTtcclxuXHJcbiAgICAgICAgICAgIGlzUHJvbWlzZShpbm5lclNvdXJjZSkgJiYgKGlubmVyU291cmNlID0gb2JzZXJ2YWJsZUZyb21Qcm9taXNlKGlubmVyU291cmNlKSk7XHJcblxyXG4gICAgICAgICAgICBpbm5lclN1YnNjcmlwdGlvbi5zZXREaXNwb3NhYmxlKGlubmVyU291cmNlLnN1YnNjcmliZShcclxuICAgICAgICAgICAgICBmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgdmFyIHJlc3VsdDtcclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgIHJlc3VsdCA9IHNlbGVjdG9yLmNhbGwodGhpc0FyZywgeCwgaW5kZXgrKywgaW5uZXJTb3VyY2UpO1xyXG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdCk7XHJcbiAgICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLFxyXG4gICAgICAgICAgICAgIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIGcucmVtb3ZlKGlubmVyU3Vic2NyaXB0aW9uKTtcclxuICAgICAgICAgICAgICAgIGhhc0N1cnJlbnQgPSBmYWxzZTtcclxuXHJcbiAgICAgICAgICAgICAgICBpZiAoaXNTdG9wcGVkICYmIGcubGVuZ3RoID09PSAxKSB7XHJcbiAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgIH0sXHJcbiAgICAgICAgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSxcclxuICAgICAgICBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICBpc1N0b3BwZWQgPSB0cnVlO1xyXG4gICAgICAgICAgaWYgKGcubGVuZ3RoID09PSAxICYmICFoYXNDdXJyZW50KSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgfSkpO1xyXG4gICAgICByZXR1cm4gZztcclxuICAgIH0pO1xyXG4gIH07XHJcblxyXG4gIC8qKiBQcm92aWRlcyBhIHNldCBvZiBleHRlbnNpb24gbWV0aG9kcyBmb3IgdmlydHVhbCB0aW1lIHNjaGVkdWxpbmcuICovXHJcbiAgUnguVmlydHVhbFRpbWVTY2hlZHVsZXIgPSAoZnVuY3Rpb24gKF9fc3VwZXJfXykge1xyXG5cclxuICAgIGZ1bmN0aW9uIG5vdEltcGxlbWVudGVkKCkge1xyXG4gICAgICAgIHRocm93IG5ldyBFcnJvcignTm90IGltcGxlbWVudGVkJyk7XHJcbiAgICB9XHJcblxyXG4gICAgZnVuY3Rpb24gbG9jYWxOb3coKSB7XHJcbiAgICAgIHJldHVybiB0aGlzLnRvRGF0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WNoT2JzZXJ2ZXIob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgX3N1cGVyLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXIgPSBvYnNlcnZlcjtcclxuICAgICAgICAgICAgdGhpcy5tID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICB2YXIgQXV0b0RldGFjaE9ic2VydmVyUHJvdG90eXBlID0gQXV0b0RldGFjaE9ic2VydmVyLnByb3RvdHlwZTtcclxuXHJcbiAgICAgICAgQXV0b0RldGFjaE9ic2VydmVyUHJvdG90eXBlLm5leHQgPSBmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgdmFyIG5vRXJyb3IgPSBmYWxzZTtcclxuICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXIub25OZXh0KHZhbHVlKTtcclxuICAgICAgICAgICAgICAgIG5vRXJyb3IgPSB0cnVlO1xyXG4gICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICB0aHJvdyBlO1xyXG4gICAgICAgICAgICB9IGZpbmFsbHkge1xyXG4gICAgICAgICAgICAgICAgaWYgKCFub0Vycm9yKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICBBdXRvRGV0YWNoT2JzZXJ2ZXJQcm90b3R5cGUuZXJyb3IgPSBmdW5jdGlvbiAoZXhuKSB7XHJcbiAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLm9ic2VydmVyLm9uRXJyb3IoZXhuKTtcclxuICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgdGhyb3cgZTtcclxuICAgICAgICAgICAgfSBmaW5hbGx5IHtcclxuICAgICAgICAgICAgICAgIHRoaXMuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgQXV0b0RldGFjaE9ic2VydmVyUHJvdG90eXBlLmNvbXBsZXRlZCA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgdGhyb3cgZTtcclxuICAgICAgICAgICAgfSBmaW5hbGx5IHtcclxuICAgICAgICAgICAgICAgIHRoaXMuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgQXV0b0RldGFjaE9ic2VydmVyUHJvdG90eXBlLnNldERpc3Bvc2FibGUgPSBmdW5jdGlvbiAodmFsdWUpIHsgdGhpcy5tLnNldERpc3Bvc2FibGUodmFsdWUpOyB9O1xyXG4gICAgICAgIEF1dG9EZXRhY2hPYnNlcnZlclByb3RvdHlwZS5nZXREaXNwb3NhYmxlID0gZnVuY3Rpb24gKHZhbHVlKSB7IHJldHVybiB0aGlzLm0uZ2V0RGlzcG9zYWJsZSgpOyB9O1xyXG4gICAgICAgIC8qIEBwcml2YXRlICovXHJcbiAgICAgICAgQXV0b0RldGFjaE9ic2VydmVyUHJvdG90eXBlLmRpc3Bvc2FibGUgPSBmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgcmV0dXJuIGFyZ3VtZW50cy5sZW5ndGggPyB0aGlzLmdldERpc3Bvc2FibGUoKSA6IHNldERpc3Bvc2FibGUodmFsdWUpO1xyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIEF1dG9EZXRhY2hPYnNlcnZlclByb3RvdHlwZS5kaXNwb3NlID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AgICAgICAgICBvbkNvbXBsZXRlZDogZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmlzU3RvcHBlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBvcyA9IHRoaXMub2JzZXJ2ZXJzLnNsaWNlKDApO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuaXNTdG9wcGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gb3MubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb3NbaV0ub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzID0gW107XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBOb3RpZmllcyBhbGwgc3Vic2NyaWJlZCBvYnNlcnZlcnMgYWJvdXQgdGhlIGV4Y2VwdGlvbi5cclxuICAgICAgICAgICAgICogQHBhcmFtIHtNaXhlZH0gZXJyb3IgVGhlIGV4Y2VwdGlvbiB0byBzZW5kIHRvIGFsbCBvYnNlcnZlcnMuXHJcbiAgICAgICAgICAgICAqL1xyXG4gICAgICAgICAgICBvbkVycm9yOiBmdW5jdGlvbiAoZXhjZXB0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIG9zID0gdGhpcy5vYnNlcnZlcnMuc2xpY2UoMCk7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5pc1N0b3BwZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuZXhjZXB0aW9uID0gZXhjZXB0aW9uO1xyXG4gICAgICAgICAgICAgICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSBvcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvc1tpXS5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgICAgICB0aGlzLm9ic2VydmVycyA9IFtdO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogTm90aWZpZXMgYWxsIHN1YnNjcmliZWQgb2JzZXJ2ZXJzIGFib3V0IHRoZSBhcnJpdmFsIG9mIHRoZSBzcGVjaWZpZWQgZWxlbWVudCBpbiB0aGUgc2VxdWVuY2UuXHJcbiAgICAgICAgICAgICAqIEBwYXJhbSB7TWl4ZWR9IHZhbHVlIFRoZSB2YWx1ZSB0byBzZW5kIHRvIGFsbCBvYnNlcnZlcnMuXHJcbiAgICAgICAgICAgICAqL1xyXG4gICAgICAgICAgICBvbk5leHQ6IGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmlzU3RvcHBlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBvcyA9IHRoaXMub2JzZXJ2ZXJzLnNsaWNlKDApO1xyXG4gICAgICAgICAgICAgICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSBvcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvc1tpXS5vbk5leHQodmFsdWUpO1xyXG4gICAgICAgIC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iAgICAgICAgICAgIF9zdXBlci5jYWxsKHRoaXMsIHN1YnNjcmliZSk7XHJcbiAgICAgICAgICAgIHZhciBtZXNzYWdlLCBub3RpZmljYXRpb24sIG9ic2VydmFibGUgPSB0aGlzO1xyXG4gICAgICAgICAgICB0aGlzLnNjaGVkdWxlciA9IHNjaGVkdWxlcjtcclxuICAgICAgICAgICAgdGhpcy5tZXNzYWdlcyA9IG1lc3NhZ2VzO1xyXG4gICAgICAgICAgICB0aGlzLnN1YnNjcmlwdGlvbnMgPSBbXTtcclxuICAgICAgICAgICAgdGhpcy5vYnNlcnZlcnMgPSBbXTtcclxuICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IHRoaXMubWVzc2FnZXMubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgIG1lc3NhZ2UgPSB0aGlzLm1lc3NhZ2VzW2ldO1xyXG4gICAgICAgICAgICAgICAgbm90aWZpY2F0aW9uID0gbWVzc2FnZS52YWx1ZTtcclxuICAgICAgICAgICAgICAgIChmdW5jdGlvbiAoaW5uZXJOb3RpZmljYXRpb24pIHtcclxuICAgICAgICAgICAgICAgICAgICBzY2hlZHVsZXIuc2NoZWR1bGVBYnNvbHV0ZVdpdGhTdGF0ZShudWxsLCBtZXNzYWdlLnRpbWUsIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgdmFyIG9icyA9IG9ic2VydmFibGUub2JzZXJ2ZXJzLnNsaWNlKDApO1xyXG5cclxuICAgICAgICAgICAgICAgICAgICAgICAgZm9yICh2YXIgaiA9IDAsIGpMZW4gPSBvYnMubGVuZ3RoOyBqIDwgakxlbjsgaisrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpbm5lck5vdGlmaWNhdGlvbi5hY2NlcHQob2JzW2pdKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gZGlzcG9zYWJsZUVtcHR5O1xyXG4gICAgICAgICAgICAgICAgICAgIH0pO1xyXG4gICAgICAgICAgICAgICAgfSkobm90aWZpY2F0aW9uKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgcmV0dXJuIEhvdE9ic2VydmFibGU7XHJcbiAgICB9KShPYnNlcnZhYmxlKTtcclxuXHJcbiAgICAvKiogQHByaXZhdGUgKi9cclxuICAgIHZhciBDb2xkT2JzZXJ2YWJsZSA9IChmdW5jdGlvbiAoX3N1cGVyKSB7XHJcblxyXG4gICAgICAgIGZ1bmN0aW9uIHN1YnNjcmliZShvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgbWVzc2FnZSwgbm90aWZpY2F0aW9uLCBvYnNlcnZhYmxlID0gdGhpcztcclxuICAgICAgICAgICAgdGhpcy5zdWJzY3JpcHRpb25zLnB1c2gobmV3IFN1YnNjcmlwdGlvbih0aGlzLnNjaGVkdWxlci5jbG9jaykpO1xyXG4gICAgICAgICAgICB2YXIgaW5kZXggPSB0aGlzLnN1YnNjcmlwdGlvbnMubGVuZ3RoIC0gMTtcclxuICAgICAgICAgICAgdmFyIGQgPSBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gdGhpcy5tZXNzYWdlcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgbWVzc2FnZSA9IHRoaXMubWVzc2FnZXNbaV07XHJcbiAgICAgICAgICAgICAgICBub3RpZmljYXRpb24gPSBtZXNzYWdlLnZhbHVlO1xyXG4gICAgICAgICAgICAgICAgKGZ1bmN0aW9uIChpbm5lck5vdGlmaWNhdGlvbikge1xyXG4gICAgICAgICAgICAgICAgICAgIGQuYWRkKG9ic2VydmFibGUuc2NoZWR1bGVyLnNjaGVkdWxlUmVsYXRpdmVXaXRoU3RhdGUobnVsbCwgbWVzc2FnZS50aW1lLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlubmVyTm90aWZpY2F0aW9uLmFjY2VwdChvYnNlcnZlcik7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBkaXNwb3NhYmxlRW1wdHk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICAgICAgfSkobm90aWZpY2F0aW9uKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICByZXR1cm4gZGlzcG9zYWJsZUNyZWF0ZShmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZhYmxlLnN1YnNjcmlwdGlvbnNbaW5kZXhdID0gbmV3IFN1YnNjcmlwdGlvbihvYnNlcnZhYmxlLnN1YnNjcmlwdGlvbnNbaW5kZXhdLnN1YnNjcmliZSwgb2JzZXJ2YWJsZS5zY2hlZHVsZXIuY2xvY2spO1xyXG4gICAgICAgICAgICAgICAgZC5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgaW5oZXJpdHMoQ29sZE9ic2VydmFibGUsIF9zdXBlcik7XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICogQGNvbnN0cnVjdG9yXHJcbiAgICAgICAgICovXHJcbiAgICAgICAgZnVuY3Rpb24gQ29sZE9ic2VydmFibGUoc2NoZWR1bGVyLCBtZXNzYWdlcykge1xyXG4gICAgICAgICAgICBfc3VwZXIuY2FsbCh0aGlzLCBzdWJzY3JpYmUpO1xyXG4gICAgICAgICAgICB0aGlzLnNjaGVkdWxlciA9IHNjaGVkdWxlcjtcclxuICAgICAgICAgICAgdGhpcy5tZXNzYWdlcyA9IG1lc3NhZ2VzO1xyXG4gICAgICAgICAgICB0aGlzLnN1YnNjcmlwdGlvbnMgPSBbXTtcclxuICAgICAgICB9X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gZWxzZSBpZiAoaXNIb29rKHByb3BWYWx1ZSkpIHtcbiAgICAgICAgICAgIHByb3BWYWx1ZS5ob29rKG5vZGUsXG4gICAgICAgICAgICAgICAgcHJvcE5hbWUsXG4gICAgICAgICAgICAgICAgcHJldmlvdXMgPyBwcmV2aW91c1twcm9wTmFtZV0gOiB1bmRlZmluZWQpXG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBpZiAoaXNPYmplY3QocHJvcFZhbHVlKSkge1xuICAgICAgICAgICAgICAgIHBhdGNoT2JqZWN0KG5vZGUsIHByb3BzLCBwcmV2aW91cywgcHJvcE5hbWUsIHByb3BWYWx1ZSk7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKHByb3BWYWx1ZSAhPT0gdW5kZWZpbmVkKSB7XG4gICAgICAgICAgICAgICAgbm9kZVtwcm9wTmFtZV0gPSBwcm9wVmFsdWVcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cbn1cblxuZnVuY3Rpb24gcmVtb3ZlUHJvcGVydHkobm9kZSwgcHJvcHMsIHByZXZpb3VzLCBwcm9wTmFtZSkge1xuICAgIGlmIChwcmV2aW91cykge1xuICAgICAgICB2YXIgcHJldmlvdXNWYWx1ZSA9IHByZXZpb3VzW3Byb3BOYW1lXVxuXG4gICAgICAgIGlmICghaXNIb29rKHByZXZpb3VzVmFsdWUpKSB7XG4gICAgICAgICAgICBpZiAocHJvcE5hbWUgPT09IFwiYXR0cmlidXRlc1wiKSB7XG4gICAgICAgICAgICAgICAgZm9yICh2YXIgYXR0ck5hbWUgaW4gcHJldmlvdXNWYWx1ZSkge1xuICAgICAgICAgICAgICAgICAgICBub2RlLnJlbW92ZUF0dHJpYnV0ZShhdHRyTmFtZSlcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IGVsc2UgaWYgKHByb3BOYW1lID09PSBcInN0eWxlXCIpIHtcbiAgICAgICAgICAgICAgICBmb3IgKHZhciBpIGluIHByZXZpb3VzVmFs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lbmd0aCA9PT0gMCkge1xuICAgICAgICByZXR1cm4ge31cbiAgICB9IGVsc2Uge1xuICAgICAgICBpbmRpY2VzLnNvcnQoYXNjZW5kaW5nKVxuICAgICAgICByZXR1cm4gcmVjdXJzZShyb290Tm9kZSwgdHJlZSwgaW5kaWNlcywgbm9kZXMsIDApXG4gICAgfVxufVxuXG5mdW5jdGlvbiByZWN1cnNlKHJvb3ROb2RlLCB0cmVlLCBpbmRpY2VzLCBub2Rlcywgcm9vdEluZGV4KSB7XG4gICAgbm9kZXMgPSBub2RlcyB8fCB7fVxuXG5cbiAgICBpZiAocm9vdE5vZGUpIHtcbiAgICAgICAgaWYgKGluZGV4SW5SYW5nZShpbmRpY2VzLCByb290SW5kZXgsIHJvb3RJbmRleCkpIHtcbiAgICAgICAgICAgIG5vZGVzW3Jvb3RJbmRleF0gPSByb290Tm9kZVxuICAgICAgICB9XG5cbiAgICAgICAgdmFyIHZDaGlsZHJlbiA9IHRyZWUuY2hpbGRyZW5cblxuICAgICAgICBpZiAodkNoaWxkcmVuKSB7XG5cbiAgICAgICAgICAgIHZhciBjaGlsZE5vZGVzID0gcm9vdE5vZGUuY2hpbGROb2Rlc1xuXG4gICAgICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IHRyZWUuY2hpbGRyZW4ubGVuZ3RoOyBpKyspIHtcbiAgICAgICAgICAgICAgICByb290SW5kZXggKz0gMVxuXG4gICAgICAgICAgICAgICAgdmFyIHZDaGlsZCA9IHZDaGlsZHJlbltpXSB8fCBub0NoaWxkXG4gICAgICAgICAgICAgICAgdmFyIG5leHRJbmRleCA9IHJvb3RJbmRleCArICh2Q2hpbGQuY291bnQgfHwgMClcblxuICAgICAgICAgICAgICAgIC8vIHNraXAgcmVjdXJzaW9uIGRvd24gdGhlIHRyZWUgaWYgdGhlcmUgYXJlIG5vIG5vZGVzIGRvd24gaGVyZVxuICAgICAgICAgICAgICAgIGlmIChpbmRleEluUmFuZ2UoaW5kaWNlcywgcm9vdEluZG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IHtcbiAgICAgICAgYXBwbHkgPSBhcHBlbmRQYXRjaChhcHBseSwgbmV3IFZQYXRjaChWUGF0Y2guV0lER0VULCBhLCBiKSlcblxuICAgICAgICBpZiAoIWlzV2lkZ2V0KGEpKSB7XG4gICAgICAgICAgICBkZXN0cm95V2lkZ2V0cyhhLCBwYXRjaCwgaW5kZXgpXG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBpZiAoYXBwbHkpIHtcbiAgICAgICAgcGF0Y2hbaW5kZXhdID0gYXBwbHlcbiAgICB9XG59XG5cbmZ1bmN0aW9uIGRpZmZQcm9wcyhhLCBiLCBob29rcykge1xuICAgIHZhciBkaWZmXG5cbiAgICBmb3IgKHZhciBhS2V5IGluIGEpIHtcbiAgICAgICAgaWYgKCEoYUtleSBpbiBiKSkge1xuICAgICAgICAgICAgZGlmZiA9IGRpZmYgfHwge31cbiAgICAgICAgICAgIGRpZmZbYUtleV0gPSB1bmRlZmluZWRcbiAgICAgICAgfVxuXG4gICAgICAgIHZhciBhVmFsdWUgPSBhW2FLZXldXG4gICAgICAgIHZhciBiVmFsdWUgPSBiW2FLZXldXG5cbiAgICAgICAgaWYgKGhvb2tzICYmIGFLZXkgaW4gaG9va3MpIHtcbiAgICAgICAgICAgIGRpZmYgPSBkaWZmIHx8IHt9XG4gICAgICAgICAgICBkaWZmW2FLZXldID0gYlZhbHVlXG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBpZiAoaXNPYmplY3QoYVZhbHVlKSAmJiBpc09iamVjdChiVmFsdWUpKSB7XG4gICAgICAgICAgICAgICAgaWYgKGdldFByb3RvdHlwZShiVmFsdWUpICE9PSBnZXRQcm90b3R5cGUoYVZhbHVlKSkge1xuICAgICAgICAgICAgICAgICAgICBkaWZmID0gZGlmZiB8fCB7fVxuICAgICAgICAgICAgICAgICAgICBkaWZmW2FLZXldID0gYlZhbHVlXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgdmFyIG9iamVjdERpZmYgPSBkaWZmUHJvcHMoYVZhbHVlLCBiVmFsdWUpXG4gICAgICAgICAgICAgICAgICAgIGlmIChvYmplY3REaWZmKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBkaWZmID0gZGlmZiB8fCB7fVxuICAgICAgICAgICAgICAgICAgICAgICAgZGlmZlthS2V5XSA9IG9iamVjdERpZmZcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSBpZiAoYVZhbHVlICE9PSBiVmFsdWUpIHtcbiAgICAgICAgICAgICAgICBkaWZmID0gZGlmZiB8fCB7fVxuICAgICAgICAgICAgICAgIGRpZmZbYUtleV0gPSBiVmFsdWVcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIGZvciAodmFyIGJLZXkgaW4gYikge1xuICAgICAgICBpZiAoIShiS2V5IGluIGEpKSB7XG4gICAgICAgICAgICBkaWZmID0gZGlmZiB8fCB7fVxuICAgICAgICAgICAgZGlmZltiS2V5XSA9IGJbYktleV1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIHJldHVybiBkaWZmXG59XG5cbmZ1bmN0aW9uIGdldFByb3RvdHlwZSh2YWx1ZSkge1xuICAgIGlmIChPYmplY3QuZ2V0UHJvdG90eXBlT2YpIHtcbiAgICAgICAgcmV0dXJuIE9iamVjdC5nZXRQcm90b3R5cGVPZih2YWx1ZSlcbiAgICB9IGVsc2UgaWYgKHZhbHVlLl9fcHJvdG9fXykge1xuICAgICAgICByZXR1cm4gdmFsdWUuX19wcm90b19fXG4gICAgfSBlbHNlIGlmICh2YWx1ZS5jb25zdHJ1Y3Rvcikge1xuICAgICAgICByZXR1cm4gdmFsdWUuY29uc3RydWN0b3IucHJvdG90eXBlXG4gICAgfVxufVxuXG5mdW5jdGlvbiBkaWZmQ2hpbGRyZW4oYSwgYiwgcGF0Y2gsIGFwcGx5LCBpbmRleCkge1xuICAgIHZhciBhQ2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ge1xuICAgICAgICBpZiAodk5vZGUuaG9va3MpIHtcbiAgICAgICAgICAgIHBhdGNoW2luZGV4XSA9IG5ldyBWUGF0Y2goVlBhdGNoLlBST1BTLCB2Tm9kZS5ob29rcywgdk5vZGUuaG9va3MpXG4gICAgICAgIH1cblxuICAgICAgICBpZiAodk5vZGUuZGVzY2VuZGFudEhvb2tzKSB7XG4gICAgICAgICAgICB2YXIgY2hpbGRyZW4gPSB2Tm9kZS5jaGlsZHJlblxuICAgICAgICAgICAgdmFyIGxlbiA9IGNoaWxkcmVuLmxlbmd0aFxuICAgICAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCBsZW47IGkrKykge1xuICAgICAgICAgICAgICAgIHZhciBjaGlsZCA9IGNoaWxkcmVuW2ldXG4gICAgICAgICAgICAgICAgaW5kZXggKz0gMVxuXG4gICAgICAgICAgICAgICAgaG9va3MoY2hpbGQsIHBhdGNoLCBpbmRleClcblxuICAgICAgICAgICAgICAgIGlmIChpc1ZOb2RlKGNoaWxkKSAmJiBjaGlsZC5jb3VudCkge1xuICAgICAgICAgICAgICAgICAgICBpbmRleCArPSBjaGlsZC5jb3VudFxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cbn1cblxuLy8gTGlzdCBkaWZmLCBuYWl2ZSBsZWZ0IHRvIHJpZ2h0IHJlb3JkZXJpbmdcbmZ1bmN0aW9uIHJlb3JkZXIoYUNoaWxkcmVuLCBiQ2hpbGRyZW4pIHtcblxuICAgIHZhciBiS2V5cyA9IGtleUluZGV4KGJDaGlsZHJlbilcblxuICAgIGlmICghYktleXMpIHtcbiAgICAgICAgcmV0dXJuIGJDaGlsZHJlblxuICAgIH1cblxuICAgIHZhciBhS2V5cyA9IGtleUluZGV4KGFDaGlsZHJlbilcblxuICAgIGlmICghYUtleXMpIHtcbiAgICAgICAgcmV0dXJuIGJDaGlsZHJlblxuICAgIH1cblxuICAgIHZhciBiTWF0Y2ggPSB7fSwgYU1hdGNoID0ge31cblxuICAgIGZvciAodmFyIGtleSBpbiBiS2V5cykge1xuICAgICAgICBiTWF0Y2hbYktleXNba2V5XV0gPSBhS2V5c1trZXldXG4gICAgfVxuXG4gICAgZm9yICh2YXIga2V5IGluIGFLZXlzKSB7XG4gICAgICAgIGFNYXRjaFthS2V5c1trZXldXSA9IGJLZXlzW2tleV1cbiAgICB9XG5cbiAgICB2YXIgYUxlbiA9IGFDaGlsZHJlbi5sZW5ndGhcbiAgICB2YXIgYkxlbiA9IGJDaGlsZHJlbi5sZW5ndGhcbiAgICB2YXIgbGVuID0gYUxlbiA+IGJMZW4gPyBhTGVuIDogYkxlblxuICAgIHZhciBzaHVmZmxlID0gW11cbiAgICB2YXIgZnJlZUluZGV4ID0gMFxuICAgIHZhciBpID0gMFxuICAgIHZhciBtb3ZlSW5kZXggPSAwXG4gICAgdmFyIG1vdmVzID0ge31cbiAgICB2YXIgcmVtb3ZlcyA9IG1vdmVzLnJlbW92ZXMgPSB7fVxuICAgIHZhciByZXZlcnNlID0gbW92ZXMucmV2ZXJzZSA9IHt9XG4gICAgdmFyIGhhc01vdmVzID0gZmFsc2VcblxuICAgIHdoaWxlIChmcmVlSW5kZXggPCBsZW4pIHtcbiAgICAgICAgdmFyIG1vdmUgPSBhTWF0Y2hbaV1cbiAgICAgICAgaWYgKG1vdmUgIT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgICAgc2h1ZmZsZVtpXSA9IGJDaGlsZHJlblttb3ZlXVxuICAgICAgICAgICAgaWYgKG1vdmUgIT09IG1vdmVJbmRleCkge1xuICAgICAgICAgICAgICAgIG1vdmVzW21vdmVdID0gbW92ZUluZGV4XG4gICAgICAgICAgICAgICAgcmV2ZXJzZVttb3ZlSW5kZXhdID0gbW92ZVxuICAgICAgICAgICAgICAgIGhhc01vdmVzID0gdHJ1ZVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgbW92ZUluZGV4KytcbiAgICAgICAgfSBlbHNlIGlmIChpIGluIGFNYXRjaCkge1xuICAgICAgICAgICAgc2h1ZmZsZVtpXSA9IHVuZGVmaW5lZFxuICAgICAgICAgICAgcmVtb3Zlc1tpXSA9IG1vdmVJbmRleCsrXG4gICAgICAgICAgICBoYXNNb3ZlcyA9IHRydWVcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHdoaWxlIChiTWF0Y2hbZnJlZUluZGV4XSAhPT0gdW5kZWZpbmVkKSB7XG4gICAgICAgICAgICAgICAgZnJlZUluZGV4KytcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKGZyZWVJbmRleCA8IGxlbikge1xuICAgICAgICAgICAgICAgIHZhciBmcmVlQ2hpbGQgPSBiQ2hpbGRyZW5bZnJlZUluZGV4XVxuICAgICAgICAgICAgICAgIGlmIChmcmVlQ2hpbGQpIHtcbiAgICAgICAgICAgICAgICAgICAgc2h1ZmZsZVtpXSA9IGZyZWVDaGlsZFxuICAgICAgICAgICAgICAgICAgICBpZiAoZnJlZUluZGV4ICE9PSBtb3ZlSW5kZXgpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGhhc01vdmVzID0gdHJ1ZVxuICAgICAgICAgICAgICAgICAgICAgICAgbW92ZXNbZnJlZUluZGV4XSA9IG1vdmVJbmRleFxuICAgICAgICAgICAgICAgICAgICAgICAgcmV2ZXJzZVttb3ZlSW5kZXhdID0gZnJlZUluZGV4XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgbW92ZUluZGV4KytcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgZnJlZUluZGV4KytcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBpKytcbiAgICB9XG5cbiAgICBpZiAoaGFzTW92ZXMpIHtcbiAgICAgICAgc2h1ZmZsZS5tb3ZlcyA9IG1vdmVzXG4gICAgfVxuXG4gICAgcmV0dXJuIHNodWZmbGVcbn1cblxuZnVuY3Rpb24ga2V5SW5kZXgoY2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2luZG93IDoge30scmVxdWlyZShcImJ1ZmZlclwiKS5CdWZmZXIsYXJndW1lbnRzWzNdLGFyZ3VtZW50c1s0XSxhcmd1bWVudHNbNV0sYXJndW1lbnRzWzZdLFwiL2Zha2VfMTk1YjUyOGUuanNcIixcIi9cIikiXX0= +}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/fake_d9a5177.js","/") +},{"1YiZ5S":19,"buffer":15,"rxmarbles/binder":24,"rxmarbles/intents/operators-menu":32,"rxmarbles/intents/sandbox":33,"rxmarbles/models/operators-menu":34,"rxmarbles/models/sandbox":37,"rxmarbles/renderer":39,"rxmarbles/views/operators-menu":44,"rxmarbles/views/sandbox":48}]},{},[93]) +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi9Vc2Vycy9hbWVkL0hvYmJ5L3J4bWFyYmxlcy9ub2RlX21vZHVsZXMvZ3VscC1icm93c2VyaWZ5L25vZGVfbW9kdWxlcy9icm93c2VyaWZ5L25vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCIvVXNlcnMvYW1lZC9Ib2JieS9yeG1hcmJsZXMvbm9kZV9tb2R1bGVzL2RvbS1kZWxlZ2F0b3IvYWRkLWV2ZW50LmpzIiwiL1VzZXJzL2FtZWQvSG9iYnkvcnhtYXJibGVzL25vZGVfbW9kdWxlcy9kb20tZGVsZWdhdG9yL2RvbS1kZWxlZ2F0b3IuanMiLCIvVXNlcnMvYW1lZC9Ib2JieS9yeG1hcmJsZXMvbm9kZV9tb2R1bGVzL2RvbS1kZWxlZ2F0b3IvaW5kZXguanMiLCIvVXNlcnMvYW1lZC9Ib2JieS9yeG1hcmJsZXMvbm9kZV9tb2R1bGVzL2RvbS1kZWxlZ2F0b3Ivbm9kZV9tb2R1bGVzL2N1aWQvZGlzdC9icm93c2VyLWN1aWQuan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HRUaWNrID0gKGZ1bmN0aW9uICgpIHtcbiAgICB2YXIgY2FuU2V0SW1tZWRpYXRlID0gdHlwZW9mIHdpbmRvdyAhPT0gJ3VuZGVmaW5lZCdcbiAgICAmJiB3aW5kb3cuc2V0SW1tZWRpYXRlO1xuICAgIHZhciBjYW5Qb3N0ID0gdHlwZW9mIHdpbmRvdyAhPT0gJ3VuZGVmaW5lZCdcbiAgICAmJiB3aW5kb3cucG9zdE1lc3NhZ2UgJiYgd2luZG93LmFkZEV2ZW50TGlzdGVuZXJcbiAgICA7XG5cbiAgICBpZiAoY2FuU2V0SW1tZWRpYXRlKSB7XG4gICAgICAgIHJldHVybiBmdW5jdGlvbiAoZikgeyByZXR1cm4gd2luZG93LnNldEltbWVkaWF0ZShmKSB9O1xuICAgIH1cblxuICAgIGlmIChjYW5Qb3N0KSB7XG4gICAgICAgIHZhciBxdWV1ZSA9IFtdO1xuICAgICAgICB3aW5kb3cuYWRkRXZlbnRMaXN0ZW5lcignbWVzc2FnZScsIGZ1bmN0aW9uIChldikge1xuICAgICAgICAgICAgdmFyIHNvdXJjZSA9IGV2LnNvdXJjZTtcbiAgICAgICAgICAgIGlmICgoc291cmNlID09PSB3aW5kb3cgfHwgc291cmNlID09PSBudWxsKSAmJiBldi5kYXRhID09PSAncHJvY2Vzcy10aWNrJykge1xuICAgICAgICAgICAgICAgIGV2LnN0b3BQcm9wYWdhdGlvbigpO1xuICAgICAgICAgICAgICAgIGlmIChxdWV1ZS5sZW5ndGggPiAwKSB7XG4gICAgICAgICAgICAgICAgICAgIHZhciBmbiA9IHF1ZXVlLnNoaWZ0KCk7XG4gICAgICAgICAgICAgICAgICAgIGZuKCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9LCB0cnVlKTtcblxuICAgICAgICByZXR1cm4gZnVuY3Rpb24gbmV4dFRpY2soZm4pIHtcbiAgICAgICAgICAgIHF1ZXVlLnB1c2goZm4pO1xuICAgICAgICAgICAgd2lu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HNsaWNlLmNhbGwob2JqZWN0KTtcclxuICAgIH1cclxuICAgIHZhciBza2lwUHJvdG8gPSBzdXBwb3J0LmVudW1Qcm90b3R5cGVzICYmIHR5cGVvZiBvYmplY3QgPT0gJ2Z1bmN0aW9uJyxcclxuICAgICAgICBza2lwRXJyb3JQcm9wcyA9IHN1cHBvcnQuZW51bUVycm9yUHJvcHMgJiYgKG9iamVjdCA9PT0gZXJyb3JQcm90byB8fCBvYmplY3QgaW5zdGFuY2VvZiBFcnJvcik7XHJcblxyXG4gICAgZm9yICh2YXIga2V5IGluIG9iamVjdCkge1xyXG4gICAgICBpZiAoIShza2lwUHJvdG8gJiYga2V5ID09ICdwcm90b3R5cGUnKSAmJlxyXG4gICAgICAgICAgIShza2lwRXJyb3JQcm9wcyAmJiAoa2V5ID09ICdtZXNzYWdlJyB8fCBrZXkgPT0gJ25hbWUnKSkpIHtcclxuICAgICAgICByZXN1bHQucHVzaChrZXkpO1xyXG4gICAgICB9XHJcbiAgICB9XHJcblxyXG4gICAgaWYgKHN1cHBvcnQubm9uRW51bVNoYWRvd3MgJiYgb2JqZWN0ICE9PSBvYmplY3RQcm90bykge1xyXG4gICAgICB2YXIgY3RvciA9IG9iamVjdC5jb25zdHJ1Y3RvcixcclxuICAgICAgICAgIGluZGV4ID0gLTEsXHJcbiAgICAgICAgICBsZW5ndGggPSBzaGFkb3dlZFByb3BzLmxlbmd0aDtcclxuXHJcbiAgICAgIGlmIChvYmplY3QgPT09IChjdG9yICYmIGN0b3IucHJvdG90eXBlKSkge1xyXG4gICAgICAgIHZhciBjbGFzc05hbWUgPSBvYmplY3QgPT09IHN0cmluZ1Byb3RvID8gc3RyaW5nQ2xhc3MgOiBvYmplY3QgPT09IGVycm9yUHJvdG8gPyBlcnJvckNsYXNzIDogdG9TdHJpbmcuY2FsbChvYmplY3QpLFxyXG4gICAgICAgICAgICBub25FbnVtID0gbm9uRW51bVByb3BzW2NsYXNzTmFtZV07XHJcbiAgICAgIH1cclxuICAgIC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sZiA9IHRoaXMsIGZhaWxlZCA9IGZhbHNlLCBkID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcblxyXG4gICAgICAgICAgICBkLnNldERpc3Bvc2FibGUodGhpcy5fc2NoZWR1bGVyLnNjaGVkdWxlUGVyaW9kaWNXaXRoU3RhdGUoc3RhdGUsIHBlcmlvZCwgZnVuY3Rpb24gKHN0YXRlMSkge1xyXG4gICAgICAgICAgICAgICAgaWYgKGZhaWxlZCkgeyByZXR1cm4gbnVsbDsgfVxyXG4gICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gYWN0aW9uKHN0YXRlMSk7XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgZmFpbGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICBpZiAoIXNlbGYuX2hhbmRsZXIoZSkpIHsgdGhyb3cgZTsgfVxyXG4gICAgICAgICAgICAgICAgICAgIGQuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBudWxsO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9KSk7XHJcblxyXG4gICAgICAgICAgICByZXR1cm4gZDtcclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICByZXR1cm4gQ2F0Y2hTY2hlZHVsZXI7XHJcbiAgICB9KFNjaGVkdWxlcikpO1xyXG5cclxuICAvKipcclxuICAgKiAgUmVwcmVzZW50cyBhIG5vdGlmaWNhdGlvbiB0byBhbiBvYnNlcnZlci5cclxuICAgKi9cclxuICB2YXIgTm90aWZpY2F0aW9uID0gUnguTm90aWZpY2F0aW9uID0gKGZ1bmN0aW9uICgpIHtcclxuICAgIGZ1bmN0aW9uIE5vdGlmaWNhdGlvbihraW5kLCBoYXNWYWx1ZSkge1xyXG4gICAgICB0aGlzLmhhc1ZhbHVlID0gaGFzVmFsd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dXJjZXMgPSB0aGlzO1xyXG4gICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICB2YXIgZTtcclxuICAgICAgdHJ5IHtcclxuICAgICAgICBlID0gc291cmNlc1skaXRlcmF0b3IkXSgpO1xyXG4gICAgICB9IGNhdGNoKGVycikge1xyXG4gICAgICAgIG9ic2VydmVyLm9uRXJyb3IoKTtcclxuICAgICAgICByZXR1cm47XHJcbiAgICAgIH1cclxuXHJcbiAgICAgIHZhciBpc0Rpc3Bvc2VkLFxyXG4gICAgICAgIHN1YnNjcmlwdGlvbiA9IG5ldyBTZXJpYWxEaXNwb3NhYmxlKCk7XHJcbiAgICAgIHZhciBjYW5jZWxhYmxlID0gaW1tZWRpYXRlU2NoZWR1bGVyLnNjaGVkdWxlUmVjdXJzaXZlKGZ1bmN0aW9uIChzZWxmKSB7XHJcbiAgICAgICAgdmFyIGN1cnJlbnRJdGVtO1xyXG4gICAgICAgIGlmIChpc0Rpc3Bvc2VkKSB7IHJldHVybjsgfVxyXG5cclxuICAgICAgICB0cnkge1xyXG4gICAgICAgICAgY3VycmVudEl0ZW0gPSBlLm5leHQoKTtcclxuICAgICAgICB9IGNhdGNoIChleCkge1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleCk7XHJcbiAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBpZiAoY3VycmVudEl0ZW0uZG9uZSkge1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgIHJldHVybjtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIC8vIENoZWNrIGlmIHByb21pc2VcclxuICAgICAgICB2YXIgY3VycmVudFZhbHVlID0gY3VycmVudEl0ZW0udmFsdWU7XHJcbiAgICAgICAgaXNQcm9taXNlKGN1cnJlbnRWYWx1ZSkgJiYgKGN1cnJlbn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b3NlZCxcclxuICAgICAgICBsYXN0RXhjZXB0aW9uLFxyXG4gICAgICAgIHN1YnNjcmlwdGlvbiA9IG5ldyBTZXJpYWxEaXNwb3NhYmxlKCk7XHJcbiAgICAgIHZhciBjYW5jZWxhYmxlID0gaW1tZWRpYXRlU2NoZWR1bGVyLnNjaGVkdWxlUmVjdXJzaXZlKGZ1bmN0aW9uIChzZWxmKSB7XHJcbiAgICAgICAgaWYgKGlzRGlzcG9zZWQpIHsgcmV0dXJuOyB9XHJcblxyXG4gICAgICAgIHZhciBjdXJyZW50SXRlbTtcclxuICAgICAgICB0cnkge1xyXG4gICAgICAgICAgY3VycmVudEl0ZW0gPSBlLm5leHQoKTtcclxuICAgICAgICB9IGNhdGNoIChleCkge1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleCk7XHJcbiAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBpZiAoY3VycmVudEl0ZW0uZG9uZSkge1xyXG4gICAgICAgICAgaWYgKGxhc3RFeGNlcHRpb24pIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihsYXN0RXhjZXB0aW9uKTtcclxuICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICAvLyBDaGVjayBpZiBwcm9taXNlXHJcbiAgICAgICAgdmFyIGN1cnJlbnRWYWx1ZSA9IGN1cnJlbnRJdGVtLnZhbHVlO1xyXG4gICAgICAgIGlzUHJvbWlzZShjdXJyZW50VmFsdWUpICYmIChjdXJyZW50VmFsdWUgPSBvYnNlcnZhYmxlRnJvbVByb21pc2UoY3VycmVudFZhbHVlKSk7XHJcblxyXG4gICAgICAgIHZhciBkID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7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blxyXG4gICAgICAgIHZhciBDaGVja2VkT2JzZXJ2ZXJQcm90b3R5cGUgPSBDaGVja2VkT2JzZXJ2ZXIucHJvdG90eXBlO1xyXG5cclxuICAgICAgICBDaGVja2VkT2JzZXJ2ZXJQcm90b3R5cGUub25OZXh0ID0gZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgICAgIHRoaXMuY2hlY2tBY2Nlc3MoKTtcclxuICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgIHRoaXMuX29ic2VydmVyLm9uTmV4dCh2YWx1ZSk7XHJcbiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgIHRocm93IGU7XHJcbiAgICAgICAgICAgIH0gZmluYWxseSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLl9zdGF0ZSA9IDA7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICBDaGVja2VkT2JzZXJ2ZXJQcm90b3R5cGUub25FcnJvciA9IGZ1bmN0aW9uIChlcnIpIHtcclxuICAgICAgICAgICAgdGhpcy5jaGVja0FjY2VzcygpO1xyXG4gICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5fb2JzZXJ2ZXIub25FcnJvcihlcnIpO1xyXG4gICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICB0aHJvdyBlO1xyXG4gICAgICAgICAgICB9IGZpbmFsbHkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5fc3RhdGUgPSAyO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgQ2hlY2tlZE9ic2VydmVyUHJvdG90eXBlLm9uQ29tcGxldGVkID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICB0aGlzLmNoZWNrQWNjZXNzKCk7XHJcbiAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICA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W5jdGlvbiAoKSB7XHJcbiAgICAgIHZhciBpc093bmVyID0gZmFsc2UsIHBhcmVudCA9IHRoaXM7XHJcbiAgICAgIGlmICghdGhpcy5oYXNGYXVsdGVkICYmIHRoaXMucXVldWUubGVuZ3RoID4gMCkge1xyXG4gICAgICAgIGlzT3duZXIgPSAhdGhpcy5pc0FjcXVpcmVkO1xyXG4gICAgICAgIHRoaXMuaXNBY3F1aXJlZCA9IHRydWU7XHJcbiAgICAgIH1cclxuICAgICAgaWYgKGlzT3duZXIpIHtcclxuICAgICAgICB0aGlzLmRpc3Bvc2FibGUuc2V0RGlzcG9zYWJsZSh0aGlzLnNjaGVkdWxlci5zY2hlZHVsZVJlY3Vyc2l2ZShmdW5jdGlvbiAoc2VsZikge1xyXG4gICAgICAgICAgdmFyIHdvcms7XHJcbiAgICAgICAgICBpZiAocGFyZW50LnF1ZXVlLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgd29yayA9IHBhcmVudC5xdWV1ZS5zaGlmdCgpO1xyXG4gICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgcGFyZW50LmlzQWNxdWlyZWQgPSBmYWxzZTtcclxuICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgd29yaygpO1xyXG4gICAgICAgICAgfSBjYXRjaCAoZXgpIHtcclxuICAgICAgICAgICAgcGFyZW50LnF1ZXVlID0gW107XHJcbiAgICAgICAgICAgIHBhcmVudC5oYXNGYXVsdGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgdGhyb3cgZXg7XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgICBzZWxmKCk7XHJcbiAgICAgICAgfSkpO1xyXG4gICAgICB9XHJcbiAgICB9O1xyXG5cclxuICAgIFNjaGVkdWxlZE9ic2VydmVyLnByb3RvdHlwZS5kaXNwb3NlID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICBfX3N1cGVy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ICAgICAgICBpZiAoaSA8IGxlbiB8fCBvYmpJc0l0ZXJhYmxlKSB7XHJcbiAgICAgICAgICB2YXIgcmVzdWx0O1xyXG4gICAgICAgICAgaWYgKG9iaklzSXRlcmFibGUpIHtcclxuICAgICAgICAgICAgdmFyIG5leHQgPSBpdC5uZXh0KCk7XHJcbiAgICAgICAgICAgIGlmIChuZXh0LmRvbmUpIHtcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgcmVzdWx0ID0gbmV4dC52YWx1ZTtcclxuICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgIHJlc3VsdCA9IGxpc3RbaV07XHJcbiAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgaWYgKG1hcEZuICYmIGlzQ2FsbGFibGUobWFwRm4pKSB7XHJcbiAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgcmVzdWx0ID0gdGhpc0FyZyA/IG1hcEZuLmNhbGwodGhpc0FyZywgcmVzdWx0LCBpKSA6IG1hcEZuKHJlc3VsdCwgaSk7XHJcbiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgfVxyXG5cclxuICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChyZXN1bHQpO1xyXG4gICAgICAgICAgaSsrO1xyXG4gICAgICAgICAgc2VsZigpO1xyXG4gICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgIH1cclxuICAgICAgfSk7XHJcbiAgICB9KTtcclxuICB9O1xyXG5cclxuICAvKipcclxuICAgKiAgQ29udmVydHMgYW4gYXJ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uXHJcbiAgICAgICAgLy8gQ2hlY2sgZm9yIHByb21pc2VzIHN1cHBvcnRcclxuICAgICAgICBpc1Byb21pc2UoeHMpICYmICh4cyA9IG9ic2VydmFibGVGcm9tUHJvbWlzZSh4cykpO1xyXG5cclxuICAgICAgICBzdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZSh4cy5zdWJzY3JpYmUob2JzZXJ2ZXIub25OZXh0LmJpbmQob2JzZXJ2ZXIpLCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICBncm91cC5yZW1vdmUoc3Vic2NyaXB0aW9uKTtcclxuICAgICAgICAgIGlmIChxLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgc3Vic2NyaWJlKHEuc2hpZnQoKSk7XHJcbiAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICBhY3RpdmVDb3VudC0tO1xyXG4gICAgICAgICAgICBpc1N0b3BwZWQgJiYgYWN0aXZlQ291bnQgPT09IDAgJiYgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgIH1cclxuICAgICAgICB9KSk7XHJcbiAgICAgIH1cclxuICAgICAgZ3JvdXAuYWRkKHNvdXJjZXMuc3Vic2NyaWJlKGZ1bmN0aW9uIChpbm5lclNvdXJjZSkge1xyXG4gICAgICAgIGlmIChhY3RpdmVDb3VudCA8IG1heENvbmN1cnJlbnRPck90aGVyKSB7XHJcbiAgICAgICAgICBhY3RpdmVDb3VudCsrO1xyXG4gICAgICAgICAgc3Vic2NyaWJlKGlubmVyU291cmNlKTtcclxuICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgcS5wdXNoKGlubmVyU291cmNlKTtcclxuICAgICAgICB9XHJcbiAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICBpc1N0b3BwZWQgPSB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HJcbiAgICAgKi9cclxuICAgIG9ic2VydmFibGVQcm90by5kaXN0aW5jdFVudGlsQ2hhbmdlZCA9IGZ1bmN0aW9uIChrZXlTZWxlY3RvciwgY29tcGFyZXIpIHtcclxuICAgICAgICB2YXIgc291cmNlID0gdGhpcztcclxuICAgICAgICBrZXlTZWxlY3RvciB8fCAoa2V5U2VsZWN0b3IgPSBpZGVudGl0eSk7XHJcbiAgICAgICAgY29tcGFyZXIgfHwgKGNvbXBhcmVyID0gZGVmYXVsdENvbXBhcmVyKTtcclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBoYXNDdXJyZW50S2V5ID0gZmFsc2UsIGN1cnJlbnRLZXk7XHJcbiAgICAgICAgICAgIHJldHVybiBzb3VyY2Uuc3Vic2NyaWJlKGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgICAgICAgdmFyIGNvbXBhcmVyRXF1YWxzID0gZmFsc2UsIGtleTtcclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAga2V5ID0ga2V5U2VsZWN0b3IodmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZXhjZXB0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGlmIChoYXNDdXJyZW50S2V5KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgY29tcGFyZXJFcXVhbHMgPSBjb21wYXJlcihjdXJyZW50S2V5LCBrZXkpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGV4Y2VwdGlvbikge1xyXG4gICAgIC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WNjdW11bGF0aW9uLCBhY2N1bXVsYXRpb24sIGhhc1ZhbHVlO1xyXG4gICAgICByZXR1cm4gc291cmNlLnN1YnNjcmliZSAoXHJcbiAgICAgICAgZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICFoYXNWYWx1ZSAmJiAoaGFzVmFsdWUgPSB0cnVlKTtcclxuICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgIGlmIChoYXNBY2N1bXVsYXRpb24pIHtcclxuICAgICAgICAgICAgICBhY2N1bXVsYXRpb24gPSBhY2N1bXVsYXRvcihhY2N1bXVsYXRpb24sIHgpO1xyXG4gICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgIGFjY3VtdWxhdGlvbiA9IGhhc1NlZWQgPyBhY2N1bXVsYXRvcihzZWVkLCB4KSA6IHg7XHJcbiAgICAgICAgICAgICAgaGFzQWNjdW11bGF0aW9uID0gdHJ1ZTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGFjY3VtdWxhdGlvbik7XHJcbiAgICAgICAgfSxcclxuICAgICAgICBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLFxyXG4gICAgICAgIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICFoYXNWYWx1ZSAmJiBoYXNTZWVkICYmIG9ic2VydmVyLm9uTmV4dChzZWVkKTtcclxuICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgfVxyXG4gICAgICApO1xyXG4gICAgfSk7XHJcbiAgfTtcclxuXHJcbiAgLyoqXHJcbiAgICogIEJ5cGFzc2VzIGEgc3BlY2lmaWVkIG51bWJlciBvZiBlbGVtZW50cyB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IHZhciBtID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCksXHJcbiAgICAgICAgcmVmQ291bnREaXNwb3NhYmxlID0gbmV3IFJlZkNvdW50RGlzcG9zYWJsZShtKSxcclxuICAgICAgICBuID0gMCxcclxuICAgICAgICBxID0gW107XHJcblxyXG4gICAgICBmdW5jdGlvbiBjcmVhdGVXaW5kb3cgKCkge1xyXG4gICAgICAgIHZhciBzID0gbmV3IFN1YmplY3QoKTtcclxuICAgICAgICBxLnB1c2gocyk7XHJcbiAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGFkZFJlZihzLCByZWZDb3VudERpc3Bvc2FibGUpKTtcclxuICAgICAgfVxyXG5cclxuICAgICAgY3JlYXRlV2luZG93KCk7XHJcblxyXG4gICAgICBtLnNldERpc3Bvc2FibGUoc291cmNlLnN1YnNjcmliZShcclxuICAgICAgICBmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IHEubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHsgcVtpXS5vbk5leHQoeCk7IH1cclxuICAgICAgICAgIHZhciBjID0gbiAtIGNvdW50ICsgMTtcclxuICAgICAgICAgIGMgPj0wICYmIGMgJSBza2lwID09PSAwICYmIHEuc2hpZnQoKS5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgKytuICUgc2tpcCA9PT0gMCAmJiBjcmVhdGVXaW5kb3coKTtcclxuICAgICAgICB9LCBcclxuICAgICAgICBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgd2hpbGUgKHEubGVuZ3RoID4gMCkgeyBxLnNoaWZ0KCkub25FcnJvcihlKTsgfVxyXG4gICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICB9LCBcclxuICAgICAgICBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICB3aGlsZSAocS5sZW5ndGggPiAwKSB7IHEuc2hpZnQoKS5vbkNvb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cclxuICAgICAgICAgIGlzUHJvbWlzZShyZXN1bHQpICYmIChyZXN1bHQgPSBvYnNlcnZhYmxlRnJvbVByb21pc2UocmVzdWx0KSk7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0KTtcclxuICAgICAgICB9LFxyXG4gICAgICAgIGZ1bmN0aW9uIChlcnIpIHtcclxuICAgICAgICAgIHZhciByZXN1bHQ7XHJcbiAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICByZXN1bHQgPSBvbkVycm9yLmNhbGwodGhpc0FyZywgZXJyKTtcclxuICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgICAgaXNQcm9taXNlKHJlc3VsdCkgJiYgKHJlc3VsdCA9IG9ic2VydmFibGVGcm9tUHJvbWlzZShyZXN1bHQpKTtcclxuICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChyZXN1bHQpO1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICB9LFxyXG4gICAgICAgIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgIHZhciByZXN1bHQ7XHJcbiAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICByZXN1bHQgPSBvbkNvbXBsZXRlZC5jYWxsKHRoaXNBcmcpO1xyXG4gICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgICBpc1Byb21pc2UocmVzdWx0KSAmJiAocmVzdWx0ID0gb2JzZXJ2YWJsZUZyb21Qcm9taXNlKHJlc3VsdCkpO1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdCk7XHJcbiA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AgICAgICAgICBkZWZhdWx0VmFsdWUgPSBudWxsO1xyXG4gICAgICAgIH1cclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBmb3VuZCA9IGZhbHNlO1xyXG4gICAgICAgICAgICByZXR1cm4gc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgZm91bmQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHgpO1xyXG4gICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoIWZvdW5kKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGRlZmF1bHRWYWx1ZSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICB9KTtcclxuICAgIH07XHJcblxyXG4gIC8vIFN3YXAgb3V0IGZvciBBcnJheS5maW5kSW5kZXhcclxuICBmdW5jdGlvbiBhcnJheUluZGV4T2ZDb21wYXJlcihhcnJheSwgaXRlbSwgY29tcGFyZXIpIHtcclxuICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSBhcnJheS5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICBpZiAoY29tcGFyZXIoYXJyYXlbaV0sIGl0ZW0pKSB7IHJldHVybiBpOyB9XHJcbiAgICB9XHJcbiAgICByZXR1cm4gLTE7XHJcbiAgfVxyXG5cclxuICBmdW5jdGlvbiBIYXNoU2V0KGNvbXBhcmVyKSB7XHJcbiAgICB0aGlzLmNvbXBhcmVyID0gY29tcGFyZXI7XHJcbiAgICB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ksIHdyaXRlciwgcmVmQ291bnREaXNwb3NhYmxlKSxcclxuICAgICAgICAgICAgICBkdXJhdGlvbkdyb3VwID0gbmV3IEdyb3VwZWRPYnNlcnZhYmxlKGtleSwgd3JpdGVyKTtcclxuICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICBkdXJhdGlvbiA9IGR1cmF0aW9uU2VsZWN0b3IoZHVyYXRpb25Hcm91cCk7XHJcbiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICBtYXAuZ2V0VmFsdWVzKCkuZm9yRWFjaChoYW5kbGVFcnJvcihlKSk7XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChncm91cCk7XHJcblxyXG4gICAgICAgICAgICB2YXIgbWQgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgZ3JvdXBEaXNwb3NhYmxlLmFkZChtZCk7XHJcblxyXG4gICAgICAgICAgICB2YXIgZXhwaXJlID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgIG1hcC5yZW1vdmUoa2V5KSAmJiB3cml0ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICBncm91cERpc3Bvc2FibGUucmVtb3ZlKG1kKTtcclxuICAgICAgICAgICAgfTtcclxuXHJcbiAgICAgICAgICAgIG1kLnNldERpc3Bvc2FibGUoZHVyYXRpb24udGFrZSgxKS5zdWJzY3JpYmUoXHJcbiAgICAgICAgICAgICAgbm9vcCxcclxuICAgICAgICAgICAgICBmdW5jdGlvbiAoZXhuKSB7XHJcbiAgICAgICAgICAgICAgICBtYXAuZ2V0VmFsdWVzKCkuZm9yRWFjaChoYW5kbGVFcnJvcihleG4pKTtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXhuKTtcclxuICAgICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAgIGV4cGlyZSlcclxuICAgICAgICAgICAgKTtcclxuICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICB2YXIgZWxlbWVudDtcclxuICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgIGVsZW1lbnQgPSBlbGVtZW50U2VsZWN0b3IoeCk7XHJcbiAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgIG1hcC5nZXRWYWx1ZXMoKS5mb3JFYWNoKGhhbmRsZUVycm9yKGUpKTtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgfVxyXG5cclxuICAgICAgICAgIHdyaXRlci5vbk5leHQoZWxlbWVudCk7XHJcbiAgICAgIH0sIGZ1bmN0aW9uIChleCkge1xyXG4gICAgICAgIG1hcC5nZXRWYWx1ZXMoKS5mb3JFYWNoKGhhbmRsZUVycm9yKGV4KSk7XHJcbiAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleCk7XHJcbiAgICAgIH0sIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICBtYXAuZ2V0VmFsdWVzKCkuZm9yRWFjaChmdW5jdGlvbiAoaXRlbSkgeyBpdGVtLm9uQ29tcGxldGVkKCk7IH0pO1xyXG4gICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgIH0pKTtcclxuXHJcbiAgICAgIHJldHVybiByZWZDb3VudERpc3Bvc2FibGU7XHJcbiAgICB9KTtcclxuICB9O1xyXG5cclxuICAvKipcclxuICAgKiAgUHJvamVjdHMgZWFjaCBlbGVtZW50IG9mIGFuIG9ic2VydmFibGUgc2VxdWVuY2UgaW50byBhIG5ldyBmb3JtIGJ5IGluY29ycG9yYXRpbmcgdGhlIGVsZW1lbnQncyBpbmRleC5cclxuICAg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UHJvdG8uZmxhdE1hcE9ic2VydmVyID0gb2JzZXJ2YWJsZVByb3RvLnNlbGVjdE1hbnlPYnNlcnZlciA9IGZ1bmN0aW9uIChvbk5leHQsIG9uRXJyb3IsIG9uQ29tcGxldGVkLCB0aGlzQXJnKSB7XHJcbiAgICB2YXIgc291cmNlID0gdGhpcztcclxuICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgdmFyIGluZGV4ID0gMDtcclxuXHJcbiAgICAgIHJldHVybiBzb3VyY2Uuc3Vic2NyaWJlKFxyXG4gICAgICAgIGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICB2YXIgcmVzdWx0O1xyXG4gICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgcmVzdWx0ID0gb25OZXh0LmNhbGwodGhpc0FyZywgeCwgaW5kZXgrKyk7XHJcbiAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgIH1cclxuICAgICAgICAgIGlzUHJvbWlzZShyZXN1bHQpICYmIChyZXN1bHQgPSBvYnNlcnZhYmxlRnJvbVByb21pc2UocmVzdWx0KSk7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0KTtcclxuICAgICAgICB9LFxyXG4gICAgICAgIGZ1bmN0aW9uIChlcnIpIHtcclxuICAgICAgICAgIHZhciByZXN1bHQ7XHJcbiAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICByZXN1bHQgPSBvbkVycm9yLmNhbGwodGhpc0FyZywgZXJyKTtcclxuICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgfVxyXG4gICAgICA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cbiAgICAgICAgICAgICAgICAgICAgc3VtOiBwcmV2LnN1bSArIGN1cixcclxuICAgICAgICAgICAgICAgICAgICBjb3VudDogcHJldi5jb3VudCArIDFcclxuICAgICAgICAgICAgICAgIH07XHJcbiAgICAgICAgICAgIH0pLmZpbmFsVmFsdWUoKS5zZWxlY3QoZnVuY3Rpb24gKHMpIHtcclxuICAgICAgICAgICAgICAgIGlmIChzLmNvdW50ID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCdUaGUgaW5wdXQgc2VxdWVuY2Ugd2FzIGVtcHR5Jyk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gcy5zdW0gLyBzLmNvdW50O1xyXG4gICAgICAgICAgICB9KTtcclxuICAgIH07XHJcblxyXG4gIGZ1bmN0aW9uIHNlcXVlbmNlRXF1YWxBcnJheShmaXJzdCwgc2Vjb25kLCBjb21wYXJlcikge1xyXG4gICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICB2YXIgY291bnQgPSAwLCBsZW4gPSBzZWNvbmQubGVuZ3RoO1xyXG4gICAgICByZXR1cm4gZmlyc3Quc3Vic2NyaWJlKGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgIHZhciBlcXVhbCA9IGZhbHNlO1xyXG4gICAgICAgIHRyeSB7XHJcbiAgICAgICAgICBjb3VudCA8IGxlbiAmJiAoZXF1YWwgPSBjb21wYXJlcih2YWx1ZSwgc2Vjb25kW2NvdW50KytdKSk7XHJcbiAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgIHJldHVybjtcclxuICAgICAgICB9XHJcbiAgICAgICAgaWYgKCFlcXVhbCkge1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25OZXh0K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gICAgIGlmIChxci5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICB2ID0gcXIuc2hpZnQoKTtcclxuICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgIGVxdWFsID0gY29tcGFyZXIodiwgeCk7XHJcbiAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgIH1cclxuICAgICAgICAgIGlmICghZXF1YWwpIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGZhbHNlKTtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgIH1cclxuICAgICAgICB9IGVsc2UgaWYgKGRvbmVyKSB7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbk5leHQoZmFsc2UpO1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgcWwucHVzaCh4KTtcclxuICAgICAgICB9XHJcbiAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICBkb25lbCA9IHRydWU7XHJcbiAgICAgICAgaWYgKHFsLmxlbmd0aCA9PT0gMCkge1xyXG4gICAgICAgICAgaWYgKHFyLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGZhbHNlKTtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgIH0gZWxzZSBpZiAoZG9uZXIpIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHRydWUpO1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgIH1cclxuICAgICAgfSk7XHJcblxyXG4gICAgICBpc1Byb21pc2Uoc2Vjb25kKSAmJiAoc2Vjb25kID0gb2JzZXJ2YWJsZUZyb21Qcm9taXNlKHNlY29uZCkpO1xyXG4gICAgICB2YXIgc3Vic2NyaXB0aW9uMiA9IHNlY29uZC5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICB2YXIgZXF1YWw7XHJcbiAgICAgICAgaWYgKHFsLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgIHZhciB2ID0gcWwuc2hpZnQoKTtcclxuICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgIGVxdWFsID0gY29tcGFyZXIodiwgeCk7XHJcbiAgICAgICAgICB9IGNhdGNoIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgICBpZiAoIWVxdWFsKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChmYWxzZSk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgfSBlbHNlIGlmIChkb25lbCkge1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGZhbHNlKTtcclxuICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgIHFyLnB1c2goeCk7XHJcbiAgICAgICAgfVxyXG4gICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgZG9uZXIgPSB0cnVlO1xyXG4gICAgICAgIGlmIChxci5sZW5ndGggPT09IDApIHtcclxuICAgICAgICAgIGlmIChxbC5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChmYWxzZSk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICB9IGVsc2UgaWYgKGRvbmVsKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh0cnVlKTtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgIH1cclxuICAgICAgICB9XHJcbiAgICAgIH0pO1xyXG4gICAgICByZXR1cm4gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUoc3Vic2NyaXB0aW9uMSwgc3Vic2NyaXB0aW9uMik7XHJcbiAgICB9KTtcclxuICB9O1xyXG5cclxuICAgIGZ1bmN0aW9uIGVsZW1lbnRBdE9yRGVmYXVsdChzb3VyY2UsIGluZGV4LCBoYXNEZWZhdWx0LCBkZWZhdWx0VmFsdWUpIHtcclxuICAgICAgICBpZiAoaW5kZXggPCAwKSB7XHJcbiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcihhcmd1bWVudE91dE9mUmFuZ2UpO1xyXG4gICAgICAgIH1cclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBpID0gaW5kZXg7XHJcbiAgICAgICAgICAgIHJldHVybiBzb3VyY2Uuc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoaSA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh4KTtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaS0tO1xyXG4gICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZX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bmV3IHJvb3QuTWFwKCk7XHJcbiAgICAgICAgcmV0dXJuIHNvdXJjZS5zdWJzY3JpYmUoXHJcbiAgICAgICAgICBmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICB2YXIga2V5O1xyXG4gICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgIGtleSA9IGtleVNlbGVjdG9yKHgpO1xyXG4gICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgIHZhciBlbGVtZW50ID0geDtcclxuICAgICAgICAgICAgaWYgKGVsZW1lbnRTZWxlY3Rvcikge1xyXG4gICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICBlbGVtZW50ID0gZWxlbWVudFNlbGVjdG9yKHgpO1xyXG4gICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICBtLnNldChrZXksIGVsZW1lbnQpO1xyXG4gICAgICAgICAgfSxcclxuICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksXHJcbiAgICAgICAgICBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChtKTtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgIH0pO1xyXG4gICAgICB9KTtcclxuICAgIH07XHJcbiAgfVxyXG5cclxuICB2YXIgZm5TdHJpbmcgPSAnZnVuY3Rpb24nO1xyXG5cclxuICBmdW5jdGlvbiB0b1RodW5rKG9iaiwgY3R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IG5ldyBvYmouY29uc3RydWN0b3IoKSxcclxuICAgICAgICAgIGZpbmlzaGVkO1xyXG5cclxuICAgICAgaWYgKCFwZW5kaW5nKSB7XHJcbiAgICAgICAgdGltZW91dFNjaGVkdWxlci5zY2hlZHVsZShmdW5jdGlvbiAoKSB7IGRvbmUobnVsbCwgcmVzdWx0cyk7IH0pO1xyXG4gICAgICAgIHJldHVybjtcclxuICAgICAgfVxyXG5cclxuICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IGtleXMubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICBydW4ob2JqW2tleXNbaV1dLCBrZXlzW2ldKTtcclxuICAgICAgfVxyXG5cclxuICAgICAgZnVuY3Rpb24gcnVuKGZuLCBrZXkpIHtcclxuICAgICAgICBpZiAoZmluaXNoZWQpIHsgcmV0dXJuOyB9XHJcbiAgICAgICAgdHJ5IHtcclxuICAgICAgICAgIGZuID0gdG9UaHVuayhmbiwgY3R4KTtcclxuXHJcbiAgICAgICAgICBpZiAodHlwZW9mIGZuICE9PSBmblN0cmluZykge1xyXG4gICAgICAgICAgICByZXN1bHRzW2tleV0gPSBmbjtcclxuICAgICAgICAgICAgcmV0dXJuIC0tcGVuZGluZyB8fCBkb25lKG51bGwsIHJlc3VsdHMpO1xyXG4gICAgICAgICAgfVxyXG5cclxuICAgICAgICAgIGZuLmNhbGwoY3R4LCBmdW5jdGlvbihlcnIsIHJlcyl7XHJcbiAgICAgICAgICAgIGlmIChmaW5pc2hlZCkgeyByZXR1cm47IH1cclxuXHJcbiAgICAgICAgICAgIGlmIChlcnIpIHtcclxuICAgICAgICAgICAgICBmaW5pc2hlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgcmV0dXJuIGRvbmUoZXJyKTtcclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgcmVzdWx0c1trZXldID0gcmVzO1xyXG4gICAgICAgICAgICAtLXBlbmRpbmcgfHwgZG9uZShudWxsLCByZXN1bHRzKTtcclxuICAgICAgICAgIH0pO1xyXG4gICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgIGZpbmlzaGVkID0gdHJ1ZTtcclxuICAgICAgICAgIGRvbmUoZSk7XHJcbiAgICAgICAgfVxyXG4gICAgICB9XHJcbiAgICB9XHJcbiAgfVxyXG5cclxuICBmdW5jdGlvbiBvYnNlcnZhYmxlVG9UaGluayhvYnNlcnZhYmxlKSB7XHJcbiAgICByZXR1cm4gZnVuY3Rpb24gKGZuKSB7XHJcbiAgICAgIHZhciB2YWx1ZSwgaGFzVmFsdWUgPSBmYWxzZTtcclxuICAgICAgb2JzZXJ2YWJsZS5zdWJzY3JpYmUoXHJcbiAgICAgICAgZnVuY3Rpb24gKHYpIHtcclxuICAgICAgICAgIHZhbHVlID0gdjtcclxuICAgICAgICAgIGhhc1ZhbHVlID0gdHJ1ZTtcclxuICAgICAgICB9LFxyXG4gICAgICAgIGZuLFxyXG4gICAgICAgIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgIGhhc1ZhbHVlICYmIGZuKG51bGwsIHZhbHVlKTtcclxuICAgICAgICB9KTtcclxuICAgIH1cclxuICB9XHJcblxyXG4gIGZ1bmN0aW9uIHByb21pc2VUb1RodW5rKHByb21pc2UpIHtcclxuICAgIHJldHVybiBmdW5jdGlvbihmbil7XHJcbiAgICAgIHByb21pc2UudGhlbihmdW5jdGlvbihyZXMpIHtcclxuICAgICAgICBmbihudWxsLCByZXMpO1xyXG4gICAgICB9LCBmbik7XHJcbiAgICB9XHJcbiAgfVxyXG5cclxuICBmdW5jdGlvbiBpc09ic2VydmFibGUob2JqKSB7XHJcbiAgICByZXR1cm4gb2JqICYmIG9iai5wcm90b3R5cGUuc3Vic2NyaWJlID09PSBmblN0cmluZztcclxuICB9XHJcblxyXG4gIGZ1bmN0aW9uIGlzR2VuZXJhdG9yRnVuY3Rpb24ob2JqKSB7XHJcbiAgICByZXR1cm4gb2JqICYmIG9iai5jb25zdHJ1Y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gICBsZW4gPSBhcmdzLmxlbmd0aCxcclxuICAgICAgICAgIGhhc0NhbGxiYWNrID0gbGVuICYmIHR5cGVvZiBhcmdzW2xlbiAtIDFdID09PSBmblN0cmluZztcclxuXHJcbiAgICAgICAgZG9uZSA9IGhhc0NhbGxiYWNrID8gYXJncy5wb3AoKSA6IGVycm9yO1xyXG4gICAgICAgIGdlbiA9IGZuLmFwcGx5KHRoaXMsIGFyZ3MpO1xyXG4gICAgICB9IGVsc2Uge1xyXG4gICAgICAgIGRvbmUgPSBkb25lIHx8IGVycm9yO1xyXG4gICAgICB9XHJcblxyXG4gICAgICBuZXh0KCk7XHJcblxyXG4gICAgICBmdW5jdGlvbiBleGl0KGVyciwgcmVzKSB7XHJcbiAgICAgICAgdGltZW91dFNjaGVkdWxlci5zY2hlZHVsZShkb25lLmJpbmQoY3R4LCBlcnIsIHJlcykpO1xyXG4gICAgICB9XHJcblxyXG4gICAgICBmdW5jdGlvbiBuZXh0KGVyciwgcmVzKSB7XHJcbiAgICAgICAgdmFyIHJldDtcclxuXHJcbiAgICAgICAgLy8gbXVsdGlwbGUgYXJnc1xyXG4gICAgICAgIGlmIChhcmd1bWVudHMubGVuZ3RoID4gMikgcmVzID0gc2xpY2UuY2FsbChhcmd1bWVudHMsIDEpO1xyXG5cclxuICAgICAgICBpZiAoZXJyKSB7XHJcbiAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICByZXQgPSBnZW4udGhyb3coZXJyKTtcclxuICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgcmV0dXJuIGV4aXQoZSk7XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBpZiAoIWVycikge1xyXG4gICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgcmV0ID0gZ2VuLm5leHQocmVzKTtcclxuICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgcmV0dXJuIGV4aXQoZSk7XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBpZiAocmV0LmRvbmUpICB7XHJcbiAgICAgICAgICByZXR1cm4gZXhpdChudWxsLCByZXQudmFsdWUpO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgcmV0LnZhbHVlID0gdG9UaHVuayhyZXQudmFsdWUsIGN0eCk7XHJcblxyXG4gICAgICAgIGlmICh0eXBlb2YgcmV0LnZhbHVlID09PSBmblN0cmluZykge1xyXG4gICAgICAgICAgdmFyIGNhbGxlZCA9IGZhbHNlO1xyXG4gICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgcmV0LnZhbHVlLmNhbGwoY3R4LCBmdW5jdGlvbigpe1xyXG4gICAgICAgICAgICAgIGlmIChjYWxsZWQpIHtcclxuICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgIGNhbGxlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgbmV4dC5hcHBseShjdHgsIGFyZ3VtZW50cyk7XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICB0aW1lb3V0U2NoZWR1bGVyLnNjaGVkdWxlKGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICBpZiAoY2FsbGVkKSB7XHJcbiAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICBjYWxsZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgIG5leHQuY2FsbChjdHgsIGUpO1xyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICAgIH1cclxuICAgICAgICAgIHJldHVybjtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIC8vIE5vdCBzdXBwb3J0ZWRcclxuICAgICAgICBuZXh0KG5ldyBUeXBlRXJyb3IoJ1J4LnNwYXduIG9ubHkgc3VwcG9yd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gICAgfVxyXG4gICAgICBpZiAoZW1iZXIpIHtcclxuICAgICAgICByZXR1cm4gZnJvbUV2ZW50UGF0dGVybihcclxuICAgICAgICAgIGZ1bmN0aW9uIChoKSB7IEVtYmVyLmFkZExpc3RlbmVyKGVsZW1lbnQsIGV2ZW50TmFtZSwgaCk7IH0sXHJcbiAgICAgICAgICBmdW5jdGlvbiAoaCkgeyBFbWJlci5yZW1vdmVMaXN0ZW5lcihlbGVtZW50LCBldmVudE5hbWUsIGgpOyB9LFxyXG4gICAgICAgICAgc2VsZWN0b3IpO1xyXG4gICAgICB9XHJcbiAgICAgIGlmIChqcSkge1xyXG4gICAgICAgIHZhciAkZWxlbSA9IGpxKGVsZW1lbnQpO1xyXG4gICAgICAgIHJldHVybiBmcm9tRXZlbnRQYXR0ZXJuKFxyXG4gICAgICAgICAgZnVuY3Rpb24gKGgpIHsgJGVsZW0ub24oZXZlbnROYW1lLCBoKTsgfSxcclxuICAgICAgICAgIGZ1bmN0aW9uIChoKSB7ICRlbGVtLm9mZihldmVudE5hbWUsIGgpOyB9LFxyXG4gICAgICAgICAgc2VsZWN0b3IpO1xyXG4gICAgICB9XHJcbiAgICB9XHJcbiAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgIHJldHVybiBjcmVhdGVFdmVudExpc3RlbmVyKFxyXG4gICAgICAgIGVsZW1lbnQsXHJcbiAgICAgICAgZXZlbnROYW1lLFxyXG4gICAgICAgIGZ1bmN0aW9uIGhhbmRsZXIgKGUpIHtcclxuICAgICAgICAgIHZhciByZXN1bHRzID0gZTtcclxuXHJcbiAgICAgICAgICBpZiAoc2VsZWN0b3IpIHtcclxuICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICByZXN1bHRzID0gc2VsZWN0b3IoYXJndW1lbnRzKTtcclxuICAgICAgICAgICAgfSBjYXRjaCAoZXJyKSB7XHJcbiAgICAgICAgICAgICAgb2J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gaXNEb25lID0gZmFsc2UsXHJcbiAgICAgICAgdmFsdWVzID0gbmV3IEFycmF5KG4pO1xyXG5cclxuICAgICAgZnVuY3Rpb24gbmV4dCh4LCBpKSB7XHJcbiAgICAgICAgdmFsdWVzW2ldID0geFxyXG4gICAgICAgIHZhciByZXM7XHJcbiAgICAgICAgaGFzVmFsdWVbaV0gPSB0cnVlO1xyXG4gICAgICAgIGlmIChoYXNWYWx1ZUFsbCB8fCAoaGFzVmFsdWVBbGwgPSBoYXNWYWx1ZS5ldmVyeShpZGVudGl0eSkpKSB7XHJcbiAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICByZXMgPSByZXN1bHRTZWxlY3Rvci5hcHBseShudWxsLCB2YWx1ZXMpO1xyXG4gICAgICAgICAgfSBjYXRjaCAoZXgpIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleCk7XHJcbiAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgIH1cclxuICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChyZXMpO1xyXG4gICAgICAgIH0gZWxzZSBpZiAoaXNEb25lKSB7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgIH1cclxuICAgICAgfVxyXG5cclxuICAgICAgcmV0dXJuIG5ldyBDb21wb3NpdGVEaXNwb3NhYmxlKFxyXG4gICAgICAgIHNvdXJjZS5zdWJzY3JpYmUoXHJcbiAgICAgICAgICBmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICBuZXh0KHgsIDApO1xyXG4gICAgICAgICAgfSxcclxuICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksXHJcbiAgICAgICAgICBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIGlzRG9uZSA9IHRydWU7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICB9KSxcclxuICAgICAgICBzdWJqZWN0LnN1YnNjcmliZShcclxuICAgICAgICAgIGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgIG5leHQoeCwgMSk7XHJcbiAgICAgICAgICB9LFxyXG4gICAgICAgICAgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSlcclxuICAgICAgICApO1xyXG4gICAgfSk7XHJcbiAgfVxyXG5cclxuICB2YXIgUGF1c2FibGVCdWZmZXJlZE9ic2VydmFibGUgPSAoZnVuY3Rpb24gKF9zdXBlcikge1xyXG5cclxuICAgIGluaGVyaXRzKFBhdXNhYmxlQnVmZmVyZWRPYnNlcnZhYmxlLCBfc3VwZXIpO1xyXG5cclxuICAgIGZ1bmN0aW9uIHN1YnNjcmliZShvYnNlcnZlcikge1xyXG4gICAgICB2YXIgcSA9IFtdLCBwcmV2aW91c1Nob3VsZEZpcmU7XHJcblxyXG4gICAgICB2YXIgc3Vic2NyaXB0aW9uID1cclxuICAgICAgICBjb21iaW5lTGF0ZXN0U291cmNlKFxyXG4gICAgICAgICAgdGhpcy5zb3VyY2UsXHJcbiAgICAgICAgICB0aGlzLnBhdXNlci5kaXN0aW5jdFVudGlsQ2hhbmdlZCgpLnN0YXJ0V2l0aChmYWxzZSksXHJcbiAgICAgICAgICBmdW5jdGlvbiAoZGF0YSwgc2hvdWxkRmlyZSkge1xyXG4gICAgICAgICAgICByZXR1cm4geyBkYXRhOiBkYXRhLCBzaG91bGRGaXJlOiBzaG91bGRGaXJlIH07XHJcbiAgICAgICAgICB9KVxyXG4gICAgICAgICAgLnN1YnNjcmliZShcclxuICAgICAgICAgICAgZnVuY3Rpb24gKHJlc3VsdHMpIHtcclxuICAgICAgICAgICAgICBpZiAocHJldmlvdXNTaG91bGRGaXJlICE9PSB1bmRlZmluZWQgJiYgcmVzdWx0cy5zaG91bGRGaXJlICE9IHByZXZpb3VzU2hvdWxkRmlyZSkge1xyXG4gICAgICAgICAgICAgICAgcHJldmlvdXNTaG91bGRGaXJlID0gcmVzdWx0cy5zaG91bGRGaXJlO1xyXG4gICAgICAgICAgICAgICAgLy8gY2hhbmdlIGluIHNob3VsZEZpcmVcclxuICAgICAgICAgICAgICAgIGlmIChyZXN1bHRzLnNob3VsZEZpcmUpIHtcclxuICAgICAgICAgICAgICAgICAgd2hpbGUgKHEubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChxLnNoaWZ0KCkpO1xyXG4gICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgIHByZXZpb3VzU2hvdWxkRmlyZSA9IHJlc3VsdHMuc2hvdWxkRmlyZTtcclxuICAgICAgICAgICAgICAgIC8vIG5ldyBkYXRhXHJcbiAgICAgICAgICAgICAgICBpZiAocmVzdWx0cy5zaG91bGRGaXJlKSB7XHJcbiAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChyZXN1bHRzLmRhdGEpO1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgcS5wdXNoKHJlc3VsdHMuZGF0YSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICBmdW5jdGlvbiAoZXJyKSB7XHJcbiAgICAgICAgICAgICAgLy8gRW1wdHkgYnVmZmVyIGJlZm9yZSBzZW5kaW5nIGVycm9yXHJcbiAgICAgICAgICAgICAgd2hpbGUgKHEubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHEuc2hpZnQoKSk7XHJcbiAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXJyKTtcclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgZnVuY3Rpb24gKCkge1xy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gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICBvbkVycm9yOiBmdW5jdGlvbiAoZXJyb3IpIHtcclxuICAgICAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgICAgIHRoaXMuaGFzRmFpbGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIHRoaXMuZXJyb3IgPSBlcnJvcjtcclxuXHJcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuZW5hYmxlUXVldWUgfHwgdGhpcy5xdWV1ZS5sZW5ndGggPT09IDApIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLnN1YmplY3Qub25FcnJvcihlcnJvcik7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIG9uTmV4dDogZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICB2YXIgaGFzUmVxdWVzdGVkID0gZmFsc2U7XHJcblxyXG4gICAgICAgICAgICAgICAgaWYgKHRoaXMucmVxdWVzdGVkQ291bnQgPT09IDApIHtcclxuICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5lbmFibGVRdWV1ZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLnF1ZXVlLnB1c2godmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMucmVxdWVzdGVkQ291bnQgIT09IC0xKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLnJlcXVlc3RlZENvdW50LS0gPT09IDApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuZGlzcG9zZUN1cnJlbnRSZXF1ZXN0KCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgaGFzUmVxdWVzdGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICBpZiAoaGFzUmVxdWVzdGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5zdWJqZWN0Lm9uTmV4dCh2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIF9wcm9jZXNzUmVxdWVzdDogZnVuY3Rpb24gKG51bWJlck9mSXRlbXMpIHtcclxuICAgICAgICAgICAgICAgIGlmICh0aGlzLmVuYWJsZVF1ZXVlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgLy9jb25zb2xlLmxvZygncXVldWUgbGVuZ3RoJywgdGhpcy5xdWV1ZS5sZW5ndGgpO1xyXG5cclxuICAgICAgICAgICAgICAgICAgICB3aGlsZSAodGhpcy5xdWV1ZS5sZW5ndGggPj0gbnVtYmVyT2ZJdGVtcyAmJiBudW1iZXJPZkl0ZW1zID4gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAvL2NvbnNvbGUubG9nKCdudW1iZXIgb2YgaXRlbXMnLCBudW1iZXJPZkl0ZW1zKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5zdWJqZWN0Lm9uTmV4dCh0aGlzLnF1ZXVlLnNoaWZ0KCkpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBudW1iZXJPZkl0ZW1zLS07XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5xdWV1ZS5sZW5ndGggIT09IDApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHsgbnVtYmVyT2ZJdGVtczogbnVtYmVyT2ZJdGVtcywgcmV0dXJuVmFsdWU6IHRydWUgfTtcclxuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4geyBudW1iZXJPZkl0ZW1zOiBudW1iZXJPZkl0ZW1zLCByZXR1cm5WYWx1ZTogZmFsc2UgfTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuaGFzRmFpbGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5zdWJqZWN0Lm9uRXJyb3IodGhpcy5lcnJvcik7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5jb250cm9sbGVkRGlzcG9zYWJsZS5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5jb250cm9sbGVkRGlzcG9zYWJsZSA9IGRpc3Bvc2FibGVFbXB0eTtcclxuICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAodGhpcy5oYXNDb21wbGV0ZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLnN1YmplY3Qub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmNvbnRyb2xsZWREaXNwb3NhYmxlLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmNvbnRyb2xsZWREaXNwb3NhYmxlID0gZGlzcG9zYWJsZUVtcHR5O1xyXG4gICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgIHJldHVybiB7IG51bWJlck9mSXRlbXM6IG51bWJlck9mSXRlbXMsIHJldHVyblZhbHVlOiBmYWxzZSB9O1xyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICByZXF1ZXN0OiBmdW5jdGlvbiAobnVtYmVyKSB7XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmRpc3Bvc2VDdXJyZW50UmVxdWVzdCgpO1xyXG4gICAgICAgICAgICAgICAgdmFyIHNlbGYgPSB0aGlzLFxyXG4gICAgICAgICAgICAgICAgICAgIHIgPSB0aGlzLl9wcm9jZXNzUmVxdWVzdChudW1iZXIpO1xyXG5cclxuICAgICAgICAgICAgICAgIG51bWJlciA9IHIubnVtYmVyT2ZJdGVtcztcclxuICAgICAgICAgICAgICAgIGlmICghci5yZXR1cm5WYWx1ZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMucmVxdWVzdGVkQ291bnQgPSBudW1iZXI7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5yZXF1ZXN0ZWREaXNwb3NhYmxlID0gZGlzcG9zYWJsZUNyZWF0ZShmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHNlbGYucmVxdWVzdGVkQ291bnQgPSAwO1xyXG4gICAgICAgICAgICAgICAgICAgIH0pO1xyXG5cclxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gdGhpcy5yZXF1ZXN0ZWREaXNwb3NhYmxlXHJcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBkaXNwb3NhYmxlRW1wdHk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIGRpc3Bvc2VDdXJyZW50UmVxdWVzdDogZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5yZXF1ZXN0ZWREaXNwb3NhYmxlLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgICAgIHRoaXMucmVxdWVzdGVkRGlzcG9zYWJsZSA9IGRpc3Bvc2FibGVFbXB0eTtcclxuICAgICAgICAgICAgfSxcclxuXHJcbiAgICAgICAgICAgIGRpc3Bvc2U6IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAg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W2luZGV4M10ua2V5LCBrZXkpKSB7XHJcbiAgICAgICAgICAgIGlmIChpbmRleDIgPCAwKSB7XHJcbiAgICAgICAgICAgICAgdGhpcy5idWNrZXRzW2luZGV4MV0gPSB0aGlzLmVudHJpZXNbaW5kZXgzXS5uZXh0O1xyXG4gICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgIHRoaXMuZW50cmllc1tpbmRleDJdLm5leHQgPSB0aGlzLmVudHJpZXNbaW5kZXgzXS5uZXh0O1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIHRoaXMuZW50cmllc1tpbmRleDNdLmhhc2hDb2RlID0gLTE7XHJcbiAgICAgICAgICAgIHRoaXMuZW50cmllc1tpbmRleDNdLm5leHQgPSB0aGlzLmZyZWVMaXN0O1xyXG4gICAgICAgICAgICB0aGlzLmVudHJpZXNbaW5kZXgzXS5rZXkgPSBudWxsO1xyXG4gICAgICAgICAgICB0aGlzLmVudHJpZXNbaW5kZXgzXS52YWx1ZSA9IG51bGw7XHJcbiAgICAgICAgICAgIHRoaXMuZnJlZUxpc3QgPSBpbmRleDM7XHJcbiAgICAgICAgICAgICsrdGhpcy5mcmVlQ291bnQ7XHJcbiAgICAgICAgICAgIHJldHVybiB0cnVlO1xyXG4gICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgaW5kZXgyID0gaW5kZXgzO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgIH1cclxuICAgICAgfVxyXG4gICAgICByZXR1cm4gZmFsc2U7XHJcbiAgICB9O1xyXG5cclxuICAgIGRpY3Rpb25hcnlQcm90by5jbGVhciA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgdmFyIGluZGV4LCBsZW47XHJcbiAgICAgIGlmICh0aGlzLnNpemUgPD0gMCkgeyByZXR1cm47IH1cclxuICAgICAgZm9yIChpbmRleCA9IDAsIGxlbiA9IHRoaXMuYnVja2V0cy5sZW5ndGg7IGluZGV4IDwgbGVuOyArK2luZGV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AgICAgZ3JvdXAuYWRkKGxlZnQuc3Vic2NyaWJlKFxyXG4gICAgICAgIGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgdmFyIGlkID0gbGVmdElkKys7XHJcbiAgICAgICAgICB2YXIgbWQgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuXHJcbiAgICAgICAgICBsZWZ0TWFwLmFkZChpZCwgdmFsdWUpO1xyXG4gICAgICAgICAgZ3JvdXAuYWRkKG1kKTtcclxuXHJcbiAgICAgICAgICB2YXIgZXhwaXJlID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICBsZWZ0TWFwLnJlbW92ZShpZCkgJiYgbGVmdE1hcC5jb3VudCgpID09PSAwICYmIGxlZnREb25lICYmIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIGdyb3VwLnJlbW92ZShtZCk7XHJcbiAgICAgICAgICB9O1xyXG5cclxuICAgICAgICAgIHZhciBkdXJhdGlvbjtcclxuICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgIGR1cmF0aW9uID0gbGVmdER1cmF0aW9uU2VsZWN0b3IodmFsdWUpO1xyXG4gICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgbWQuc2V0RGlzcG9zYWJsZShkdXJhdGlvbi50YWtlKDEpLnN1YnNjcmliZShub29wLCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBleHBpcmUpKTtcclxuXHJcbiAgICAgICAgICByaWdodE1hcC5nZXRWYWx1ZXMoKS5mb3JFYWNoKGZ1bmN0aW9uICh2KSB7XHJcbiAgICAgICAgICAgIHZhciByZXN1bHQ7XHJcbiAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0U2VsZWN0b3IodmFsdWUsIHYpO1xyXG4gICAgICAgICAgICB9IGNhdGNoIChleG4pIHtcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4bik7XHJcbiAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0KTtcclxuICAgICAgICAgIH0pO1xyXG4gICAgICAgIH0sXHJcbiAgICAgICAgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSxcclxuICAgICAgICBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICBsZWZ0RG9uZSA9IHRydWU7XHJcbiAgICAgICAgICAocmlnaHREb25lIHx8IGxlZnRNYXAuY291bnQoKSA9PT0gMCkgJiYgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICB9KVxyXG4gICAgICApO1xyXG5cclxuICAgICAgZ3JvdXAuYWRkKHJpZ2h0LnN1YnNjcmliZShcclxuICAgICAgICBmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgIHZhciBpZCA9IHJpZ2h0SWQrKztcclxuICAgICAgICAgIHZhciBtZCA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG5cclxuICAgICAgICAgIHJpZ2h0TWFwLmFkZChpZCwgdmFsdWUpO1xyXG4gICAgICAgICAgZ3JvdXAuYWRkKG1kKTtcclxuXHJcbiAgICAgICAgICB2YXIgZXhwaXJlID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICByaWdodE1hcC5yZW1vdmUoaWQpICYmIHJpZ2h0TWFwLmNvdW50KCkgPT09IDAgJiYgcmlnaHREb25lICYmIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIGdyb3VwLnJlbW92ZShtZCk7XHJcbiAgICAgICAgICB9O1xyXG5cclxuICAgICAgICAgIHZhciBkdXJhdGlvbjtcclxuICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgIGR1cmF0aW9uID0gcmlnaHREdXJhdGlvblNlbGVjdG9yKHZhbHVlKTtcclxuICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgfVxyXG5cclxuICAgICAgICAgIG1kLnNldERpc3Bvc2FibGUoZHVyYXRpb24udGFrZSgxKS5zdWJzY3JpYmUobm9vcCwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZXhwaXJlKSk7XHJcblxyXG4gICAgICAgICAgbGVmdE1hcC5nZXRWYWx1ZXMoKS5mb3JFYWNoKGZ1bmN0aW9uICh2KSB7XHJcbiAgICAgICAgICAgIHZhciByZXN1bHQ7XHJcbiAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0U2VsZWN0b3IodiwgdmFsdWUpO1xyXG4gICAgICAgICAgICB9IGNhdGNoKGV4bikge1xyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXhuKTtcclxuICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChyZXN1bHQpO1xyXG4gICAgICAgICAgfSk7XHJcbiAgICAgICAgfSxcclxuICAgICAgICBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLFxyXG4gICAgICAgIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgIHJpZ2h0RG9uZSA9IHRydWU7XHJcbiAgICAgICAgICAobGVmdERvbmUgfHwgcmlnaHRNYXAuY291bnQoKSA9PT0gMCkgJiYgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICB9KVxyXG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vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICBncm91cC5yZW1vdmUobWQpO1xyXG4gICAgICAgICAgfTtcclxuXHJcbiAgICAgICAgICB2YXIgZHVyYXRpb247XHJcbiAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICBkdXJhdGlvbiA9IGxlZnREdXJhdGlvblNlbGVjdG9yKHZhbHVlKTtcclxuICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgbGVmdE1hcC5nZXRWYWx1ZXMoKS5mb3JFYWNoKGhhbmRsZUVycm9yKGUpKTtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgfVxyXG5cclxuICAgICAgICAgIG1kLnNldERpc3Bvc2FibGUoZHVyYXRpb24udGFrZSgxKS5zdWJzY3JpYmUoXHJcbiAgICAgICAgICAgIG5vb3AsXHJcbiAgICAgICAgICAgIGZ1bmN0aW9uIChlKSB7XHJcbiAgICAgICAgICAgICAgbGVmdE1hcC5nZXRWYWx1ZXMoKS5mb3JFYWNoKGhhbmRsZUVycm9yKGUpKTtcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICBleHBpcmUpXHJcbiAgICAgICAgICApO1xyXG4gICAgICAgIH0sXHJcbiAgICAgICAgZnVuY3Rpb24gKGUpIHtcclxuICAgICAgICAgIGxlZnRNYXAuZ2V0VmFsdWVzKCkuZm9yRWFjaChoYW5kbGVFcnJvcihlKSk7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgIH0sXHJcbiAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQuYmluZChvYnNlcnZlcikpXHJcbiAgICAgICk7XHJcblxyXG4gICAgICBncm91cC5hZGQocmlnaHQuc3Vic2NyaWJlKFxyXG4gICAgICAgIGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgdmFyIGlkID0gcmlnaHRJZCsrO1xyXG4gICAgICAgICAgcmlnaHRNYXAuYWRkKGlkLCB2YWx1ZSk7XHJcblxyXG4gICAgICAgICAgdmFyIG1kID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgICBncm91cC5hZGQobWQpO1xyXG5cclxuICAgICAgICAgIHZhciBleHBpcmUgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIHJpZ2h0TWFwLnJlbW92ZShpZCk7XHJcbiAgICAgICAgICAgIGdyb3VwLnJlbW92ZShtZCk7XHJcbiAgICAgICAgICB9O1xyXG5cclxuICAgICAgICAgIHZhciBkdXJhdGlvbjtcclxuICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgIGR1cmF0aW9uID0gcmlnaHREdXJhdGlvblNlbGVjdG9yKHZhbHVlKTtcclxuICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgbGVmdE1hcC5nZXRWYWx1ZXMoKS5mb3JFYWNoKGhhbmRsZUVycm9yKGUpKTtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgICAgbWQuc2V0RGlzcG9zYWJsZShkdXJhdGlvbi50YWtlKDEpLnN1YnNjcmliZShcclxuICAgICAgICAgICAgbm9vcCxcclxuICAgICAgICAgICAgZnVuY3Rpb24gKGUpIHtcclxuICAgICAgICAgICAgICBsZWZ0TWFwLmdldFZhbHVlcygpLmZvckVhY2goaGFuZGxlRXJyb3IoZSkpO1xyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIGV4cGlyZSlcclxuICAgICAgICAgICk7XHJcblxyXG4gICAgICAgIC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TtcclxuXHJcbiAgICAgIHZhciBlbnN1cmVBY3RpdmUgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgdmFyIGlzT3duZXIgPSBmYWxzZTtcclxuICAgICAgICBpZiAocS5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICAgIGlzT3duZXIgPSAhaXNBY3F1aXJlZDtcclxuICAgICAgICAgICAgaXNBY3F1aXJlZCA9IHRydWU7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGlmIChpc093bmVyKSB7XHJcbiAgICAgICAgICBtLnNldERpc3Bvc2FibGUoc2NoZWR1bGVyLnNjaGVkdWxlUmVjdXJzaXZlKGZ1bmN0aW9uIChzZWxmKSB7XHJcbiAgICAgICAgICAgIHZhciB3b3JrO1xyXG4gICAgICAgICAgICBpZiAocS5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICAgICAgd29yayA9IHEuc2hpZnQoKTtcclxuICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICBpc0FjcXVpcmVkID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIHZhciBtMSA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgICBkLmFkZChtMSk7XHJcbiAgICAgICAgICAgIG0xLnNldERpc3Bvc2FibGUod29yay5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgICAgdmFyIHJlc3VsdCA9IG51bGw7XHJcbiAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgIHJlc3VsdCA9IHNlbGVjdG9yKHgpO1xyXG4gICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgIHEucHVzaChyZXN1bHQpO1xyXG4gICAgICAgICAgICAgIGFjdGl2ZUNvdW50Kys7XHJcbiAgICAgICAgICAgICAgZW5zdXJlQWN0aXZlKCk7XHJcbiAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICBkLnJlbW92ZShtMSk7XHJcbiAgICAgICAgICAgICAgYWN0aXZlQ291bnQtLTtcclxuICAgICAgICAgICAgICBpZiAoYWN0aXZlQ291bnQgPT09IDApIHtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICAgIHNlbGYoKTtcclxuICAgICAgICAgIH0pKTtcclxuICAgICAgICB9XHJcbiAgICAgIH07XHJcblxyXG4gICAgICBxLnB1c2goc291cmNlKTtcclxuICAgICAgYWN0aXZlQ291bnQrKztcclxuICAgICAgZW5zdXJlQWN0aXZlKCk7XHJcbiAgICAgIHJldHVybiBkO1xyXG4gICAgfSk7XHJcbiAgfTtcclxuXHJcbiAgIC8qKlxyXG4gICAqICBSdW5zIGFsbCBvYnNlcnZhYmxlIHNlcXVlbmNlcyBpbiBwYXJhbGxlbCBhbmQgY29sbGVjdCB0aGVpciBsYXN0IGVsZW1lbnRzLlxyXG4gICAqXHJcbiAgICogQGV4YW1wbGVcclxuICAgKiAgMSAtIHJlcyA9IFJ4Lk9ic2VydmFibGUuZm9ya0pvaW4oW29iczEsIG9iczJdKTtcclxuICAgKiAgMSAtIHJlcyA9IFJ4Lk9ic2VydmFibGUuZm9ya0pvaW4ob2JzMSwgb2JzMiwgLi4uKTtcclxuICAgKiBAcmV0dXJucyB7T2JzZXJ2YWJsZX0gQW4gb2JzZXJ2YWJsZSBzZXF1ZW5jZSB3aXRoIGFuIGFycmF5IGN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ICBmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgICBpZiAoIWZpbmlzaGVkKSB7XHJcbiAgICAgICAgICAgICAgICBoYXNSZXN1bHRzW2ldID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIHJlc3VsdHNbaV0gPSB2YWx1ZTtcclxuICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIGZ1bmN0aW9uIChlKSB7XHJcbiAgICAgICAgICAgICAgZmluaXNoZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgIHN1YnNjcmliZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICBncm91cC5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICBpZiAoIWZpbmlzaGVkKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoIWhhc1Jlc3VsdHNbaV0pIHtcclxuICAgICAgICAgICAgICAgICAgICBzdWJzY3JpYmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaGFzQ29tcGxldGVkW2ldID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIGZvciAodmFyIGl4ID0gMDsgaXggPCBjb3VudDsgaXgrKykge1xyXG4gICAgICAgICAgICAgICAgICBpZiAoIWhhc0NvbXBsZXRlZFtpeF0pIHsgcmV0dXJuOyB9XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBmaW5pc2hlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICBzdWJzY3JpYmVyLm9uTmV4dChyZXN1bHRzKTtcclxuICAgICAgICAgICAgICAgIHN1YnNjcmliZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0pKTtc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0gcmVzdWx0U2VsZWN0b3IobGFzdExlZnQsIGxhc3RSaWdodCk7XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChyZXN1bHQpO1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgIH0pXHJcbiAgICAgICk7XHJcblxyXG4gICAgICByaWdodFN1YnNjcmlwdGlvbi5zZXREaXNwb3NhYmxlKFxyXG4gICAgICAgIHNlY29uZC5zdWJzY3JpYmUoZnVuY3Rpb24gKHJpZ2h0KSB7XHJcbiAgICAgICAgICBoYXNSaWdodCA9IHRydWU7XHJcbiAgICAgICAgICBsYXN0UmlnaHQgPSByaWdodDtcclxuICAgICAgICB9LCBmdW5jdGlvbiAoZXJyKSB7XHJcbiAgICAgICAgICBsZWZ0U3Vic2NyaXB0aW9uLmRpc3Bvc2UoKTtcclxuICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXJyKTtcclxuICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICByaWdodFN0b3BwZWQgPSB0cnVlO1xyXG4gICAgICAgICAgaWYgKGxlZnRTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgIGlmICghaGFzTGVmdCkge1xyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH0gZWxzZSBpZiAoIWhhc1JpZ2h0KSB7XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICB2YXIgcmVzdWx0O1xyXG4gICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICByZXN1bHQgPSByZXN1bHRTZWxlY3RvcihsYXN0TGVmdCwgbGFzdFJpZ2h0KTtcclxuICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0KTtcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgfSlcclxuICAgICAgKTtcclxuXHJcbiAgICAgIHJldHVybiBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZShsZWZ0U3Vic2NyaXB0aW9uLCByaWdodFN1YnNjcmlwdGlvbik7XHJcbiAgICB9KTtcclxuICB9O1xyXG5cclxuICAvKipcclxuICAgKiBDb21vbmFkaWMgYmluZCBvcGVyYXRvci5cclxuICAgKiBAcGFyYW0ge0Z1bmN0aW9ufSBzZWxlY3RvciBBIHRyYW5zZm9ybSBmdW5jdGlvbiB0byBhcHBseSB0byBlYWNoIGVsZW1lbnQuXHJcbiAgICogQHBhcmFtIHtPYmplY3R9IHNjaGVkdWxlciBTY2hlZHVsZXIgdXNlZCB0byBleGVjdXRlIHRoZSBvcGVyYXRpb24uIElmIG5vdCBzcGVjaWZpZWQsIGRlZmF1bHRzIHRvIHRoZSBJbW1lZGlhdGVTY2hlZHVsZXIuXHJcbiAgICogQHJldHVybnMge09ic2VydmFibGV9IEFuIG9ic2VydmFibGUgc2VxdWVuY2Ugd2hpY2ggcmVzdWx0cyBmcm9tIHRoZSBjb21vbmFkaWMgYmluZCBvcGVyYXRpb24uXHJcbiAgICovXHJcbiAgb2JzZXJ2YWJsZVByb3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ZCA9PT0gJ0UnKSB7XHJcbiAgICAgICAgICBxID0gW107XHJcbiAgICAgICAgICBxLnB1c2gobm90aWZpY2F0aW9uKTtcclxuICAgICAgICAgIGV4Y2VwdGlvbiA9IG5vdGlmaWNhdGlvbi52YWx1ZS5leGNlcHRpb247XHJcbiAgICAgICAgICBzaG91bGRSdW4gPSAhcnVubmluZztcclxuICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgcS5wdXNoKHsgdmFsdWU6IG5vdGlmaWNhdGlvbi52YWx1ZSwgdGltZXN0YW1wOiBub3RpZmljYXRpb24udGltZXN0YW1wICsgZHVlVGltZSB9KTtcclxuICAgICAgICAgIHNob3VsZFJ1biA9ICFhY3RpdmU7XHJcbiAgICAgICAgICBhY3RpdmUgPSB0cnVlO1xyXG4gICAgICAgIH1cclxuICAgICAgICBpZiAoc2hvdWxkUnVuKSB7XHJcbiAgICAgICAgICBpZiAoZXhjZXB0aW9uICE9PSBudWxsKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgIGQgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgY2FuY2VsYWJsZS5zZXREaXNwb3NhYmxlKGQpO1xyXG4gICAgICAgICAgICBkLnNldERpc3Bvc2FibGUoc2NoZWR1bGVyLnNjaGVkdWxlUmVjdXJzaXZlV2l0aFJlbGF0aXZlKGR1ZVRpbWUsIGZ1bmN0aW9uIChzZWxmKSB7XHJcbiAgICAgICAgICAgICAgdmFyIGUsIHJlY3Vyc2VEdWVUaW1lLCByZXN1bHQsIHNob3VsZFJlY3Vyc2U7XHJcbiAgICAgICAgICAgICAgaWYgKGV4Y2VwdGlvbiAhPT0gbnVsbCkge1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICBydW5uaW5nID0gdHJ1ZTtcclxuICAgICAgICAgICAgICBkbyB7XHJcbiAgICAgICAgICAgICAgICByZXN1bHQgPSBudWxsO1xyXG4gICAgICAgICAgICAgICAgaWYgKHEubGVuZ3RoID4gMCAmJiBxWzBdLnRpbWVzdGFtcCAtIHNjaGVkdWxlci5ub3coKSA8PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgIHJlc3VsdCA9IHEuc2hpZnQoKS52YWx1ZTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGlmIChyZXN1bHQgIT09IG51bGwpIHtcclxuICAgICAgICAgICAgICAgICAgcmVzdWx0LmFjY2VwdChvYnNlcnZlcik7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgfSB3aGlsZSAocmVzdWx0ICE9PSBudWxsKTtcclxuICAgICAgICAgICAgICBzaG91bGRSZWN1cnNlID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgcmVjdXJzZUR1ZVRpbWUgPSAwO1xyXG4gICAgICAgICAgICAgIGlmIChxLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgICAgIHNob3VsZFJlY3Vyc2UgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgcmVjdXJzZUR1ZVRpbWUgPSBNYXRoLm1heCgwLCBxWzBdLnRpbWVzdGFtcCAtIHNjaGVkdWxlci5ub3coKSk7XHJcbiAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgIGFjdGl2ZSA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICBlID0gZXhjZXB0aW9uO1xyXG4gICAgICAgICAgICAgIHJ1bm5pbmcgPSBmYWxzZTtcclxuICAgICAgICAgICAgICBpZiAoZSAhPT0gbnVsbCkge1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICB9IGVsc2UgaWYgKHNob3VsZFJ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uID0gc291cmNlLnN1YnNjcmliZShcclxuICAgICAgICBmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgaGFzdmFsdWUgPSB0cnVlO1xyXG4gICAgICAgICAgdmFsdWUgPSB4O1xyXG4gICAgICAgICAgaWQrKztcclxuICAgICAgICAgIHZhciBjdXJyZW50SWQgPSBpZCxcclxuICAgICAgICAgICAgZCA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgY2FuY2VsYWJsZS5zZXREaXNwb3NhYmxlKGQpO1xyXG4gICAgICAgICAgZC5zZXREaXNwb3NhYmxlKHNjaGVkdWxlci5zY2hlZHVsZVdpdGhSZWxhdGl2ZShkdWVUaW1lLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIGhhc3ZhbHVlICYmIGlkID09PSBjdXJyZW50SWQgJiYgb2JzZXJ2ZXIub25OZXh0KHZhbHVlKTtcclxuICAgICAgICAgICAgaGFzdmFsdWUgPSBmYWxzZTtcclxuICAgICAgICAgIH0pKTtcclxuICAgICAgICB9LFxyXG4gICAgICAgIGZ1bmN0aW9uIChlKSB7XHJcbiAgICAgICAgICBjYW5jZWxhYmxlLmRpc3Bvc2UoKTtcclxuICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICBoYXN2YWx1ZSA9IGZhbHNlO1xyXG4gICAgICAgICAgaWQrKztcclxuICAgICAgICB9LFxyXG4gICAgICAgIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgIGNhbmNlbGFibGUuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgaGFzdmFsdWUgJiYgb2JzZXJ2ZXIub25OZXh0KHZhbHVlKTtcclxuICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICBoYXN2YWx1ZSA9IGZhbHNlO1xyXG4gICAgICAgICAgaWQrKztcclxuICAgICAgICB9KTtcclxuICAgICAgcmV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cbiAgICAgIG9ic2VydmVyLm9uTmV4dChhZGRSZWYocywgcmVmQ291bnREaXNwb3NhYmxlKSk7XHJcbiAgICAgIGNyZWF0ZVRpbWVyKDApO1xyXG5cclxuICAgICAgZ3JvdXBEaXNwb3NhYmxlLmFkZChzb3VyY2Uuc3Vic2NyaWJlKFxyXG4gICAgICAgIGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICB2YXIgbmV3SWQgPSAwLCBuZXdXaW5kb3cgPSBmYWxzZTtcclxuICAgICAgICAgIHMub25OZXh0KHgpO1xyXG4gICAgICAgICAgaWYgKCsrbiA9PT0gY291bnQpIHtcclxuICAgICAgICAgICAgbmV3V2luZG93ID0gdHJ1ZTtcclxuICAgICAgICAgICAgbiA9IDA7XHJcbiAgICAgICAgICAgIG5ld0lkID0gKyt3aW5kb3dJZDtcclxuICAgICAgICAgICAgcy5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICBzID0gbmV3IFN1YmplY3QoKTtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGFkZFJlZihzLCByZWZDb3VudERpc3Bvc2FibGUpKTtcclxuICAgICAgICAgIH1cclxuICAgICAgICAgIG5ld1dpbmRvdyAmJiBjcmVhdGVUaW1lcihuZXdJZCk7XHJcbiAgICAgICAgfSwgXHJcbiAgICAgICAgZnVuY3Rpb24gKGUpIHtcclxuICAgICAgICAgIHMub25FcnJvcihlKTtcclxuICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgcy5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICB9XHJcbiAgICAgICkpO1xyXG4gICAgICByZXR1cm4gcmVmQ291bnREaXNwb3NhYmxlO1xyXG4gICAgfSk7XHJcbiAgfTtcclxuXHJcbiAgICAvKipcclxuICAgICAqICBQcm9q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Aoc2NoZWR1bGVyID0gdGltZW91dFNjaGVkdWxlcik7XHJcbiAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgIHZhciBmaXJzdCA9IHRydWUsXHJcbiAgICAgICAgaGFzUmVzdWx0ID0gZmFsc2UsXHJcbiAgICAgICAgcmVzdWx0LFxyXG4gICAgICAgIHN0YXRlID0gaW5pdGlhbFN0YXRlLFxyXG4gICAgICAgIHRpbWU7XHJcbiAgICAgIHJldHVybiBzY2hlZHVsZXIuc2NoZWR1bGVSZWN1cnNpdmVXaXRoQWJzb2x1dGUoc2NoZWR1bGVyLm5vdygpLCBmdW5jdGlvbiAoc2VsZikge1xyXG4gICAgICAgIGhhc1Jlc3VsdCAmJiBvYnNlcnZlci5vbk5leHQocmVzdWx0KTtcclxuXHJcbiAgICAgICAgdHJ5IHtcclxuICAgICAgICAgIGlmIChmaXJzdCkge1xyXG4gICAgICAgICAgICBmaXJzdCA9IGZhbHNlO1xyXG4gICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgc3RhdGUgPSBpdGVyYXRlKHN0YXRlKTtcclxuICAgICAgICAgIH1cclxuICAgICAgICAgIGhhc1Jlc3VsdCA9IGNvbmRpdGlvbihzdGF0ZSk7XHJcbiAgICAgICAgICBpZiAoaGFzUmVzdWx0KSB7XHJcbiAgICAgICAgICAgIHJlc3VsdCA9IHJlc3VsdFNlbGVjdG9yKHN0YXRlKTtcclxuICAgICAgICAgICAgdGltZSA9IHRpbWVTZWxlY3RvcihzdGF0ZSk7XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgIHJldHVybjtcclxuICAgICAgICB9XHJcbiAgICAgICAgaWYgKGhhc1Jlc3VsdCkge1xyXG4gICAgICAgICAgc2VsZih0aW1lKTtcclxuICAgICAgICB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c3ViRGVsYXkgPSBzdWJzY3JpcHRpb25EZWxheTtcclxuICAgICAgICAgICAgc2VsZWN0b3IgPSBkZWxheUR1cmF0aW9uU2VsZWN0b3I7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIGRlbGF5cyA9IG5ldyBDb21wb3NpdGVEaXNwb3NhYmxlKCksIGF0RW5kID0gZmFsc2UsIGRvbmUgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoYXRFbmQgJiYgZGVsYXlzLmxlbmd0aCA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sIHN1YnNjcmlwdGlvbiA9IG5ldyBTZXJpYWxEaXNwb3NhYmxlKCksIHN0YXJ0ID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgc3Vic2NyaXB0aW9uLnNldERpc3Bvc2FibGUoc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBkZWxheTtcclxuICAgICAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkZWxheSA9IHNlbGVjdG9yKHgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGVycm9yKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXJyb3IpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIHZhciBkID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgZGVsYXlzLmFkZChkKTtcclxuICAgICAgICAgICAgICAgICAgICBkLnNldERpc3Bvc2FibGUoZGVsYXkuc3Vic2NyaWJlKGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkZWxheXMucmVtb3ZlKGQpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkb25lKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGRlbGF5cy5yZW1vdmUoZCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGRvbmUoKTtcclxuICAgICAgICAgICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgYXRFbmQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIHN1YnNjcmlwdGlvbi5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgZG9uZSgpO1xyXG4gICAgICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICB9O1xyXG5cclxuICAgICAgICAgICAgaWYgKCFzdWJEZWxheSkge1xyXG4gICAgICAgICAgICAgICAgc3RhcnQoKTtcclxuICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgIHN1YnNjcmlwdGlvbi5zZXREaXNwb3NhYmxlKHN1YkRlbGF5LnN1YnNjcmliZShmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgc3RhcnQo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YXIgbXlJZCA9IGlkO1xyXG5cclxuICAgICAgICAgIGZ1bmN0aW9uIHRpbWVyV2lucyAoKSB7XHJcbiAgICAgICAgICAgIHJldHVybiBpZCA9PT0gbXlJZDtcclxuICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICB2YXIgZCA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgdGltZXIuc2V0RGlzcG9zYWJsZShkKTtcclxuICAgICAgICAgIGQuc2V0RGlzcG9zYWJsZSh0aW1lb3V0LnN1YnNjcmliZShmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIHRpbWVyV2lucygpICYmIHN1YnNjcmlwdGlvbi5zZXREaXNwb3NhYmxlKG90aGVyLnN1YnNjcmliZShvYnNlcnZlcikpO1xyXG4gICAgICAgICAgICBkLmRpc3Bvc2UoKTtcclxuICAgICAgICAgIH0sIGZ1bmN0aW9uIChlKSB7XHJcbiAgICAgICAgICAgIHRpbWVyV2lucygpICYmIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIHRpbWVyV2lucygpICYmIHN1YnNjcmlwdGlvbi5zZXREaXNwb3NhYmxlKG90aGVyLnN1YnNjcmliZShvYnNlcnZlcikpO1xyXG4gICAgICAgICAgfSkpO1xyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIHNldFRpbWVyKGZpcnN0VGltZW91dCk7XHJcblxyXG4gICAgICAgIGZ1bmN0aW9uIG9ic2VydmVyV2lucygpIHtcclxuICAgICAgICAgIHZhciByZXMgPSAhc3dpdGNoZWQ7XHJcbiAgICAgICAgICBpZiAocmVzKSB7IGlkKys7IH1cclxuICAgICAgICAgIHJldHVybiByZXM7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBvcmlnaW5hbC5zZXREaXNwb3NhYmxlKHNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rp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m5lclN1YnNjcmlwdGlvbi5zZXREaXNwb3NhYmxlKGlubmVyU291cmNlLnN1YnNjcmliZShcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQuYmluZChvYnNlcnZlciksXHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSxcclxuICAgICAgICAgICAgICBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBnLnJlbW92ZShpbm5lclN1YnNjcmlwdGlvbik7XHJcbiAgICAgICAgICAgICAgICBoYXNDdXJyZW50ID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgICBpZiAoaXNTdG9wcGVkICYmIGcubGVuZ3RoID09PSAxKSB7XHJcbiAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgIH1cclxuICAgICAgICB9LFxyXG4gICAgICAgIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksXHJcbiAgICAgICAgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgaXNTdG9wcGVkID0gdHJ1ZTtcclxuICAgICAgICAgIGlmICghaGFzQ3VycmVudCAmJiBnLmxlbmd0aCA9PT0gMSkge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgIH0pKTtcclxuXHJcbiAgICAgIHJldHVybiBnO1xyXG4gICAgfSk7XHJcbiAgfTtcclxuXHJcbiAgLypcclxuICAgKiBQZXJmb3JtcyBhIGV4Y2x1c2l2ZSBtYXAgd2FpdGluZyBmb3IgdGhlIGZpcnN0IHRvIGZpbmlzaCBiZWZvcmUgc3Vic2NyaWJpbmcgdG8gYW5vdGhlciBvYnNlcnZhYmxlLlxyXG4gICAqIE9ic2VydmFibGVzIHRoYXQgY29tZSBpbiBiZXR3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nJlbnQpIHtcclxuICAgICAgICAgICAgaGFzQ3VycmVudCA9IHRydWU7XHJcblxyXG4gICAgICAgICAgICBpbm5lclN1YnNjcmlwdGlvbiA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgICBnLmFkZChpbm5lclN1YnNjcmlwdGlvbik7XHJcblxyXG4gICAgICAgICAgICBpc1Byb21pc2UoaW5uZXJTb3VyY2UpICYmIChpbm5lclNvdXJjZSA9IG9ic2VydmFibGVGcm9tUHJvbWlzZShpbm5lclNvdXJjZSkpO1xyXG5cclxuICAgICAgICAgICAgaW5uZXJTdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZShpbm5lclNvdXJjZS5zdWJzY3JpYmUoXHJcbiAgICAgICAgICAgICAgZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgIHZhciByZXN1bHQ7XHJcbiAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICByZXN1bHQgPSBzZWxlY3Rvci5jYWxsKHRoaXNBcmcsIHgsIGluZGV4KyssIGlubmVyU291cmNlKTtcclxuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChyZXN1bHQpO1xyXG4gICAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSxcclxuICAgICAgICAgICAgICBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBnLnJlbW92ZShpbm5lclN1YnNjcmlwdGlvbik7XHJcbiAgICAgICAgICAgICAgICBoYXNDdXJyZW50ID0gZmFsc2U7XHJcblxyXG4gICAgICAgICA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cclxuXHJcbiAgICAgICAgdmFyIEF1dG9EZXRhY2hPYnNlcnZlclByb3RvdHlwZSA9IEF1dG9EZXRhY2hPYnNlcnZlci5wcm90b3R5cGU7XHJcblxyXG4gICAgICAgIEF1dG9EZXRhY2hPYnNlcnZlclByb3RvdHlwZS5uZXh0ID0gZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgICAgIHZhciBub0Vycm9yID0gZmFsc2U7XHJcbiAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLm9ic2VydmVyLm9uTmV4dCh2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICBub0Vycm9yID0gdHJ1ZTtcclxuICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgdGhyb3cgZTtcclxuICAgICAgICAgICAgfSBmaW5hbGx5IHtcclxuICAgICAgICAgICAgICAgIGlmICghbm9FcnJvcikge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgQXV0b0RldGFjaE9ic2VydmVyUHJvdG90eXBlLmVycm9yID0gZnVuY3Rpb24gKGV4bikge1xyXG4gICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5vYnNlcnZlci5vbkVycm9yKGV4bik7XHJcbiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgIHRocm93IGU7XHJcbiAgICAgICAgICAgIH0gZmluYWxseSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIEF1dG9EZXRhY2hPYnNlcnZlclByb3RvdHlwZS5jb21wbGV0ZWQgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICA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hcyB3ZWxsIGFzIGFuIG9ic2VydmVyLlxyXG4gICAgICogIEVhY2ggbm90aWZpY2F0aW9uIGlzIGJyb2FkY2FzdGVkIHRvIGFsbCBzdWJzY3JpYmVkIG9ic2VydmVycy5cclxuICAgICAqL1xyXG4gICAgdmFyIFN1YmplY3QgPSBSeC5TdWJqZWN0ID0gKGZ1bmN0aW9uIChfc3VwZXIpIHtcclxuICAgICAgICBmdW5jdGlvbiBzdWJzY3JpYmUob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICBpZiAoIXRoaXMuaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLm9ic2VydmVycy5wdXNoKG9ic2VydmVyKTtcclxuICAgICAgICAgICAgICAgIHJldHVybiBuZXcgSW5uZXJTdWJzY3JpcHRpb24odGhpcywgb2JzZXJ2ZXIpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIGlmICh0aGlzLmV4Y2VwdGlvbikge1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcih0aGlzLmV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gZGlzcG9zYWJsZUVtcHR5O1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIHJldHVybiBkaXNwb3NhYmxlRW1wdHk7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBpbmhlcml0cyhTdWJqZWN0LCBfc3VwZXIpO1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBDcmVhdGVzIGEgc3ViamVjdC5cclxuICAgICAgICAgKiBAY29uc3RydWN0b3JcclxuICAgICAgICAgKi9cclxuICAgICAgICBmdW5jdGlvbiBTdWJqZWN0KCkge1xyXG4gICAgICAgICAgICBfc3VwZXIuY2FsbCh0aGlzLCBzdWJzY3JpYmUpO1xyXG4gICAgICAgICAgICB0aGlzLmlzRGlzcG9zZWQgPSBmYWxzZSxcclxuICAgICAgICAgICAgdGhpcy5pc1N0b3BwZWQgPSBmYWxzZSxcclxuICAgICAgICAgICAgdGhpcy5vYnNlcnZlcnMgPSBbXTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGFkZFByb3BlcnRpZXMoU3ViamVjdC5wcm90b3R5cGUsIE9ic2VydmVyLCB7XHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBJbmRpY2F0ZXMgd2hldGhlciB0aGUgc3ViamVjdCBoYXMgb2JzZXJ2ZXJzIHN1YnNjcmliZWQgdG8gaXQuXHJcbiAgICAgICAgICAgICAqIEByZXR1cm5zIHtCb29sZWFufSBJbmRpY2F0ZXMgd2hldGhlciB0aGUgc3ViamVjdCBoYXMgb2JzZXJ2ZXJzIHN1YnNjcmliZWQgdG8gaXQuXHJcbiAgICAgICAgICAgICAqL1xyXG4gICAgICAgICAgICBoYXNPYnNlcnZlcnM6IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLm9ic2VydmVycy5sZW5ndGggPiAwO1xyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogTm90aWZpZXMgYWxsIHN1YnNjcmliZWQgb2JzZXJ2ZXJzIGFib3V0IHRoZSBlbmQgb2YgdGhlIHNlcXVlbmNlLlxyXG4gICAgICAgICAgICAgKi9cclxuICAgICAgICAgICAgb25Db21wbGV0ZWQ6IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgb3MgPSB0aGlzLm9ic2VydmVycy5zbGljZSgwKTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmlzU3RvcHBlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IG9zLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9zW2ldLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgICAgICB0aGlzLm9ic2VydmVycyA9IFtdO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogTm90aWZpZXMgYWxsIHN1YnNjcmliZWQgb2JzZXJ2ZXJzIGFib3V0IHRoZSBleGNlcHRpb24uXHJcbiAgICAgICAgICAgICAqIEBwYXJhbSB7TWl4ZWR9IGVycm9yIFRoZSBleGNlcHRpb24gdG8gc2VuZCB0byBhbGwgb2JzZXJ2ZXJzLlxyXG4gICAgICAgICAgICAgKi9cclxuICAgICAgICAgICAgb25FcnJvcjogZnVuY3Rpb24gKGV4Y2VwdGlvbikge1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmlzU3RvcHBlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBvcyA9IHRoaXMub2JzZXJ2ZXJzLnNsaWNlKDApO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuaXNTdG9wcGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmV4Y2VwdGlvbiA9IGV4Y2VwdGlvbjtcclxuICAgICAgICAgICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gb3MubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb3NbaV0ub25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5vYnNlcnZlcnMgPSBbXTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgLyoqXHJcbiAgICAgICAgICAgICAqIE5vdGlmaWVzIGFsbCBzdWJzY3JpYmVkIG9ic2VydmVycyBhYm91dCB0aGUgYXJyaXZhbCBvZiB0aGUgc3BlY2lmaWVkIGVsZW1lbnQgaW4gdGhlIHNlcXVlbmNlLlxyXG4gICAgICAgICAgICAgKiBAcGFyYW0ge01peGVkfSB2YWx1ZSBUaGUgdmFsdWUgdG8gc2VuZCB0byBhbGwgb2JzZXJ2ZXJzLlxyXG4gICAgICAgICAgICAgKi9cclxuICAgICAgICAgICAgb25OZXh0OiBmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgb3MgPSB0aGlzLm9ic2VydmVycy5zbGljZSgwKTtcclxuICAgICAgICAgICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gb3MubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb3NbaV0ub25OZXh0KHZhbHVlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBVbnN1YnNjcmliZSBhbGwgb2JzZXJ2ZXJzIGFuZCByZWxlYXNlIHJlc291cmNlcy5cclxuICAgICAgICAgICAgICovXHJcbiAgICAgICAgICAgIGRpc3Bvc2U6IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgIC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1YnNjcmliZWQgb2JzZXJ2ZXJzIGFib3V0IHRoZSBlbmQgb2YgdGhlIHNlcXVlbmNlLCBhbHNvIGNhdXNpbmcgdGhlIGxhc3QgcmVjZWl2ZWQgdmFsdWUgdG8gYmUgc2VudCBvdXQgKGlmIGFueSkuXHJcbiAgICAgICAqL1xyXG4gICAgICBvbkNvbXBsZXRlZDogZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIHZhciBvLCBpLCBsZW47XHJcbiAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgIHRoaXMuaXNTdG9wcGVkID0gdHJ1ZTtcclxuICAgICAgICAgIHZhciBvcyA9IHRoaXMub2JzZXJ2ZXJzLnNsaWNlKDApLFxyXG4gICAgICAgICAgICB2ID0gdGhpcy52YWx1ZSxcclxuICAgICAgICAgICAgaHYgPSB0aGlzLmhhc1ZhbHVlO1xyXG5cclxuICAgICAgICAgIGlmIChodikge1xyXG4gICAgICAgICAgICBmb3IgKGkgPSAwLCBsZW4gPSBvcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgIG8gPSBvc1tpXTtcclxuICAgICAgICAgICAgICBvLm9uTmV4dCh2KTtcclxuICAgICAgICAgICAgICBvLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgIGZvciAoaSA9IDAsIGxlbiA9IG9zLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgb3NbaV0ub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgfVxyXG5cclxuICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzID0gW107XHJcbiAgICAgICAgfVxyXG4gICAgICB9LFxyXG4gICAgICAvKipcclxuICAgICAgICogTm90aWZ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uICAgICAgICAgICAgdGhpcy5zdWJzY3JpcHRpb25zID0gW107XHJcbiAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzID0gW107XHJcbiAgICAgICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSB0aGlzLm1lc3NhZ2VzLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICBtZXNzYWdlID0gdGhpcy5tZXNzYWdlc1tpXTtcclxuICAgICAgICAgICAgICAgIG5vdGlmaWNhdGlvbiA9IG1lc3NhZ2UudmFsdWU7XHJcbiAgICAgICAgICAgICAgICAoZnVuY3Rpb24gKGlubmVyTm90aWZpY2F0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgc2NoZWR1bGVyLnNjaGVkdWxlQWJzb2x1dGVXaXRoU3RhdGUobnVsbCwgbWVzc2FnZS50aW1lLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHZhciBvYnMgPSBvYnNlcnZhYmxlLm9ic2VydmVycy5zbGljZSgwKTtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGZvciAodmFyIGogPSAwLCBqTGVuID0gb2JzLmxlbmd0aDsgaiA8IGpMZW47IGorKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaW5uZXJOb3RpZmljYXRpb24uYWNjZXB0KG9ic1tqXSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGRpc3Bvc2FibGVFbXB0eTtcclxuICAgICAgICAgICAgICAgICAgICB9KTtcclxuICAgICAgICAgICAgICAgIH0pKG5vdGlmaWNhdGlvbik7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIHJldHVybiBIb3RPYnNlcnZhYmxlO1xyXG4gICAgfSkoT2JzZXJ2YWJsZSk7XHJcblxyXG4gICAgLyoqIEBwcml2YXRlICovX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Zyb21FdmVudChkb2N1bWVudCwgXCJtb3VzZXVwXCIpO1xuXG5mdW5jdGlvbiBvYnNlcnZlKHZpZXcpIHtcbiAgcmVwbGljYXRlKHZpZXcubWFyYmxlTW91c2VEb3duJCwgaW5wdXRNYXJibGVNb3VzZURvd24kKTtcbiAgcmVwbGljYXRlKHZpZXcuY29tcGxldGlvbk1vdXNlRG93biQsIGlucHV0Q29tcGxldGlvbk1vdXNlRG93biQpO1xufVxuXG5mdW5jdGlvbiBtYWtlRGVsdGFEcmFnJChtb3VzZURvd24kLCByZXN1bHRGdW5jdGlvbikge1xuICByZXR1cm4gbW91c2VEb3duJFxuICAgIC5tYXAoZnVuY3Rpb24oZXZlbnQpIHtcbiAgICAgIHZhciB0YXJnZXQgPSBldmVudC5jdXJyZW50VGFyZ2V0O1xuICAgICAgcmV0dXJuIG1vdXNlTW92ZSRcbiAgICAgICAgLm1hcChmdW5jdGlvbihldikge1xuICAgICAgICAgIGV2LnN0b3BQcm9wYWdhdGlvbigpO1xuICAgICAgICAgIGV2LnByZXZlbnREZWZhdWx0KCk7XG4gICAgICAgICAgcmV0dXJuIGV2LnBhZ2VYO1xuICAgICAgICB9KVxuICAgICAgICAud2luZG93V2l0aENvdW50KDIsMSlcbiAgICAgICAgLmZsYXRNYXAoZnVuY3Rpb24ocmVzdWx0KSB7IHJldHVybiByZXN1bHQudG9BcnJheSgpOyB9KVxuICAgICAgICAubWFwKGZ1bmN0aW9uKGFycmF5KSB7XG4gICAgICAgICAgdmFyIGR4ID0gYXJyYXlbMV0gLSBhcnJheVswXTsgLy8gdGhlIGRyYWcgZHggaW4gcGl4ZWxzXG4gICAgICAgICAgdmFyIHB4VG9QZXJjZW50YWdlO1xuICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICBpZiAodGFyZ2V0ICYmIHRhcmdldC5wYXJlbnRFbGVtZW50ICYmIHRhcmdldC5wYXJlbnRFbGVtZW50LmNsaWVudFdpZHRoKSB7XG4gICAgICAgICAgICAgIHB4V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B9XG4gICAgfVxufVxuXG5mdW5jdGlvbiByZW1vdmVQcm9wZXJ0eShub2RlLCBwcm9wcywgcHJldmlvdXMsIHByb3BOYW1lKSB7XG4gICAgaWYgKHByZXZpb3VzKSB7XG4gICAgICAgIHZhciBwcmV2aW91c1ZhbHVlID0gcHJldmlvdXNbcHJvcE5hbWVdXG5cbiAgICAgICAgaWYgKCFpc0hvb2socHJldmlvdXNWYWx1ZSkpIHtcbiAgICAgICAgICAgIGlmIChwcm9wTmFtZSA9PT0gXCJhdHRyaWJ1dGVzXCIpIHtcbiAgICAgICAgICAgICAgICBmb3IgKHZhciBhdHRyTmFtZSBpbiBwcmV2aW91c1ZhbHVlKSB7XG4gICAgICAgICAgICAgICAgICAgIG5vZGUucmVtb3ZlQXR0cmlidXRlKGF0dHJOYW1lKVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSBpZiAocHJvcE5hbWUgPT09IFwic3R5bGVcIikge1xuICAgICAgICAgICAgICAgIGZvciAodmFyIGkgaW4gcHJldmlvdXNWYWx1ZSkge1xuICAgICAgICAgICAgICAgICAgICBub2RlLnN0eWxlW2ldID0gXCJcIlxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIHByZXZpb3VzVmFsdWUgPT09IFwic3RyaW5nXCIpIHtcbiAgICAgICAgICAgICAgICBub2RlW3Byb3BOYW1lXSA9IFwiXCJcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgbm9kZVtwcm9wTmFtZV0gPSBudWxsXG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG59XG5cbmZ1bmN0aW9uIHBhdGNoT2JqZWN0KG5vZGUsIHByb3BzLCBwcmV2aW91cywgcHJvcE5hbWUsIHByb3BWYWx1ZSkge1xuICAgIHZhciBwcmV2aW91c1ZhbHVlID0gcHJldmlvdXMgPyBwcmV2aW91c1twcm9wTmFtZV0gOiB1bmRlZm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uXG4gICAgICAgIGlmICh2Q2hpbGRyZW4pIHtcblxuICAgICAgICAgICAgdmFyIGNoaWxkTm9kZXMgPSByb290Tm9kZS5jaGlsZE5vZGVzXG5cbiAgICAgICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgdHJlZS5jaGlsZHJlbi5sZW5ndGg7IGkrKykge1xuICAgICAgICAgICAgICAgIHJvb3RJbmRleCArPSAxXG5cbiAgICAgICAgICAgICAgICB2YXIgdkNoaWxkID0gdkNoaWxkcmVuW2ldIHx8IG5vQ2hpbGRcbiAgICAgICAgICAgICAgICB2YXIgbmV4dEluZGV4ID0gcm9vdEluZGV4ICsgKHZDaGlsZC5jb3VudCB8fCAwKVxuXG4gICAgICAgICAgICAgICAgLy8gc2tpcCByZWN1cnNpb24gZG93biB0aGUgdHJlZSBpZiB0aGVyZSBhcmUgbm8gbm9kZXMgZG93biBoZXJlXG4gICAgICAgICAgICAgICAgaWYgKGluZGV4SW5SYW5nZShpbmRpY2VzLCByb290SW5kZXgsIG5leHRJbmRleCkpIHtcbiAgICAgICAgICAgICAgICAgICAgcmVjdXJzZShjaGlsZE5vZGVzW2ldLCB2Q2hpbGQsIGluZGljZXMsIG5vZGVzLCByb290SW5kZXgpXG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgcm9vdEluZGV4ID0gbmV4dEluZGV4XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICByZXR1cm4gbm9kZXNcbn1cblxuLy8gQmluYXJ5IHNlYXJjaCBmb3IgYW4gaW5kZXggaW4gdGhlIGludGVydmFsIFtsZWZ0LCByaWdodF1cbmZ1bmN0aW9uIGluZGV4SW5SYW5nZShpbmRpY2VzLCBsZWZ0LCByaWdodCkge1xuICAgIGlmIChpbmRpY2VzLmxlbmd0aCA9PT0gMCkge1xuICAgICAgICByZXR1cm4gZmFsc2VcbiAgICB9XG5cbiAgICB2YXIgbWluSW5kZXggPSAwXG4gICAgdmFyIG1heEluZ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cbiAgICAgICAgdmFyIGJWYWx1ZSA9IGJbYUtleV1cblxuICAgICAgICBpZiAoaG9va3MgJiYgYUtleSBpbiBob29rcykge1xuICAgICAgICAgICAgZGlmZiA9IGRpZmYgfHwge31cbiAgICAgICAgICAgIGRpZmZbYUtleV0gPSBiVmFsdWVcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGlmIChpc09iamVjdChhVmFsdWUpICYmIGlzT2JqZWN0KGJWYWx1ZSkpIHtcbiAgICAgICAgICAgICAgICBpZiAoZ2V0UHJvdG90eXBlKGJWYWx1ZSkgIT09IGdldFByb3RvdHlwZShhVmFsdWUpKSB7XG4gICAgICAgICAgICAgICAgICAgIGRpZmYgPSBkaWZmIHx8IHt9XG4gICAgICAgICAgICAgICAgICAgIGRpZmZbYUtleV0gPSBiVmFsdWVcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICB2YXIgb2JqZWN0RGlmZiA9IGRpZmZQcm9wcyhhVmFsdWUsIGJWYWx1ZSlcbiAgICAgICAgICAgICAgICAgICAgaWYgKG9iamVjdERpZmYpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGRpZmYgPSBkaWZmIHx8IHt9XG4gICAgICAgICAgICAgICAgICAgICAgICBkaWZmW2FLZXldID0gb2JqZWN0RGlmZlxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIGlmIChhVmFsdWUgIT09IGJWYWx1ZSkge1xuICAgICAgICAgICAgICAgIGRpZmYgPSBkaWZmIHx8IHt9XG4gICAgICAgICAgICAgICAgZGlmZlthS2V5XSA9IGJWYWx1ZVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgZm9yICh2YXIgYktleSBpbiBiKSB7XG4gICAgICAgIGlmICghKGJLZXkgaW4gYSkpIHtcbiAgICAgICAgICAgIGRpZmYgPSBkaWZmIHx8IHt9XG4gICAgICAg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A9IHt9XG4gICAgdmFyIHJldmVyc2UgPSBtb3Zlcy5yZXZlcnNlID0ge31cbiAgICB2YXIgaGFzTW92ZXMgPSBmYWxzZVxuXG4gICAgd2hpbGUgKGZyZWVJbmRleCA8IGxlbikge1xuICAgICAgICB2YXIgbW92ZSA9IGFNYXRjaFtpXVxuICAgICAgICBpZiAobW92ZSAhPT0gdW5kZWZpbmVkKSB7XG4gICAgICAgICAgICBzaHVmZmxlW2ldID0gYkNoaWxkcmVuW21vdmVdXG4gICAgICAgICAgICBpZiAobW92ZSAhPT0gbW92ZUluZGV4KSB7XG4gICAgICAgICAgICAgICAgbW92ZXNbbW92ZV0gPSBtb3ZlSW5kZXhcbiAgICAgICAgICAgICAgICByZXZlcnNlW21vdmVJbmRleF0gPSBtb3ZlXG4gICAgICAgICAgICAgICAgaGFzTW92ZXMgPSB0cnVlXG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBtb3ZlSW5kZXgrK1xuICAgICAgICB9IGVsc2UgaWYgKGkgaW4gYU1hdGNoKSB7XG4gICAgICAgICAgICBzaHVmZmxlW2ldID0gdW5kZWZpbmVkXG4gICAgICAgICAgICByZW1vdmVzW2ldID0gbW92ZUluZGV4KytcbiAgICAgICAgICAgIGhhc01vdmVzID0gdHJ1ZVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgd2hpbGUgKGJNYXRjaFtmcmVlSW5kZXhdICE9PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgICAgICBmcmVlSW5kZXgrK1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAoZnJlZUluZGV4IDwgbGVuKSB7XG4gICAgICAgICAgICAgICAgdmFyIGZyZWVDaGlsZCA9IGJDaGlsZHJlbltmcmVlSW5kZXhdXG4gICAgICAgICAgICAgICAgaWYgKGZyZWVDaGlsZCkge1xuICAgICAgICAgICAgICAgICAgICBzaHVmZmxlW2ldID0gZnJlZUNoaWxkXG4gICAgICAgICAgICAgICAgICAgIGlmIChmcmVlSW5kZXggIT09IG1vdmVJbmRleCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgaGFzTW92ZXMgPSB0cnVlXG4gICAgICAgICAgICAgICAgICAgICAgICBtb3Zlc1tmcmVlSW5kZXhdID0gbW92ZUluZGV4XG4gICAgICAgICAgICAgICAgICAgICAgICByZXZlcnNlW21vdmVJbmRleF0gPSBmcmVlSW5kZXhcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICBtb3ZlSW5kZXgrK1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBmcmVlSW5kZXgrK1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIGkrK1xuICAgIH1cblxuICAgIGlmIChoYXNNb3Zlcykge1xuICAgICAgICBzaHVmZmxlLm1vdmVzID0gbW92ZXNcbiAgICB9XG5cbiAgICByZXR1cm4gc2h1ZmZsZVxufVxuXG5mdW5jdGlvbiBrZXlJbmRleChjaGlsZHJlbikge1xuICAgIHZhciBpLCBrZXlzXG5cbiAgICBmb3IgKGkgPSAwOyBpIDwgY2hpbGRyZW4ubGVuZ3RoOyBpKyspIHtcbiAgICAgICAgdmFyIGNoaWxkID0gY2hpbGRyZW5baV1cblxuICAgICAgICBpZiAoY2hpbGQua2V5ICE9PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgIGtleXMgPSBrZXlzIHx8IHt9XG4gICAgICAgICAgICBrZXlzW2NoaWxkLmtleV0gPSBpXG4gICAgICAgIH1cbiAgICB9XG5cbiAgICByZXR1cm4ga2V5c1xufVxuXG5mdW5jdGlvbiBhcHBlbmRQYXRjaChhcHBseSwgcGF0Y2gpIHtcbiAgICBpZiAoYXBwbHkpIHtcbiAgICAgICAgaWYgKGlzQXJyYXkoYXBwbHkpKSB7XG4gICAgICAgICAgICBhcHBseS5wdXNoKHBhdGNoKVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgYXBwbHkgPSBbYXBwbHksIHBhdGNoX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ZhciBkZXNjZW5kYW50SG9va3MgPSBmYWxzZVxuICAgIHZhciBob29rc1xuXG4gICAgZm9yICh2YXIgcHJvcE5hbWUgaW4gcHJvcGVydGllcykge1xuICAgICAgICBpZiAocHJvcGVydGllcy5oYXNPd25Qcm9wZXJ0eShwcm9wTmFtZSkpIHtcbiAgICAgICAgICAgIHZhciBwcm9wZXJ0eSA9IHByb3BlcnRpZXNbcHJvcE5hbWVdXG4gICAgICAgICAgICBpZiAoaXNWSG9vayhwcm9wZXJ0eSkpIHtcbiAgICAgICAgICAgICAgICBpZiAoIWhvb2tzKSB7XG4gICAgICAgICAgICAgICAgICAgIGhvb2tzID0ge31cbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICBob29rc1twcm9wTmFtZV0gPSBwcm9wZXJ0eVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgZm9yICh2YXIgaSA9IDA7IGkgPCBjb3VudDsgaSsrKSB7XG4gICAgICAgIHZhciBjaGlsZCA9IGNoaWxkcmVuW2ldXG4gICAgICAgIGlmIChpc1ZOb2RlKGNoaWxkKSkge1xuICAgICAgICAgICAgZGVzY2VuZGFudHMgKz0gY2hpbGQuY291bnQgfHwgMFxuXG4gICAgICAgICAgICBpZiAoIWhhc1dpZGdldHMgJiYgY2hpbGQuaGFzV2lkZ2V0cykge1xuICAgICAgICAgICAgICAgIGhhc1dpZGdldHMgPSB0cnVlXG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmICghZGVzY2VuZGFudEhvb2tzICYmIChjaGlsZC5ob29rcyB8fCBjaGlsZC5kZXNjZW5kYW50SG9va3MpKSB7XG4gICAgICAgICAgICAgICAgZGVzY2VuZGFudEhvb2tzID0gdHJ1ZVxuICAgICAgICAgICAgfVxuICAgICAgICB9IGVsc2UgaWYgKCFoYXNXaWRnZXRzICYmIGlzV2lkZ2V0KGNoaWxkKSkge1xuICAgICAgICAgICAgaWYgKHR5cGVvZiBjaGlsZC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W4ocHJvcGVydGllcykpIHtcbiAgICAgICAgY2hpbGRyZW4gPSBwcm9wZXJ0aWVzXG4gICAgICAgIHByb3BlcnRpZXMgPSB7fVxuICAgIH1cblxuICAgIHByb3BlcnRpZXMgPSBwcm9wZXJ0aWVzIHx8IHt9XG5cbiAgICAvLyBzZXQgbmFtZXNwYWNlIGZvciBzdmdcbiAgICBwcm9wZXJ0aWVzLm5hbWVzcGFjZSA9IFNWR19OQU1FU1BBQ0VcblxuICAgIC8vIGZvciBlYWNoIGtleSwgaWYgYXR0cmlidXRlICYgc3RyaW5nLCBib29sIG9yIG51bWJlciB0aGVuXG4gICAgLy8gY29udmVydCBpdCBpbnRvIGEgc2V0QXR0cmlidXRlIGhvb2tcbiAgICBmb3IgKHZhciBrZXkgaW4gcHJvcGVydGllcykge1xuICAgICAgICBpZiAoIXByb3BlcnRpZXMuaGFzT3duUHJvcGVydHkoa2V5KSkge1xuICAgICAgICAgICAgY29udGludWVcbiAgICAgICAgfVxuXG4gICAgICAgIGlmIChCTEFDS0xJU1RFRF9LRVlTW2tleV0pIHtcbiAgICAgICAgICAgIGNvbnRpbnVlXG4gICAgICAgIH1cblxuICAgICAgICB2YXIgdmFsdWUgPSBwcm9wZXJ0aWVzW2tleV1cbiAgICAgICAgaWYgKHR5cGVvZiB2YWx1ZSAhPT0gXCJzdHJpbmdcIiAmJlxuICAgICAgICAgICAgdHlwZW9mIHZhbHVlICE9PSBcIm51bWJlclwiICYmXG4gICAgICAgICAgICB0eXBlb2YgdmFsdWUgIT09IFwiYm9vbGVhblwiXG4gICAgICAgICkge1xuICAgICAgICAgICAgY29udGludWVcbiAgICAgICAgfVxuXG4gICAgICAgIHByb3BlcnRpZXNba2V5XSA9IGF0dHJpYnV0ZUhvb2sodmFsdWUpXG4gICAgfVxuXG4gICAgcmV0dXJuIGgodGFnTmFtZSwgcHJvcGVydGllcywgY2hpbGRyZW4pXG59XG5cbmZ1bmN0aW9uIGlzQ2hpbGRyZW4oeCkge1xuICAg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FNhbmRib3hWaWV3ID0gcmVxdWlyZSgncnhtYXJibGVzL3ZpZXdzL3NhbmRib3gnKTtcbnZhciBTYW5kYm94SW50ZW50ID0gcmVxdWlyZSgncnhtYXJibGVzL2ludGVudHMvc2FuZGJveCcpO1xudmFyIHJlbmRlcmVyID0gcmVxdWlyZSgncnhtYXJibGVzL3JlbmRlcmVyJyk7XG5cbmJpbmRlcihPcGVyYXRvcnNNZW51TW9kZWwsIE9wZXJhdG9yc01lbnVWaWV3LCBPcGVyYXRvcnNNZW51SW50ZW50KTtcbmJpbmRlcihTYW5kYm94TW9kZWwsIFNhbmRib3hWaWV3LCBTYW5kYm94SW50ZW50KTtcbnJlbmRlcmVyLmluaXQoKTtcblxufSkuY2FsbCh0aGlzLHJlcXVpcmUoXCIxWWlaNVNcIiksdHlwZW9mIHNlbGYgIT09IFwidW5kZWZpbmVkXCIgPyBzZWxmIDogdHlwZW9mIHdpbmRvdyAhPT0gXCJ1bmRlZmluZWRcIiA/IHdpbmRvdyA6IHt9LHJlcXVpcmUoXCJidWZmZXJcIikuQnVmZmVyLGFyZ3VtZW50c1szXSxhcmd1bWVudHNbNF0sYXJndW1lbnRzWzVdLGFyZ3VtZW50c1s2XSxcIi9mYWtlX2Q5YTUxNzcuanNcIixcIi9cIikiXX0= diff --git a/dist/js/binder.js b/dist/js/binder.js index 6d0a84a..5d11ee1 100644 --- a/dist/js/binder.js +++ b/dist/js/binder.js @@ -1401,6 +1401,6 @@ module.exports = function(model, view, intent) { if (model) { model.observe(intent); } }; -}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/fake_d37cc0d2.js","/") +}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/fake_bb9ad017.js","/") },{"1YiZ5S":4,"buffer":1}]},{},[5]) -//# sourceMapp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WzNdLGFyZ3VtZW50c1s0XSxhcmd1bWVudHNbNV0sYXJndW1lbnRzWzZdLFwiL2Zha2VfYmI5YWQwMTcuanNcIixcIi9cIikiXX0= diff --git a/dist/js/renderer.js b/dist/js/renderer.js index e349868..e279fac 100644 --- a/dist/js/renderer.js +++ b/dist/js/renderer.js @@ -2335,699 +2335,6 @@ process.chdir = function (dir) { }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/gulp-browserify/node_modules/browserify/node_modules/process/browser.js","/../node_modules/gulp-browserify/node_modules/browserify/node_modules/process") },{"1YiZ5S":19,"buffer":15}],20:[function(require,module,exports){ -(function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ -var split = require('browser-split') -var ClassList = require('class-list') -var DataSet = require('data-set') -require('html-element') - -function context () { - - var cleanupFuncs = [] - - function h() { - var args = [].slice.call(arguments), e = null - function item (l) { - var r - function parseClass (string) { - var m = split(string, /([\.#]?[a-zA-Z0-9_:-]+)/) - if(/^\.|#/.test(m[1])) - e = document.createElement('div') - forEach(m, function (v) { - var s = v.substring(1,v.length) - if(!v) return - if(!e) - e = document.createElement(v) - else if (v[0] === '.') - ClassList(e).add(s) - else if (v[0] === '#') - e.setAttribute('id', s) - }) - } - - if(l == null) - ; - else if('string' === typeof l) { - if(!e) - parseClass(l) - else - e.appendChild(r = document.createTextNode(l)) - } - else if('number' === typeof l - || 'boolean' === typeof l - || l instanceof Date - || l instanceof RegExp ) { - e.appendChild(r = document.createTextNode(l.toString())) - } - //there might be a better way to handle this... - else if (isArray(l)) - forEach(l, item) - else if(isNode(l)) - e.appendChild(r = l) - else if(l instanceof Text) - e.appendChild(r = l) - else if ('object' === typeof l) { - for (var k in l) { - if('function' === typeof l[k]) { - if(/^on\w+/.test(k)) { - if (e.addEventListener){ - e.addEventListener(k.substring(2), l[k], false) - cleanupFuncs.push(function(){ - e.removeEventListener(k.substring(2), l[k], false) - }) - }else{ - e.attachEvent(k, l[k]) - cleanupFuncs.push(function(){ - e.detachEvent(k, l[k]) - }) - } - } else { - // observable - e[k] = l[k]() - cleanupFuncs.push(l[k](function (v) { - e[k] = v - })) - } - } - else if(k === 'style') { - if('string' === typeof l[k]) { - e.style.cssText = l[k] - }else{ - for (var s in l[k]) (function(s, v) { - if('function' === typeof v) { - // observable - e.style.setProperty(s, v()) - cleanupFuncs.push(v(function (val) { - e.style.setProperty(s, val) - })) - } else - e.style.setProperty(s, l[k][s]) - })(s, l[k][s]) - } - } else if (k.substr(0, 5) === "data-") { - DataSet(e)[k.substr(5)] = l[k] - } else { - e[k] = l[k] - } - } - } else if ('function' === typeof l) { - //assume it's an observable! - var v = l() - e.appendChild(r = isNode(v) ? v : document.createTextNode(v)) - - cleanupFuncs.push(l(function (v) { - if(isNode(v) && r.parentElement) - r.parentElement.replaceChild(v, r), r = v - else - r.textContent = v - })) - } - - return r - } - while(args.length) - item(args.shift()) - - return e - } - - h.cleanup = function () { - for (var i = 0; i < cleanupFuncs.length; i++){ - cleanupFuncs[i]() - } - } - - return h -} - -var h = module.exports = context() -h.context = context - -function isNode (el) { - return el && el.nodeName && el.nodeType -} - -function isText (el) { - return el && el.nodeName === '#text' && el.nodeType == 3 -} - -function forEach (arr, fn) { - if (arr.forEach) return arr.forEach(fn) - for (var i = 0; i < arr.length; i++) fn(arr[i], i) -} - -function isArray (arr) { - return Object.prototype.toString.call(arr) == '[object Array]' -} - -}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/hyperscript/index.js","/../node_modules/hyperscript") -},{"1YiZ5S":19,"browser-split":21,"buffer":15,"class-list":22,"data-set":24,"html-element":14}],21:[function(require,module,exports){ -(function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ -/*! - * Cross-Browser Split 1.1.1 - * Copyright 2007-2012 Steven Levithan - * Available under the MIT License - * ECMAScript compliant, uniform cross-browser split method - */ - -/** - * Splits a string into an array of strings using a regex or string separator. Matches of the - * separator are not included in the result array. However, if `separator` is a regex that contains - * capturing groups, backreferences are spliced into the result each time `separator` is matched. - * Fixes browser bugs compared to the native `String.prototype.split` and can be used reliably - * cross-browser. - * @param {String} str String to split. - * @param {RegExp|String} separator Regex or string to use for separating the string. - * @param {Number} [limit] Maximum number of items to include in the result array. - * @returns {Array} Array of substrings. - * @example - * - * // Basic use - * split('a b c d', ' '); - * // -> ['a', 'b', 'c', 'd'] - * - * // With limit - * split('a b c d', ' ', 2); - * // -> ['a', 'b'] - * - * // Backreferences in result array - * split('..word1 word2..', /([a-z]+)(\d+)/i); - * // -> ['..', 'word', '1', ' ', 'word', '2', '..'] - */ -module.exports = (function split(undef) { - - var nativeSplit = String.prototype.split, - compliantExecNpcg = /()??/.exec("")[1] === undef, - // NPCG: nonparticipating capturing group - self; - - self = function(str, separator, limit) { - // If `separator` is not a regex, use `nativeSplit` - if (Object.prototype.toString.call(separator) !== "[object RegExp]") { - return nativeSplit.call(str, separator, limit); - } - var output = [], - flags = (separator.ignoreCase ? "i" : "") + (separator.multiline ? "m" : "") + (separator.extended ? "x" : "") + // Proposed for ES6 - (separator.sticky ? "y" : ""), - // Firefox 3+ - lastLastIndex = 0, - // Make `global` and avoid `lastIndex` issues by working with a copy - separator = new RegExp(separator.source, flags + "g"), - separator2, match, lastIndex, lastLength; - str += ""; // Type-convert - if (!compliantExecNpcg) { - // Doesn't need flags gy, but they don't hurt - separator2 = new RegExp("^" + separator.source + "$(?!\\s)", flags); - } - /* Values for `limit`, per the spec: - * If undefined: 4294967295 // Math.pow(2, 32) - 1 - * If 0, Infinity, or NaN: 0 - * If positive number: limit = Math.floor(limit); if (limit > 4294967295) limit -= 4294967296; - * If negative number: 4294967296 - Math.floor(Math.abs(limit)) - * If other: Type-convert, then use the above rules - */ - limit = limit === undef ? -1 >>> 0 : // Math.pow(2, 32) - 1 - limit >>> 0; // ToUint32(limit) - while (match = separator.exec(str)) { - // `separator.lastIndex` is not reliable cross-browser - lastIndex = match.index + match[0].length; - if (lastIndex > lastLastIndex) { - output.push(str.slice(lastLastIndex, match.index)); - // Fix browsers whose `exec` methods don't consistently return `undefined` for - // nonparticipating capturing groups - if (!compliantExecNpcg && match.length > 1) { - match[0].replace(separator2, function() { - for (var i = 1; i < arguments.length - 2; i++) { - if (arguments[i] === undef) { - match[i] = undef; - } - } - }); - } - if (match.length > 1 && match.index < str.length) { - Array.prototype.push.apply(output, match.slice(1)); - } - lastLength = match[0].length; - lastLastIndex = lastIndex; - if (output.length >= limit) { - break; - } - } - if (separator.lastIndex === match.index) { - separator.lastIndex++; // Avoid an infinite loop - } - } - if (lastLastIndex === str.length) { - if (lastLength || !separator.test("")) { - output.push(""); - } - } else { - output.push(str.slice(lastLastIndex)); - } - return output.length > limit ? output.slice(0, limit) : output; - }; - - return self; -})(); - -}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/hyperscript/node_modules/browser-split/index.js","/../node_modules/hyperscript/node_modules/browser-split") -},{"1YiZ5S":19,"buffer":15}],22:[function(require,module,exports){ -(function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ -// contains, add, remove, toggle -var indexof = require('indexof') - -module.exports = ClassList - -function ClassList(elem) { - var cl = elem.classList - - if (cl) { - return cl - } - - var classList = { - add: add - , remove: remove - , contains: contains - , toggle: toggle - , toString: $toString - , length: 0 - , item: item - } - - return classList - - function add(token) { - var list = getTokens() - if (indexof(list, token) > -1) { - return - } - list.push(token) - setTokens(list) - } - - function remove(token) { - var list = getTokens() - , index = indexof(list, token) - - if (index === -1) { - return - } - - list.splice(index, 1) - setTokens(list) - } - - function contains(token) { - return indexof(getTokens(), token) > -1 - } - - function toggle(token) { - if (contains(token)) { - remove(token) - return false - } else { - add(token) - return true - } - } - - function $toString() { - return elem.className - } - - function item(index) { - var tokens = getTokens() - return tokens[index] || null - } - - function getTokens() { - var className = elem.className - - return filter(className.split(" "), isTruthy) - } - - function setTokens(list) { - var length = list.length - - elem.className = list.join(" ") - classList.length = length - - for (var i = 0; i < list.length; i++) { - classList[i] = list[i] - } - - delete list[length] - } -} - -function filter (arr, fn) { - var ret = [] - for (var i = 0; i < arr.length; i++) { - if (fn(arr[i])) ret.push(arr[i]) - } - return ret -} - -function isTruthy(value) { - return !!value -} - -}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/hyperscript/node_modules/class-list/index.js","/../node_modules/hyperscript/node_modules/class-list") -},{"1YiZ5S":19,"buffer":15,"indexof":23}],23:[function(require,module,exports){ -(function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ - -var indexOf = [].indexOf; - -module.exports = function(arr, obj){ - if (indexOf) return arr.indexOf(obj); - for (var i = 0; i < arr.length; ++i) { - if (arr[i] === obj) return i; - } - return -1; -}; -}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/hyperscript/node_modules/class-list/node_modules/indexof/index.js","/../node_modules/hyperscript/node_modules/class-list/node_modules/indexof") -},{"1YiZ5S":19,"buffer":15}],24:[function(require,module,exports){ -(function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ -var Weakmap = require("weakmap") -var Individual = require("individual") - -var datasetMap = Individual("__DATA_SET_WEAKMAP", Weakmap()) - -module.exports = DataSet - -function DataSet(elem) { - if (elem.dataset) { - return elem.dataset - } - - var hash = datasetMap.get(elem) - - if (!hash) { - hash = createHash(elem) - datasetMap.set(elem, hash) - } - - return hash -} - -function createHash(elem) { - var attributes = elem.attributes - var hash = {} - - if (attributes === null || attributes === undefined) { - return hash - } - - for (var i = 0; i < attributes.length; i++) { - var attr = attributes[i] - - if (attr.name.substr(0,5) !== "data-") { - continue - } - - hash[attr.name.substr(5)] = attr.value - } - - return hash -} - -}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/hyperscript/node_modules/data-set/index.js","/../node_modules/hyperscript/node_modules/data-set") -},{"1YiZ5S":19,"buffer":15,"individual":25,"weakmap":27}],25:[function(require,module,exports){ -(function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ -var root = require("global") - -module.exports = Individual - -function Individual(key, value) { - if (root[key]) { - return root[key] - } - - Object.defineProperty(root, key, { - value: value - , configurable: true - }) - - return value -} - -}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/hyperscript/node_modules/data-set/node_modules/individual/index.js","/../node_modules/hyperscript/node_modules/data-set/node_modules/individual") -},{"1YiZ5S":19,"buffer":15,"global":26}],26:[function(require,module,exports){ -(function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ -/*global window, global*/ -if (typeof global !== "undefined") { - module.exports = global -} else if (typeof window !== "undefined") { - module.exports = window -} - -}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/hyperscript/node_modules/data-set/node_modules/individual/node_modules/global/index.js","/../node_modules/hyperscript/node_modules/data-set/node_modules/individual/node_modules/global") -},{"1YiZ5S":19,"buffer":15}],27:[function(require,module,exports){ -(function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ -/* (The MIT License) - * - * Copyright (c) 2012 Brandon Benvie - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and - * associated documentation files (the 'Software'), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included with all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -// Original WeakMap implementation by Gozala @ https://gist.github.com/1269991 -// Updated and bugfixed by Raynos @ https://gist.github.com/1638059 -// Expanded by Benvie @ https://github.com/Benvie/harmony-collections - -void function(global, undefined_, undefined){ - var getProps = Object.getOwnPropertyNames, - defProp = Object.defineProperty, - toSource = Function.prototype.toString, - create = Object.create, - hasOwn = Object.prototype.hasOwnProperty, - funcName = /^\n?function\s?(\w*)?_?\(/; - - - function define(object, key, value){ - if (typeof key === 'function') { - value = key; - key = nameOf(value).replace(/_$/, ''); - } - return defProp(object, key, { configurable: true, writable: true, value: value }); - } - - function nameOf(func){ - return typeof func !== 'function' - ? '' : 'name' in func - ? func.name : toSource.call(func).match(funcName)[1]; - } - - // ############ - // ### Data ### - // ############ - - var Data = (function(){ - var dataDesc = { value: { writable: true, value: undefined } }, - datalock = 'return function(k){if(k===s)return l}', - uids = create(null), - - createUID = function(){ - var key = Math.random().toString(36).slice(2); - return key in uids ? createUID() : uids[key] = key; - }, - - globalID = createUID(), - - storage = function(obj){ - if (hasOwn.call(obj, globalID)) - return obj[globalID]; - - if (!Object.isExtensible(obj)) - throw new TypeError("Object must be extensible"); - - var store = create(null); - defProp(obj, globalID, { value: store }); - return store; - }; - - // common per-object storage area made visible by patching getOwnPropertyNames' - define(Object, function getOwnPropertyNames(obj){ - var props = getProps(obj); - if (hasOwn.call(obj, globalID)) - props.splice(props.indexOf(globalID), 1); - return props; - }); - - function Data(){ - var puid = createUID(), - secret = {}; - - this.unlock = function(obj){ - var store = storage(obj); - if (hasOwn.call(store, puid)) - return store[puid](secret); - - var data = create(null, dataDesc); - defProp(store, puid, { - value: new Function('s', 'l', datalock)(secret, data) - }); - return data; - } - } - - define(Data.prototype, function get(o){ return this.unlock(o).value }); - define(Data.prototype, function set(o, v){ this.unlock(o).value = v }); - - return Data; - }()); - - - var WM = (function(data){ - var validate = function(key){ - if (key == null || typeof key !== 'object' && typeof key !== 'function') - throw new TypeError("Invalid WeakMap key"); - } - - var wrap = function(collection, value){ - var store = data.unlock(collection); - if (store.value) - throw new TypeError("Object is already a WeakMap"); - store.value = value; - } - - var unwrap = function(collection){ - var storage = data.unlock(collection).value; - if (!storage) - throw new TypeError("WeakMap is not generic"); - return storage; - } - - var initialize = function(weakmap, iterable){ - if (iterable !== null && typeof iterable === 'object' && typeof iterable.forEach === 'function') { - iterable.forEach(function(item, i){ - if (item instanceof Array && item.length === 2) - set.call(weakmap, iterable[i][0], iterable[i][1]); - }); - } - } - - - function WeakMap(iterable){ - if (this === global || this == null || this === WeakMap.prototype) - return new WeakMap(iterable); - - wrap(this, new Data); - initialize(this, iterable); - } - - function get(key){ - validate(key); - var value = unwrap(this).get(key); - return value === undefined_ ? undefined : value; - } - - function set(key, value){ - validate(key); - // store a token for explicit undefined so that "has" works correctly - unwrap(this).set(key, value === undefined ? undefined_ : value); - } - - function has(key){ - validate(key); - return unwrap(this).get(key) !== undefined; - } - - function delete_(key){ - validate(key); - var data = unwrap(this), - had = data.get(key) !== undefined; - data.set(key, undefined); - return had; - } - - function toString(){ - unwrap(this); - return '[object WeakMap]'; - } - - try { - var src = ('return '+delete_).replace('e_', '\\u0065'), - del = new Function('unwrap', 'validate', src)(unwrap, validate); - } catch (e) { - var del = delete_; - } - - var src = (''+Object).split('Object'); - var stringifier = function toString(){ - return src[0] + nameOf(this) + src[1]; - }; - - define(stringifier, stringifier); - - var prep = { __proto__: [] } instanceof Array - ? function(f){ f.__proto__ = stringifier } - : function(f){ define(f, stringifier) }; - - prep(WeakMap); - - [toString, get, set, has, del].forEach(function(method){ - define(WeakMap.prototype, method); - prep(method); - }); - - return WeakMap; - }(new Data)); - - var defaultCreator = Object.create - ? function(){ return Object.create(null) } - : function(){ return {} }; - - function createStorage(creator){ - var weakmap = new WM; - creator || (creator = defaultCreator); - - function storage(object, value){ - if (value || arguments.length === 2) { - weakmap.set(object, value); - } else { - value = weakmap.get(object); - if (value === undefined) { - value = creator(object); - weakmap.set(object, value); - } - } - return value; - } - - return storage; - } - - - if (typeof module !== 'undefined') { - module.exports = WM; - } else if (typeof exports !== 'undefined') { - exports.WeakMap = WM; - } else if (!('WeakMap' in global)) { - global.WeakMap = WM; - } - - WM.createStorage = createStorage; - if (global.WeakMap) - global.WeakMap.createStorage = createStorage; -}((0, eval)('this')); - -}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/hyperscript/node_modules/data-set/node_modules/weakmap/weakmap.js","/../node_modules/hyperscript/node_modules/data-set/node_modules/weakmap") -},{"1YiZ5S":19,"buffer":15}],28:[function(require,module,exports){ module.exports={ "name": "rxmarbles", "version": "1.0.2", @@ -3042,7 +2349,6 @@ module.exports={ "rx": "2.3.12", "virtual-dom": "0.0.19", "virtual-hyperscript": "4.4.0", - "hyperscript": "1.4.0", "dom-delegator": "^9.0.1" }, "devDependencies": { @@ -3063,7 +2369,7 @@ module.exports={ } } -},{}],29:[function(require,module,exports){ +},{}],21:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. @@ -12350,7 +11656,7 @@ module.exports={ }.call(this)); }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rx/dist/rx.all.js","/../node_modules/rx/dist") -},{"1YiZ5S":19,"buffer":15}],30:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],22:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. @@ -12834,7 +12140,7 @@ module.exports={ })); }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rx/dist/rx.testing.js","/../node_modules/rx/dist") -},{"./rx.all":29,"1YiZ5S":19,"buffer":15}],31:[function(require,module,exports){ +},{"./rx.all":21,"1YiZ5S":19,"buffer":15}],23:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var Rx = require('./dist/rx.all'); require('./dist/rx.testing'); @@ -13011,7 +12317,7 @@ Rx.Node = { module.exports = Rx; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rx/index.js","/../node_modules/rx") -},{"./dist/rx.all":29,"./dist/rx.testing":30,"1YiZ5S":19,"buffer":15,"events":18}],32:[function(require,module,exports){ +},{"./dist/rx.all":21,"./dist/rx.testing":22,"1YiZ5S":19,"buffer":15,"events":18}],24:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ /* * Utility functions @@ -13040,30 +12346,15 @@ module.exports = { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/utils.js","/../node_modules/rxmarbles") -},{"1YiZ5S":19,"buffer":15}],33:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],25:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ /* * Renders a marker for the completion notification of a stream diagram. */ -var h = require('hyperscript'); -var vh = require('virtual-hyperscript'); -var Utils = require('rxmarbles/views/utils'); +var h = require('virtual-hyperscript'); var MARBLE_WIDTH = 5; // estimate of a marble width, in percentages -function render(completionTime) { - var element = h('div.diagramCompletion.is-draggable.js-completion', {}, [ - h('div.diagramCompletion-inner') - ]); - element.dataStream = Utils.getInteractiveLeftPosStream(element, completionTime); - element.dataStream - .subscribe(function(leftPos) { - element.style.left = leftPos + '%'; - return true; - }); - return element; -} - function vrender(completionData, isDraggable, diagramData, mouseDown$) { if (typeof isDraggable === 'undefined') { isDraggable = false; @@ -13076,22 +12367,21 @@ function vrender(completionData, isDraggable, diagramData, mouseDown$) { } }); var isTallClass = (isTall) ? '.is-tall' : ''; - return vh('div.diagramCompletion' + isDraggableClass + isTallClass, { + return h('div.diagramCompletion' + isDraggableClass + isTallClass, { style: {'left': completionData.time + '%'}, attributes: {'data-diagram-id': completionData.diagramId}, 'ev-mousedown': function(ev) { if (mouseDown$) { mouseDown$.onNext(ev); } } },[ - vh('div.diagramCompletion-inner') + h('div.diagramCompletion-inner') ]); } module.exports = { - render: render, vrender: vrender }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/views/completion.js","/../node_modules/rxmarbles/views") -},{"1YiZ5S":19,"buffer":15,"hyperscript":20,"rxmarbles/views/utils":41,"virtual-hyperscript":67}],34:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"virtual-hyperscript":57}],26:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ /* * Virtually renders a stream diagram. @@ -13125,92 +12415,24 @@ module.exports = { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/views/diagram.js","/../node_modules/rxmarbles/views") -},{"1YiZ5S":19,"buffer":15,"rx":31,"rxmarbles/views/completion":33,"rxmarbles/views/marble":35,"virtual-hyperscript":67}],35:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"rx":23,"rxmarbles/views/completion":25,"rxmarbles/views/marble":27,"virtual-hyperscript":57}],27:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ /* * Renders a circle or similar shape to represent an emitted item on a stream. */ -var Rx = require('rx'); -var Utils = require('rxmarbles/views/utils'); -var vh = require('virtual-hyperscript'); +var h = require('virtual-hyperscript'); var svg = require('virtual-hyperscript/svg'); -var XMLNS = 'http://www.w3.org/2000/svg'; var NUM_COLORS = 4; -var SVG_VIEWBOX = '0 0 1 1'; -var SVG_CX = 0.5; -var SVG_CY = 0.5; -var SVG_R = 0.47; -var SVG_BORDER_WIDTH = '0.06px'; - -function createRootElement(draggable) { - var container = document.createElement('div'); - container.className = 'marble js-marble'; - if (draggable) { - container.className += ' is-draggable'; - } - return container; -} - -function createMarbleSvg(item) { - var colornum = (item.id % NUM_COLORS) + 1; - var marble = document.createElementNS(XMLNS, 'svg'); - marble.setAttribute('class', 'marble-inner'); - marble.setAttribute('viewBox', SVG_VIEWBOX); - var circle = document.createElementNS(XMLNS, 'circle'); - circle.setAttribute('cx', SVG_CX); - circle.setAttribute('cy', SVG_CY); - circle.setAttribute('r', SVG_R); - circle.setAttribute('class', 'marble-shape marble-shape--color' + colornum); - circle.setAttribute('stroke-width', SVG_BORDER_WIDTH); - marble.appendChild(circle); - return marble; -} - -function createContentElement(item) { - var content = document.createElement('p'); - content.className = 'marble-content'; - content.textContent = (item != null) ? item.content : ''; - return content; -} - -function getLeftPosStream(item, draggable, element) { - if (draggable) { - return Utils.getInteractiveLeftPosStream(element, item.time); - } else { - return Rx.Observable.just(item.time); - } -} - -function render(item, draggable) { - if (draggable == null) { - draggable = false; - } - // Create DOM elements - var marble = createRootElement(draggable); - marble.appendChild(createMarbleSvg(item)); - marble.appendChild(createContentElement(item)); - // Define public and private streams - var leftPosStream = getLeftPosStream(item, draggable, marble); - marble.dataStream = leftPosStream - .map(function(leftPos) { - return {time: leftPos, content: item.content, id: item.id}; - }); - leftPosStream - .subscribe(function(leftPos) { - marble.style.left = leftPos + '%'; - }); - return marble; -} function vrender(marbleData, isDraggable, mouseDown$) { if (typeof isDraggable === 'undefined') { isDraggable = false; } - var colornum = (marbleData.id % 4) + 1; + var colornum = (marbleData.id % NUM_COLORS) + 1; var leftPos = '' + marbleData.time + '%'; var content = '' + marbleData.content; - return vh('div.marble.js-marble'+(isDraggable ? '.is-draggable' :''), { + return h('div.marble.js-marble'+(isDraggable ? '.is-draggable' :''), { style: {'left': leftPos}, attributes: { 'data-marble-id': marbleData.id, @@ -13222,71 +12444,25 @@ function vrender(marbleData, isDraggable, mouseDown$) { } } },[ - svg('svg', {attributes: {'class': 'marble-inner', viewBox: SVG_VIEWBOX}}, [ + svg('svg', {attributes: {'class': 'marble-inner', viewBox: '0 0 1 1'}}, [ svg('circle', { attributes: { 'class': 'marble-shape marble-shape--color' + colornum, - cx: SVG_CX, cy: SVG_CY, r: SVG_R, - 'stroke-width': SVG_BORDER_WIDTH + cx: 0.5, cy: 0.5, r: 0.47, + 'stroke-width': '0.06px' } }) ]), - vh('p.marble-content', {}, content) + h('p.marble-content', {}, content) ]); } module.exports = { - render: render, vrender: vrender }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/views/marble.js","/../node_modules/rxmarbles/views") -},{"1YiZ5S":19,"buffer":15,"rx":31,"rxmarbles/views/utils":41,"virtual-hyperscript":67,"virtual-hyperscript/svg":86}],36:[function(require,module,exports){ -(function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ -/* - * Renders a scrollable list of operators to be demonstrated on the sandbox. - */ -var Rx = require('rx'); -var h = require('virtual-hyperscript'); -var SandboxInput = require('rxmarbles/views/sandbox-input'); -var SandboxOperator = require('rxmarbles/views/sandbox-operator'); -var SandboxOutput = require('rxmarbles/views/sandbox-output'); -var replicate = require('rxmarbles/utils').replicate; - -var modelExample$ = new Rx.BehaviorSubject(); -var modelInputDiagrams$ = new Rx.BehaviorSubject(); -var modelOutputDiagram$ = new Rx.BehaviorSubject(); -var marbleMouseDown$ = new Rx.Subject(); -var completionMouseDown$ = new Rx.Subject(); - -function observe(model) { - replicate(model.example$, modelExample$); - replicate(model.inputDiagrams$, modelInputDiagrams$); - replicate(model.outputDiagram$, modelOutputDiagram$); -} - -var vtree$ = Rx.Observable - .combineLatest(modelExample$, modelInputDiagrams$, modelOutputDiagram$, - function(example, inputDiagrams, outputDiagram) { - return h("div.sandbox", [ - SandboxInput.vrender(inputDiagrams, marbleMouseDown$, completionMouseDown$), - SandboxOperator.vrender(example), - SandboxOutput.vrender(outputDiagram) - ]); - } - ); - -//marbleMouseDown$.subscribe(function(ev) { console.log("LOOK!"); console.log(ev); }); - -module.exports = { - observe: observe, - vtree$: vtree$, - marbleMouseDown$: marbleMouseDown$, - completionMouseDown$: completionMouseDown$ -}; - -}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/views/new-sandbox.js","/../node_modules/rxmarbles/views") -},{"1YiZ5S":19,"buffer":15,"rx":31,"rxmarbles/utils":32,"rxmarbles/views/sandbox-input":38,"rxmarbles/views/sandbox-operator":39,"rxmarbles/views/sandbox-output":40,"virtual-hyperscript":67}],37:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"virtual-hyperscript":57,"virtual-hyperscript/svg":76}],28:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ /* * Renders a scrollable list of operators to be demonstrated on the sandbox. @@ -13371,7 +12547,7 @@ module.exports = { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/views/operators-menu.js","/../node_modules/rxmarbles/views") -},{"1YiZ5S":19,"buffer":15,"rx":31,"rxmarbles/utils":32,"virtual-hyperscript":67}],38:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"rx":23,"rxmarbles/utils":24,"virtual-hyperscript":57}],29:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ /* * Virtually renders stream diagrams meant as inputs to the sandbox. @@ -13393,7 +12569,7 @@ module.exports = { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/views/sandbox-input.js","/../node_modules/rxmarbles/views") -},{"1YiZ5S":19,"buffer":15,"rx":31,"rxmarbles/views/diagram":34,"virtual-hyperscript":67}],39:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"rx":23,"rxmarbles/views/diagram":26,"virtual-hyperscript":57}],30:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ /* * Renders a box representing the Rx operator being applied on the input @@ -13416,7 +12592,7 @@ module.exports = { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/views/sandbox-operator.js","/../node_modules/rxmarbles/views") -},{"1YiZ5S":19,"buffer":15,"rx":31,"virtual-hyperscript":67}],40:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"rx":23,"virtual-hyperscript":57}],31:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ /* * Virtually renders a stream diagram meant as the output of the sandbox. @@ -13434,117 +12610,57 @@ module.exports = { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/views/sandbox-output.js","/../node_modules/rxmarbles/views") -},{"1YiZ5S":19,"buffer":15,"rx":31,"rxmarbles/views/diagram":34,"virtual-hyperscript":67}],41:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"rx":23,"rxmarbles/views/diagram":26,"virtual-hyperscript":57}],32:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ /* - * Util functions for rendering to the DOM. + * SandboxView */ var Rx = require('rx'); var h = require('virtual-hyperscript'); -var VDOM = { - createElement: require('virtual-dom/create-element'), - diff: require('virtual-dom/diff'), - patch: require('virtual-dom/patch') -}; +var SandboxInput = require('rxmarbles/views/sandbox-input'); +var SandboxOperator = require('rxmarbles/views/sandbox-operator'); +var SandboxOutput = require('rxmarbles/views/sandbox-output'); +var replicate = require('rxmarbles/utils').replicate; -function getDxDragStream(element) { - return Rx.Observable.fromEvent(element, "mousedown") - .map(function() { - var moveStream = Rx.Observable.fromEvent(document, "mousemove"); - var upStream = Rx.Observable.fromEvent(document, "mouseup"); - var dxStream = moveStream - .map(function(ev) { - ev.stopPropagation; - ev.preventDefault(); - return ev.pageX; - }) - .windowWithCount(2, 1) - .flatMap(function(result) { return result.toArray(); }) - .map(function(array) { return array[1] - array[0]; }); - return dxStream.takeUntil(upStream); - }) - .concatAll(); -} +var modelExample$ = new Rx.BehaviorSubject(); +var modelInputDiagrams$ = new Rx.BehaviorSubject(); +var modelOutputDiagram$ = new Rx.BehaviorSubject(); +var marbleMouseDown$ = new Rx.Subject(); +var completionMouseDown$ = new Rx.Subject(); -function getInteractiveLeftPosStream(element, initialPos) { - return getDxDragStream(element) - .scan(initialPos, function(acc, dx) { - var pxToPercentage = 1; - try { - pxToPercentage = 100.0 / element.parentElement.clientWidth; - } catch (err) { - console.warn(err); - } - return acc + (dx * pxToPercentage); - }) - .map(function(pos) { - if (pos < 0) { return 0; } - if (pos > 100) { return 100; } - return pos; - }) - .map(Math.round) - .startWith(initialPos) - .distinctUntilChanged(); +function observe(model) { + replicate(model.example$, modelExample$); + replicate(model.inputDiagrams$, modelInputDiagrams$); + replicate(model.outputDiagram$, modelOutputDiagram$); } -function renderVTreeStream(vtree$, containerSelector) { - // Find and prepare the container - var container = document.querySelector(containerSelector); - if (container === null) { - console.error("Couldn't render into unknown '" + containerSelector + "'"); - return false; - } - container.innerHTML = ""; - // Make the DOM node bound to the VDOM node - var rootNode = document.createElement("div"); - container.appendChild(rootNode); - vtree$.startWith(h()) - .bufferWithCount(2, 1) - .subscribe(function(buffer) { - var oldVTree = buffer[0]; - var newVTree = buffer[1]; - rootNode = VDOM.patch(rootNode, VDOM.diff(oldVTree, newVTree)); - }); - return true; -}; - -function renderObservableDOMElement(elementStream) { - var wrapper = document.createElement("div"); - elementStream.subscribe(function(thing) { - wrapper.innerHTML = ""; - if (Array.isArray(thing)) { - for (i = 0; i < thing.length; i++) { - wrapper.appendChild(thing[i]); - } - } else if (thing instanceof Element) { - wrapper.appendChild(thing); +var vtree$ = Rx.Observable + .combineLatest(modelExample$, modelInputDiagrams$, modelOutputDiagram$, + function(example, inputDiagrams, outputDiagram) { + return h("div.sandbox", [ + SandboxInput.vrender(inputDiagrams, marbleMouseDown$, completionMouseDown$), + SandboxOperator.vrender(example), + SandboxOutput.vrender(outputDiagram) + ]); } - }); - return wrapper; -}; + ); module.exports = { - renderVTreeStream: renderVTreeStream, - renderObservableDOMElement: renderObservableDOMElement, - getInteractiveLeftPosStream: getInteractiveLeftPosStream + observe: observe, + vtree$: vtree$, + marbleMouseDown$: marbleMouseDown$, + completionMouseDown$: completionMouseDown$ }; -}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/views/utils.js","/../node_modules/rxmarbles/views") -},{"1YiZ5S":19,"buffer":15,"rx":31,"virtual-dom/create-element":42,"virtual-dom/diff":43,"virtual-dom/patch":62,"virtual-hyperscript":67}],42:[function(require,module,exports){ -(function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ -var createElement = require("vdom/create-element") - -module.exports = createElement - -}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/create-element.js","/../node_modules/virtual-dom") -},{"1YiZ5S":19,"buffer":15,"vdom/create-element":46}],43:[function(require,module,exports){ +}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/rxmarbles/views/sandbox.js","/../node_modules/rxmarbles/views") +},{"1YiZ5S":19,"buffer":15,"rx":23,"rxmarbles/utils":24,"rxmarbles/views/sandbox-input":29,"rxmarbles/views/sandbox-operator":30,"rxmarbles/views/sandbox-output":31,"virtual-hyperscript":57}],33:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var diff = require("vtree/diff") module.exports = diff }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/diff.js","/../node_modules/virtual-dom") -},{"1YiZ5S":19,"buffer":15,"vtree/diff":52}],44:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"vtree/diff":42}],34:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ module.exports = isObject @@ -13553,7 +12669,7 @@ function isObject(x) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/is-object/index.js","/../node_modules/virtual-dom/node_modules/is-object") -},{"1YiZ5S":19,"buffer":15}],45:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],35:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var isObject = require("is-object") var isHook = require("vtree/is-vhook") @@ -13649,7 +12765,7 @@ function getPrototype(value) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vdom/apply-properties.js","/../node_modules/virtual-dom/node_modules/vdom") -},{"1YiZ5S":19,"buffer":15,"is-object":44,"vtree/is-vhook":55}],46:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"is-object":34,"vtree/is-vhook":45}],36:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var document = require("global/document") @@ -13699,7 +12815,7 @@ function createElement(vnode, opts) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vdom/create-element.js","/../node_modules/virtual-dom/node_modules/vdom") -},{"./apply-properties":45,"1YiZ5S":19,"buffer":15,"global/document":48,"vtree/handle-thunk":53,"vtree/is-vnode":56,"vtree/is-vtext":57,"vtree/is-widget":58}],47:[function(require,module,exports){ +},{"./apply-properties":35,"1YiZ5S":19,"buffer":15,"global/document":38,"vtree/handle-thunk":43,"vtree/is-vnode":46,"vtree/is-vtext":47,"vtree/is-widget":48}],37:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ // Maps a virtual DOM tree onto a real DOM tree in an efficient manner. // We don't want to read all of the DOM nodes in the tree so we use @@ -13788,7 +12904,7 @@ function ascending(a, b) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vdom/dom-index.js","/../node_modules/virtual-dom/node_modules/vdom") -},{"1YiZ5S":19,"buffer":15}],48:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],38:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var topLevel = typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : {} @@ -13807,7 +12923,7 @@ if (typeof document !== 'undefined') { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vdom/node_modules/global/document.js","/../node_modules/virtual-dom/node_modules/vdom/node_modules/global") -},{"1YiZ5S":19,"buffer":15,"min-document":14}],49:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"min-document":14}],39:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var applyProperties = require("./apply-properties") @@ -13979,7 +13095,7 @@ function replaceRoot(oldRoot, newRoot) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vdom/patch-op.js","/../node_modules/virtual-dom/node_modules/vdom") -},{"./apply-properties":45,"./create-element":46,"./update-widget":51,"1YiZ5S":19,"buffer":15,"vtree/is-widget":58,"vtree/vpatch":60}],50:[function(require,module,exports){ +},{"./apply-properties":35,"./create-element":36,"./update-widget":41,"1YiZ5S":19,"buffer":15,"vtree/is-widget":48,"vtree/vpatch":50}],40:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var document = require("global/document") var isArray = require("x-is-array") @@ -14059,7 +13175,7 @@ function patchIndices(patches) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vdom/patch.js","/../node_modules/virtual-dom/node_modules/vdom") -},{"./dom-index":47,"./patch-op":49,"1YiZ5S":19,"buffer":15,"global/document":48,"x-is-array":61}],51:[function(require,module,exports){ +},{"./dom-index":37,"./patch-op":39,"1YiZ5S":19,"buffer":15,"global/document":38,"x-is-array":51}],41:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var isWidget = require("vtree/is-widget") @@ -14078,7 +13194,7 @@ function updateWidget(a, b) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vdom/update-widget.js","/../node_modules/virtual-dom/node_modules/vdom") -},{"1YiZ5S":19,"buffer":15,"vtree/is-widget":58}],52:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"vtree/is-widget":48}],42:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var isArray = require("x-is-array") var isObject = require("is-object") @@ -14427,7 +13543,7 @@ function appendPatch(apply, patch) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vtree/diff.js","/../node_modules/virtual-dom/node_modules/vtree") -},{"./handle-thunk":53,"./is-thunk":54,"./is-vnode":56,"./is-vtext":57,"./is-widget":58,"./vpatch":60,"1YiZ5S":19,"buffer":15,"is-object":44,"x-is-array":61}],53:[function(require,module,exports){ +},{"./handle-thunk":43,"./is-thunk":44,"./is-vnode":46,"./is-vtext":47,"./is-widget":48,"./vpatch":50,"1YiZ5S":19,"buffer":15,"is-object":34,"x-is-array":51}],43:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var isVNode = require("./is-vnode") var isVText = require("./is-vtext") @@ -14471,7 +13587,7 @@ function renderThunk(thunk, previous) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vtree/handle-thunk.js","/../node_modules/virtual-dom/node_modules/vtree") -},{"./is-thunk":54,"./is-vnode":56,"./is-vtext":57,"./is-widget":58,"1YiZ5S":19,"buffer":15}],54:[function(require,module,exports){ +},{"./is-thunk":44,"./is-vnode":46,"./is-vtext":47,"./is-widget":48,"1YiZ5S":19,"buffer":15}],44:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ module.exports = isThunk @@ -14480,7 +13596,7 @@ function isThunk(t) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vtree/is-thunk.js","/../node_modules/virtual-dom/node_modules/vtree") -},{"1YiZ5S":19,"buffer":15}],55:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],45:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ module.exports = isHook @@ -14490,7 +13606,7 @@ function isHook(hook) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vtree/is-vhook.js","/../node_modules/virtual-dom/node_modules/vtree") -},{"1YiZ5S":19,"buffer":15}],56:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],46:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var version = require("./version") @@ -14501,7 +13617,7 @@ function isVirtualNode(x) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vtree/is-vnode.js","/../node_modules/virtual-dom/node_modules/vtree") -},{"./version":59,"1YiZ5S":19,"buffer":15}],57:[function(require,module,exports){ +},{"./version":49,"1YiZ5S":19,"buffer":15}],47:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var version = require("./version") @@ -14512,7 +13628,7 @@ function isVirtualText(x) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vtree/is-vtext.js","/../node_modules/virtual-dom/node_modules/vtree") -},{"./version":59,"1YiZ5S":19,"buffer":15}],58:[function(require,module,exports){ +},{"./version":49,"1YiZ5S":19,"buffer":15}],48:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ module.exports = isWidget @@ -14521,12 +13637,12 @@ function isWidget(w) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vtree/is-widget.js","/../node_modules/virtual-dom/node_modules/vtree") -},{"1YiZ5S":19,"buffer":15}],59:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],49:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ module.exports = "1" }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vtree/version.js","/../node_modules/virtual-dom/node_modules/vtree") -},{"1YiZ5S":19,"buffer":15}],60:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],50:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var version = require("./version") @@ -14552,7 +13668,7 @@ VirtualPatch.prototype.version = version VirtualPatch.prototype.type = "VirtualPatch" }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/vtree/vpatch.js","/../node_modules/virtual-dom/node_modules/vtree") -},{"./version":59,"1YiZ5S":19,"buffer":15}],61:[function(require,module,exports){ +},{"./version":49,"1YiZ5S":19,"buffer":15}],51:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var nativeIsArray = Array.isArray var toString = Object.prototype.toString @@ -14564,14 +13680,14 @@ function isArray(obj) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/node_modules/x-is-array/index.js","/../node_modules/virtual-dom/node_modules/x-is-array") -},{"1YiZ5S":19,"buffer":15}],62:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],52:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var patch = require("vdom/patch") module.exports = patch }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-dom/patch.js","/../node_modules/virtual-dom") -},{"1YiZ5S":19,"buffer":15,"vdom/patch":50}],63:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"vdom/patch":40}],53:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ module.exports = AttributeHook; @@ -14592,7 +13708,7 @@ AttributeHook.prototype.hook = function (node, prop, prev) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/hooks/attribute-hook.js","/../node_modules/virtual-hyperscript/hooks") -},{"1YiZ5S":19,"buffer":15}],64:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],54:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var DataSet = require("data-set") @@ -14614,7 +13730,7 @@ DataSetHook.prototype.hook = function (node, propertyName) { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/hooks/data-set-hook.js","/../node_modules/virtual-hyperscript/hooks") -},{"1YiZ5S":19,"buffer":15,"data-set":69}],65:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"data-set":59}],55:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var DataSet = require("data-set") @@ -14636,7 +13752,7 @@ DataSetHook.prototype.hook = function (node, propertyName) { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/hooks/ev-hook.js","/../node_modules/virtual-hyperscript/hooks") -},{"1YiZ5S":19,"buffer":15,"data-set":69}],66:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"data-set":59}],56:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ module.exports = SoftSetHook; @@ -14655,7 +13771,7 @@ SoftSetHook.prototype.hook = function (node, propertyName) { }; }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/hooks/soft-set-hook.js","/../node_modules/virtual-hyperscript/hooks") -},{"1YiZ5S":19,"buffer":15}],67:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],57:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var VNode = require("vtree/vnode.js") var VText = require("vtree/vtext.js") @@ -14785,7 +13901,7 @@ function isChildren(x) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/index.js","/../node_modules/virtual-hyperscript") -},{"./hooks/data-set-hook.js":64,"./hooks/ev-hook.js":65,"./hooks/soft-set-hook.js":66,"./parse-tag.js":85,"1YiZ5S":19,"buffer":15,"error/typed":76,"vtree/is-thunk":77,"vtree/is-vhook":78,"vtree/is-vnode":79,"vtree/is-vtext":80,"vtree/is-widget":81,"vtree/vnode.js":83,"vtree/vtext.js":84}],68:[function(require,module,exports){ +},{"./hooks/data-set-hook.js":54,"./hooks/ev-hook.js":55,"./hooks/soft-set-hook.js":56,"./parse-tag.js":75,"1YiZ5S":19,"buffer":15,"error/typed":66,"vtree/is-thunk":67,"vtree/is-vhook":68,"vtree/is-vnode":69,"vtree/is-vtext":70,"vtree/is-widget":71,"vtree/vnode.js":73,"vtree/vtext.js":74}],58:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ module.exports = createHash @@ -14811,7 +13927,7 @@ function createHash(elem) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/data-set/create-hash.js","/../node_modules/virtual-hyperscript/node_modules/data-set") -},{"1YiZ5S":19,"buffer":15}],69:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],59:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var createStore = require("weakmap-shim/create-store") var Individual = require("individual") @@ -14833,7 +13949,7 @@ function DataSet(elem) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/data-set/index.js","/../node_modules/virtual-hyperscript/node_modules/data-set") -},{"./create-hash.js":68,"1YiZ5S":19,"buffer":15,"individual":70,"weakmap-shim/create-store":71}],70:[function(require,module,exports){ +},{"./create-hash.js":58,"1YiZ5S":19,"buffer":15,"individual":60,"weakmap-shim/create-store":61}],60:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var root = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? @@ -14855,7 +13971,7 @@ function Individual(key, value) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/data-set/node_modules/individual/index.js","/../node_modules/virtual-hyperscript/node_modules/data-set/node_modules/individual") -},{"1YiZ5S":19,"buffer":15}],71:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],61:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var hiddenStore = require('./hidden-store.js'); @@ -14876,7 +13992,7 @@ function createStore() { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/data-set/node_modules/weakmap-shim/create-store.js","/../node_modules/virtual-hyperscript/node_modules/data-set/node_modules/weakmap-shim") -},{"./hidden-store.js":72,"1YiZ5S":19,"buffer":15}],72:[function(require,module,exports){ +},{"./hidden-store.js":62,"1YiZ5S":19,"buffer":15}],62:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ module.exports = hiddenStore; @@ -14896,7 +14012,7 @@ function hiddenStore(obj, key) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/data-set/node_modules/weakmap-shim/hidden-store.js","/../node_modules/virtual-hyperscript/node_modules/data-set/node_modules/weakmap-shim") -},{"1YiZ5S":19,"buffer":15}],73:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],63:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ module.exports = function(obj) { if (typeof obj === 'string') return camelCase(obj); @@ -14959,7 +14075,7 @@ function reduce (xs, f, acc) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/error/node_modules/camelize/index.js","/../node_modules/virtual-hyperscript/node_modules/error/node_modules/camelize") -},{"1YiZ5S":19,"buffer":15}],74:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],64:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var nargs = /\{([0-9a-zA-Z]+)\}/g var slice = Array.prototype.slice @@ -14997,7 +14113,7 @@ function template(string) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/error/node_modules/string-template/index.js","/../node_modules/virtual-hyperscript/node_modules/error/node_modules/string-template") -},{"1YiZ5S":19,"buffer":15}],75:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],65:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ module.exports = extend @@ -15016,7 +14132,7 @@ function extend(target) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/error/node_modules/xtend/mutable.js","/../node_modules/virtual-hyperscript/node_modules/error/node_modules/xtend") -},{"1YiZ5S":19,"buffer":15}],76:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],66:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var camelize = require("camelize") var template = require("string-template") @@ -15068,7 +14184,7 @@ function TypedError(args) { }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/error/typed.js","/../node_modules/virtual-hyperscript/node_modules/error") -},{"1YiZ5S":19,"buffer":15,"camelize":73,"string-template":74,"xtend/mutable":75}],77:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15,"camelize":63,"string-template":64,"xtend/mutable":65}],67:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ module.exports = isThunk @@ -15077,7 +14193,7 @@ function isThunk(t) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/vtree/is-thunk.js","/../node_modules/virtual-hyperscript/node_modules/vtree") -},{"1YiZ5S":19,"buffer":15}],78:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],68:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ module.exports = isHook @@ -15087,7 +14203,7 @@ function isHook(hook) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/vtree/is-vhook.js","/../node_modules/virtual-hyperscript/node_modules/vtree") -},{"1YiZ5S":19,"buffer":15}],79:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],69:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var version = require("./version") @@ -15098,7 +14214,7 @@ function isVirtualNode(x) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/vtree/is-vnode.js","/../node_modules/virtual-hyperscript/node_modules/vtree") -},{"./version":82,"1YiZ5S":19,"buffer":15}],80:[function(require,module,exports){ +},{"./version":72,"1YiZ5S":19,"buffer":15}],70:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var version = require("./version") @@ -15109,7 +14225,7 @@ function isVirtualText(x) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/vtree/is-vtext.js","/../node_modules/virtual-hyperscript/node_modules/vtree") -},{"./version":82,"1YiZ5S":19,"buffer":15}],81:[function(require,module,exports){ +},{"./version":72,"1YiZ5S":19,"buffer":15}],71:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ module.exports = isWidget @@ -15118,12 +14234,12 @@ function isWidget(w) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/vtree/is-widget.js","/../node_modules/virtual-hyperscript/node_modules/vtree") -},{"1YiZ5S":19,"buffer":15}],82:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],72:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ module.exports = "1" }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/vtree/version.js","/../node_modules/virtual-hyperscript/node_modules/vtree") -},{"1YiZ5S":19,"buffer":15}],83:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],73:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var version = require("./version") var isVNode = require("./is-vnode") @@ -15190,7 +14306,7 @@ VirtualNode.prototype.version = version VirtualNode.prototype.type = "VirtualNode" }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/vtree/vnode.js","/../node_modules/virtual-hyperscript/node_modules/vtree") -},{"./is-vhook":78,"./is-vnode":79,"./is-widget":81,"./version":82,"1YiZ5S":19,"buffer":15}],84:[function(require,module,exports){ +},{"./is-vhook":68,"./is-vnode":69,"./is-widget":71,"./version":72,"1YiZ5S":19,"buffer":15}],74:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var version = require("./version") @@ -15204,7 +14320,7 @@ VirtualText.prototype.version = version VirtualText.prototype.type = "VirtualText" }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/node_modules/vtree/vtext.js","/../node_modules/virtual-hyperscript/node_modules/vtree") -},{"./version":82,"1YiZ5S":19,"buffer":15}],85:[function(require,module,exports){ +},{"./version":72,"1YiZ5S":19,"buffer":15}],75:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var classIdSplit = /([\.#]?[a-zA-Z0-9_:-]+)/ var notClassId = /^\.|#/ @@ -15257,7 +14373,7 @@ function parseTag(tag, props) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/parse-tag.js","/../node_modules/virtual-hyperscript") -},{"1YiZ5S":19,"buffer":15}],86:[function(require,module,exports){ +},{"1YiZ5S":19,"buffer":15}],76:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var attributeHook = require("./hooks/attribute-hook.js") var h = require("./index.js") @@ -15312,22 +14428,46 @@ function isChildren(x) { } }).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../node_modules/virtual-hyperscript/svg.js","/../node_modules/virtual-hyperscript") -},{"./hooks/attribute-hook.js":63,"./index.js":67,"1YiZ5S":19,"buffer":15}],87:[function(require,module,exports){ +},{"./hooks/attribute-hook.js":53,"./index.js":57,"1YiZ5S":19,"buffer":15}],77:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ /* * Renderer component. * Subscribes to vtree observables of all view components * and renders them as real DOM elements to the browser. */ -var Package = require('package.json'); -//var Sandbox = require('rxmarbles/views/sandbox'); -var OperatorsMenuView = require('rxmarbles/views/operators-menu'); -var SandboxView = require('rxmarbles/views/new-sandbox'); -var renderVTreeStream = require('rxmarbles/views/utils').renderVTreeStream; +var h = require('virtual-hyperscript'); +var VDOM = { + diff: require('virtual-dom/diff'), + patch: require('virtual-dom/patch') +}; var DOMDelegator = require('dom-delegator'); +var OperatorsMenuView = require('rxmarbles/views/operators-menu'); +var SandboxView = require('rxmarbles/views/sandbox'); +var Package = require('package.json'); var domDelegator; +function renderVTreeStream(vtree$, containerSelector) { + // Find and prepare the container + var container = document.querySelector(containerSelector); + if (container === null) { + console.error("Couldn't render into unknown '" + containerSelector + "'"); + return false; + } + container.innerHTML = ""; + // Make the DOM node bound to the VDOM node + var rootNode = document.createElement("div"); + container.appendChild(rootNode); + vtree$.startWith(h()) + .bufferWithCount(2, 1) + .subscribe(function(buffer) { + var oldVTree = buffer[0]; + var newVTree = buffer[1]; + rootNode = VDOM.patch(rootNode, VDOM.diff(oldVTree, newVTree)); + }); + return true; +}; + function renderAppVersionOnce() { var versionElement = document.querySelector("a.js-appVersion"); versionElement.textContent = "v" + Package.version; @@ -15353,6 +14493,6 @@ module.exports = { init: init }; -}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/fake_29948ce.js","/") -},{"1YiZ5S":19,"buffer":15,"dom-delegator":3,"package.json":28,"rxmarbles/views/new-sandbox":36,"rxmarbles/views/operators-menu":37,"rxmarbles/views/utils":41}]},{},[87]) -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9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ICAgdmFyIHJcbiAgICAgIGZ1bmN0aW9uIHBhcnNlQ2xhc3MgKHN0cmluZykge1xuICAgICAgICB2YXIgbSA9IHNwbGl0KHN0cmluZywgLyhbXFwuI10/W2EtekEtWjAtOV86LV0rKS8pXG4gICAgICAgIGlmKC9eXFwufCMvLnRlc3QobVsxXSkpXG4gICAgICAgICAgZSA9IGRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoJ2RpdicpXG4gICAgICAgIGZvckVhY2gobSwgZnVuY3Rpb24gKHYpIHtcbiAgICAgICAgICB2YXIgcyA9IHYuc3Vic3RyaW5nKDEsdi5sZW5ndGgpXG4gICAgICAgICAgaWYoIXYpIHJldHVyblxuICAgICAgICAgIGlmKCFlKVxuICAgICAgICAgICAgZSA9IGRvY3VtZW50LmNyZWF0ZUVsZW1lbnQodilcbiAgICAgICAgICBlbHNlIGlmICh2WzBdID09PSAnLicpXG4gICAgICAgICAgICBDbGFzc0xpc3QoZSkuYWRkKHMpXG4gICAgICAgICAgZWxzZSBpZiAodlswXSA9PT0gJyMnKVxuICAgICAgICAgICAgZS5zZXRBdHRyaWJ1dGUoJ2lkJywgcylcbiAgICAgICAgfSlcbiAgICAgIH1cblxuICAgICAgaWYobCA9PSBudWxsKVxuICAgICAgICA7XG4gICAgICBlbHNlIGlmKCdzdHJpbmcnID09PSB0eXBlb2YgbCkge1xuICAgICAgICBpZighZSlcbiAgICAgICAgICBwYXJzZUNsYXNzKGwpXG4gICAgICAgIGVsc2VcbiAgICAgICAgICBlLmFwcGVuZENoaWxkKHIgPSBkb2N1bWVudC5jcmVhdGVUZXh0Tm9kZShsKSlcbiAgICAgIH1cbiAgICAgIGVsc2UgaWYoJ251bWJlcicgPT09IHR5cGVvZiBsXG4gICAgICAgIHx8ICdib29sZWFuJyA9PT0gdHlwZW9mIGxcbiAgICAgICAgfHwgbCBpbnN0YW5jZW9mIERhdGVcbiAgICAgICAgfHwgbCBpbnN0YW5jZW9mIFJlZ0V4cCApIHtcbiAgICAgICAgICBlLmFwcGVuZENoaWxkKHIgPSBkb2N1bWVudC5jcmVhdGVUZXh0Tm9kZShsLnRvU3RyaW5nKCkpKVxuICAgICAgfVxuICAgICAgLy90aGVyZSBtaWdodCBiZSBhIGJldHRlciB3YXkgdG8gaGFuZGxlIHRoaXMuLi5cbiAgICAgIGVsc2UgaWYgKGlzQXJyYXkobCkpXG4gICAgICAgIGZvckVhY2gobCwgaXRlbSlcbiAgICAgIGVsc2UgaWYoaXNOb2RlKGwpKVxuICAgICAgICBlLmFwcGVuZENoaWxkKHIgPSBsKVxuICAgICAgZWxzZSBpZihsIGluc3RhbmNlb2YgVGV4dClcbiAgICAgICAgZS5hcHBlbmRDaGlsZChyID0gbClcbiAgICAgIGVsc2UgaWYgKCdvYmplY3QnID09PSB0eXBlb2YgbCkge1xuICAgICAgICBmb3IgKHZhciBrIGluIGwpIHtcbiAgICAgICAgICBpZignZnVuY3Rpb24nID09PSB0eXBlb2YgbFtrXSkge1xuICAgICAgICAgICAgaWYoL15vblxcdysvLnRlc3QoaykpIHtcbiAgICAgICAgICAgICAgaWYgKGUuYWRkRXZlbnRMaXN0ZW5lcil7XG4gICAgICAgICAgICAgICAgZS5hZGRFdmVudExpc3RlbmVyKGsuc3Vic3RyaW5nKDIpLCBsW2tdLCBmYWxzZSlcbiAgICAgICAgICAgICAgICBjbGVhbnVwRnVuY3MucHVzaChmdW5jdGlvbigpe1xuICAgICAgICAgICAgICAgICAgZS5yZW1vdmVFdmVudExpc3RlbmVyKGsuc3Vic3RyaW5nKDIpLCBsW2tdLCBmYWxzZSlcbiAgICAgICAgICAgICAgICB9KVxuICAgICAgICAgICAgICB9ZWxzZXtcbiAgICAgICAgICAgICAgICBlLmF0dGFjaEV2ZW50KGssIGxba10pXG4gICAgICAgICAgICAgICAgY2xlYW51cEZ1bmNzLnB1c2goZnVuY3Rpb24oKXtcbiAgICAgICAgICAgICAgICAgIGUuZGV0YWNoRXZlbnQoaywgbFtrXSlcbiAgICAgICAgICAgICAgICB9KVxuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAvLyBvYnNlcnZhYmxlXG4gICAgICAgICAgICAgIGVba10gPSBsW2tdKClcbiAgICAgICAgICAgICAgY2xlYW51cEZ1bmNzLnB1c2gobFtrXShmdW5jdGlvbiAodikge1xuICAgICAgICAgICAgICAgIGVba10gPSB2XG4gICAgICAgICAgICAgIH0pKVxuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgICBlbHNlIGlmKGsgPT09ICdzdHlsZScpIHtcbiAgICAgICAgICAgIGlmKCdzdHJpbmcnID09PSB0eXBlb2YgbFtrXSkge1xuICAgICAgICAgICAgICBlLnN0eWxlLmNzc1RleHQgPSBsW2tdXG4gICAgICAgICAgICB9ZWxzZXtcbiAgICAgICAgICAgICAgZm9yICh2YXIgcyBpbiBsW2tdKSAoZnVuY3Rpb24ocywgdikge1xuICAgICAgICAgICAgICAgIGlmKCdmdW5jdGlvbicgPT09IHR5cGVvZiB2KSB7XG4gICAgICAgICAgICAgICAgICAvLyBvYnNlcnZhYmxlXG4gICAgICAgICAgICAgICAgICBlLnN0eWxlLnNldFByb3BlcnR5KHMsIHYoKSlcbiAgICAgICAgICAgICAgICAgIGNsZWFudXBGdW5jcy5wdXNoKHYoZnVuY3Rpb24gKHZhbCkge1xuICAgICAgICAgICAgICAgICAgICBlLnN0eWxlLnNldFByb3BlcnR5KHMsIHZhbClcbiAgICAgICAgICAgICAgICAgIH0pKVxuICAgICAgICAgICAgICAgIH0gZWxzZVxuICAgICAgICAgICAgICAgICAgZS5zdHlsZS5zZXRQcm9wZXJ0eShzLCBsW2tdW3NdKVxuICAgICAgICAgICAgICB9KShzLCBsW2tdW3NdKVxuICAgICAgICAgICAgfVxuICAgICAgICAgIH0gZWxzZSBpZiAoay5zdWJzdHIoMCwgNSkgPT09IFwiZGF0YS1cIikge1xuICAgICAgICAgICAgRGF0YVNldChlKVtrLnN1YnN0cig1KV0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gICBmdW5jdGlvbiBhZGQodG9rZW4pIHtcbiAgICAgICAgdmFyIGxpc3QgPSBnZXRUb2tlbnMoKVxuICAgICAgICBpZiAoaW5kZXhvZihsaXN0LCB0b2tlbikgPiAtMSkge1xuICAgICAgICAgICAgcmV0dXJuXG4gICAgICAgIH1cbiAgICAgICAgbGlzdC5wdXNoKHRva2VuKVxuICAgICAgICBzZXRUb2tlbnMobGlzdClcbiAgICB9XG5cbiAgICBmdW5jdGlvbiByZW1vdmUodG9rZW4pIHtcbiAgICAgICAgdmFyIGxpc3QgPSBnZXRUb2tlbnMoKVxuICAgICAgICAgICAgLCBpbmRleCA9IGluZGV4b2YobGlzdCwgdG9rZW4pXG5cbiAgICAgICAgaWYgKGluZGV4ID09PSAtMSkge1xuICAgICAgICAgICAgcmV0dXJuXG4gICAgICAgIH1cblxuICAgICAgICBsaXN0LnNwbGljZShpbmRleCwgMSlcbiAgICAgICAgc2V0VG9rZW5zKGxpc3QpXG4gICAgfVxuXG4gICAgZnVuY3Rpb24gY29udGFpbnModG9rZW4pIHtcbiAgICAgICAgcmV0dXJuIGluZGV4b2YoZ2V0VG9rZW5zKCksIHRva2VuKSA+IC0xXG4gICAgfVxuXG4gICAgZnVuY3Rpb24gdG9nZ2xlKHRva2VuKSB7XG4gICAgICAgIGlmIChjb250YWlucyh0b2tlbikpIHtcbiAgICAgICAgICAgIHJlbW92ZSh0b2tlbilcbiAgICAgICAgICAgIHJldHVybiBmYWxzZVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgYWRkKHRva2VuKVxuICAgICAgICAgICAgcmV0dXJuIHRydWVcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGZ1bmN0aW9uICR0b1N0cmluZygpIHtcbiAgICAgICAgcmV0dXJuIGVsZW0uY2xhc3NOYW1lXG4gICAgfVxuXG4gICAgZnVuY3Rpb24gaXRlbShpbmRleCkge1xuICAgICAgICB2YXIgdG9rZW5zID0gZ2V0VG9rZW5zKClcbiAgICAgICAgc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4gICAgICAgICAgICByZXR1cm4gb2JqW2dsb2JhbElEXTtcclxuXHJcbiAgICAgICAgICBpZiAoIU9iamVjdC5pc0V4dGVuc2libGUob2JqKSlcclxuICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcihcIk9iamVjdCBtdXN0IGJlIGV4dGVuc2libGVcIik7XHJcblxyXG4gICAgICAgICAgdmFyIHN0b3JlID0gY3JlYXRlKG51bGwpO1xyXG4gICAgICAgICAgZGVmUHJvcChvYmosIGdsb2JhbElELCB7IHZhbHVlOiBzdG9yZSB9KTtcclxuICAgICAgICAgIHJldHVybiBzdG9yZTtcclxuICAgICAgICB9O1xyXG5cclxuICAgIC8vIGNvbW1vbiBwZXItb2JqZWN0IHN0b3JhZ2UgYXJlYSBtYWRlIHZpc2libGUgYnkgcGF0Y2hpbmcgZ2V0T3duUHJvcGVydHlOYW1lcydcclxuICAgIGRlZmluZShPYmplY3QsIGZ1bmN0aW9uIGdldE93blByb3BlcnR5TmFtZXMob2JqKXtcclxuICAgICAgdmFyIHByb3BzID0gZ2V0UHJvcHMob2JqKTtcclxuICAgICAgaWYgKGhhc093bi5jYWxsKG9iaiwgZ2xvYmFsSUQpKVxyXG4gICAgICAgIHByb3BzLnNwbGljZShwcm9wcy5pbmRleE9mKGdsb2JhbElEKSwgMSk7XHJcbiAgICAgIHJldHVybiBwcm9wcztcclxuICAgIH0pO1xyXG5cclxuICAgIGZ1bmN0aW9uIERhdGEoKXtcclxuICAgICAgdmFyIHB1aWQgPSBjcmVhdGVVSUQoKSxcclxuICAgICAgICAgIHNlY3JldCA9IHt9O1xyXG5cclxuICAgICAgdGhpcy51bmxvY2sgPSBmdW5jdGlvbihvYmope1xyXG4gICAgICAgIHZhciBzdG9yZSA9IHN0b3JhZ2Uob2JqKTtcclxuICAgICAgICBpZiAoaGFzT3duLmNhbGwoc3RvcmUsIHB1aWQpKVxyXG4gICAgICAgICAgcmV0dXJuIHN0b3JlW3B1aWRdKHNlY3JldCk7XHJcbl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IsXHJcbiAgICAgICAgICBpbmRleCA9IC0xLFxyXG4gICAgICAgICAgbGVuZ3RoID0gc2hhZG93ZWRQcm9wcy5sZW5ndGg7XHJcblxyXG4gICAgICBpZiAob2JqZWN0ID09PSAoY3RvciAmJiBjdG9yLnByb3RvdHlwZSkpIHtcclxuICAgICAgICB2YXIgY2xhc3NOYW1lID0gb2JqZWN0ID09PSBzdHJpbmdQcm90byA/IHN0cmluZ0NsYXNzIDogb2JqZWN0ID09PSBlcnJvclByb3RvID8gZXJyb3JDbGFzcyA6IHRvU3RyaW5nLmNhbGwob2JqZWN0KSxcclxuICAgICAgICAgICAgbm9uRW51bSA9IG5vbkVudW1Qcm9wc1tjbGFzc05hbWVdO1xyXG4gICAgICB9XHJcbiAgICAgIHdoaWxlICgrK2luZGV4IDwgbGVuZ3RoKSB7XHJcbiAgICAgICAga2V5ID0gc2hhZG93ZWRQcm9wc1tpbmRleF07XHJcbiAgICAgICAgaWYgKCEobm9uRW51bSAmJiBub25FbnVtW2tleV0pICYmIGhhc093blByb3BlcnR5LmNhbGwob2JqZWN0LCBrZXkpKSB7XHJcbiAgICAgICAgICByZXN1bHQucHVzaChrZXkpO1xyXG4gICAgICAgIH1cclxuICAgICAgfVxyXG4gICAgfVxyXG4gICAgcmV0dXJuIHJlc3VsdDtcclxuICB9XHJcblxyXG4gIGZ1bmN0aW9uIGludGVybmFsRm9yKG9iamVjdCwgY2FsbGJhY2ssIGtleXNGdW5jKSB7XHJcbiAgICB2YXIgaW5kZXggPSAtMSxcclxuICAgICAgcHJvcHMgPSBrZXlzRnVuYyhvYmplY3QpLFxyXG4gICAgICBsZW5ndGggPSBwcm9wcy5sZW5ndGg7XHJcblxyXG4gICAgd2hpbGUgKCsraW5kZXggPCBsZW5ndGgpIHtcclxuICAgICAgdmFyIGtleSA9IHByb3BzW2luZGV4XTtcclxuICAgICAgaWYgKGNhbGxiYWNrKG9iamVjdFtrZXldLCBrZXksIG9iamVjdCkgPT09IGZhbHNlKSB7XH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ibGUoZGlzcG9zYWJsZSkge1xyXG4gICAgICAgICAgICB0aGlzLmRpc3Bvc2FibGUgPSBkaXNwb3NhYmxlO1xyXG4gICAgICAgICAgICB0aGlzLmRpc3Bvc2FibGUuY291bnQrKztcclxuICAgICAgICAgICAgdGhpcy5pc0lubmVyRGlzcG9zZWQgPSBmYWxzZTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIElubmVyRGlzcG9zYWJsZS5wcm90b3R5cGUuZGlzcG9zZSA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgaWYgKCF0aGlzLmRpc3Bvc2FibGUuaXNEaXNwb3NlZCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmlzSW5uZXJEaXNwb3NlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuaXNJbm5lckRpc3Bvc2VkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmRpc3Bvc2FibGUuY291bnQtLTtcclxuICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5kaXNwb3NhYmxlLmNvdW50ID09PSAwICYmIHRoaXMuZGlzcG9zYWJsZS5pc1ByaW1hcnlEaXNwb3NlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLmRpc3Bvc2FibGUuaXNEaXNwb3NlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuZGlzcG9zYWJsZS51bmRlcmx5aW5nRGlzcG9zYWJsZS5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogSW5pdGlhbGl6ZXMgYSBuZXcgaW5zdGFuY2Ugb2YgdGhlIFJlZkNvdW50RGlzcG9zYWJsZSB3aXRoIHRoZSBzcGVjaWZpZWQgZGlzcG9zYWJsZS5cclxuICAgICAgICAgKiBAY29uc3RydWN0b3JcclxuICAgICAgICAgKiBAcGFyYW0ge0Rpc3Bvc2FibGV9IGRpc3Bvc2FibGUgVW5kZXJseWluZyBkaXNwb3NhYmxlLlxyXG4gICAgICAgICAgKi9cclxuICAgICAgICBmdW5jdGlvbiBSZWZDb3VudERpc3Bvc2FibGUoZGlzcG9zYWJsZSkge1xyXG4gICAgICAgICAgICB0aGlzLnVuZGVybHlpbmdEaXNwb3NhYmxlID0gZGlzcG9zYWJsZTtcclxuICAgICAgICAgICAgdGhpcy5pc0Rpc3Bvc2VkID0gZmFsc2U7XHJcbiAgICAgICAgICAgIHRoaXMuaXNQcmltYXJ5RGlzcG9zZWQgPSBmYWxzZTtcclxuICAgICAgICAgICAgdGhpcy5jb3VudCA9IDA7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBEaXNwb3NlcyB0aGUgdW5kZXJseWluZyBkaXNwb3NhYmxlIG9ubHkgd2hlbiBhbGwgZGVwZW5kZW50IGRpc3Bvc2FibGVzIGhhdmUgYmVlbiBkaXNwb3NlZFxyXG4gICAgICAgICAqL1xyXG4gICAgICAgIFJlZkNvdW50RGlzcG9zYWJsZS5wcm90b3R5cGUuZGlzcG9zZSA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgaWYgKCF0aGlzLmlzRGlzcG9zZWQpIHtcclxuICAgICAgICAgICAgICAgIGlmICghdGhpcy5pc1ByaW1hcnlEaXNwb3NlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuaXNQcmltYXJ5RGlzcG9zZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLmNvdW50ID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuaXNEaXNwb3NlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMudW5kZXJseWluZ0Rpc3Bvc2FibGUuZG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y5fc3RhdGUgPSAwO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgQ2hlY2tlZE9ic2VydmVyUHJvdG90eXBlLm9uRXJyb3IgPSBmdW5jdGlvbiAoZXJyKSB7XHJcbiAgICAgICAgICAgIHRoaXMuY2hlY2tBY2Nlc3MoKTtcclxuICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgIHRoaXMuX29ic2VydmVyLm9uRXJyb3IoZXJyKTtcclxuICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgdGhyb3cgZTtcclxuICAgICAgICAgICAgfSBmaW5hbGx5IHtcclxuICAgICAgICAgICAgICAgIHRoaXMuX3N0YXRlID0gMjtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIENoZWNrZWRPYnNlcnZlclByb3RvdHlwZS5vbkNvbXBsZXRlZCA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgdGhpcy5jaGVja0FjY2VzcygpO1xyXG4gICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5fb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgdGhyb3cgZTtcclxuICAgICAgICAgICAgfSBmaW5hbGx5IHtcclxuICAgICAgICAgICAgICAgIHRoaXMuX3N0YXRlID0gMjtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIENoZWNrZWRPYnNlcnZlclByb3RvdHlwZS5jaGVja0FjY2VzcyA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgaWYgKHRoaXMuX3N0YXRlID09PSAxKSB7IHRocm93IG5ldyBFcnJvcignUmUtZW50cmFuY3kgZGV0ZWN0ZWQnKTsgfVxyXG4gICAgICAgICAgICBpZiAodGhpcy5f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y2ggKGV4Y2VwdGlvbikge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBpZiAoaGFzQ3VycmVudEtleSkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGNvbXBhcmVyRXF1YWxzID0gY29tcGFyZXIoY3VycmVudEtleSwga2V5KTtcclxuICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaWYgKCFoYXNDdXJyZW50S2V5IHx8ICFjb21wYXJlckVxdWFscykge1xyXG4gICAgICAgICAgICAgICAgICAgIGhhc0N1cnJlbnRLZXkgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIGN1cnJlbnRLZXkgPSBrZXk7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHZhbHVlKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgb2JzZXJ2ZXIub25Db21wbGV0ZWQuYmluZChvYnNlcnZlcikpO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgLyoqXHJcbiAgICogIEludm9rZXMgYW4gYWN0aW9uIGZvciBlYWNoIGVsZW1lbnQgaW4gdGhlIG9ic2VydmFibGUgc2VxdWVuY2UgYW5kIGludm9rZXMgYW4gYWN0aW9uIHVwb24gZ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cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgIHZhciBpbmRleCA9IDA7XHJcblxyXG4gICAgICByZXR1cm4gc291cmNlLnN1YnNjcmliZShcclxuICAgICAgICBmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgdmFyIHJlc3VsdDtcclxuICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgIHJlc3VsdCA9IG9uTmV4dC5jYWxsKHRoaXNBcmcsIHgsIGluZGV4KyspO1xyXG4gICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgICBpc1Byb21pc2UocmVzdWx0KSAmJiAocmVzdWx0ID0gb2JzZXJ2YWJsZUZyb21Qcm9taXNlKHJlc3VsdCkpO1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdCk7XHJcbiAgICAgICAgfSxcclxuICAgICAgICBmdW5jdGlvbiAoZXJyKSB7XHJcbiAgICAgICAgICB2YXIgcmVzdWx0O1xyXG4gICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgcmVzdWx0ID0gb25FcnJvci5jYWxsKHRoaXNBcmcsIGVycik7XHJcbiAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgIH1cclxuICAgICAgICAgIGlzUHJvbWlzZShyZXN1bHQpICYmIChyZXN1bHQgPSBvYnNlcnZhYmxlRnJvbVByb21pc2UocmVzdWx0KSk7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0KTtcclxuICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgfSxcclxuICA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gICogQHJldHVybnMge09ic2VydmFibGV9IEFuIG9ic2VydmFibGUgc2VxdWVuY2UgdGhhdCBjb250YWlucyB0aGUgc3BlY2lmaWVkIGRlZmF1bHQgdmFsdWUgaWYgdGhlIHNvdXJjZSBpcyBlbXB0eTsgb3RoZXJ3aXNlLCB0aGUgZWxlbWVudHMgb2YgdGhlIHNvdXJjZSBpdHNlbGYuXHJcbiAgICAgKi9cclxuICAgIG9ic2VydmFibGVQcm90by5kZWZhdWx0SWZFbXB0eSA9IGZ1bmN0aW9uIChkZWZhdWx0VmFsdWUpIHtcclxuICAgICAgICB2YXIgc291cmNlID0gdGhpcztcclxuICAgICAgICBpZiAoZGVmYXVsdFZhbHVlID09PSB1bmRlZmluZWQpIHtcclxuICAgICAgICAgICAgZGVmYXVsdFZhbHVlID0gbnVsbDtcclxuICAgICAgICB9XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgZm91bmQgPSBmYWxzZTtcclxuICAgICAgICAgICAgcmV0dXJuIHNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgIGZvdW5kID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh4KTtcclxuICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKCFmb3VuZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChkZWZhdWx0VmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgfSk7XHJcbiAgICB9O1xyXG5cclx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sc2UsXHJcbiAgICAgICAgICAgIHdyaXRlciA9IG1hcC50cnlHZXRWYWx1ZShrZXkpO1xyXG4gICAgICAgICAgaWYgKCF3cml0ZXIpIHtcclxuICAgICAgICAgICAgd3JpdGVyID0gbmV3IFN1YmplY3QoKTtcclxuICAgICAgICAgICAgbWFwLnNldChrZXksIHdyaXRlcik7XHJcbiAgICAgICAgICAgIGZpcmVOZXdNYXBFbnRyeSA9IHRydWU7XHJcbiAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgaWYgKGZpcmVOZXdNYXBFbnRyeSkge1xyXG4gICAgICAgICAgICB2YXIgZ3JvdXAgPSBuZXcgR3JvdXBlZE9ic2VydmFibGUoa2V5LCB3cml0ZXIsIHJlZkNvdW50RGlzcG9zYWJsZSksXHJcbiAgICAgICAgICAgICAgZHVyYXRpb25Hcm91cCA9IG5ldyBHcm91cGVkT2JzZXJ2YWJsZShrZXksIHdyaXRlcik7XHJcbiAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgZHVyYXRpb24gPSBkdXJhdGlvblNlbGVjdG9yKGR1cmF0aW9uR3JvdXApO1xyXG4gICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgbWFwLmdldFZhbHVlcygpLmZvckVhY2goaGFuZGxlRXJyb3IoZSkpO1xyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoZ3JvdXApO1xyXG5cclxuICAgICAgICAgICAgdmFyIG1kID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgICAgIGdyb3VwRGlzcG9zYWJsZS5hZGQobWQpO1xyXG5cclxuICAgICAgICAgICAgdmFyIGV4cGlyZSA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICBtYXAucmVtb3ZlKGtleSkgJiYgd3JpdGVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgZ3JvdXBEaXNwb3NhYmxlLnJlbW92ZShtZCk7XHJcbiAgICAgICAgICAgIH07XHJcblxyXG4gICAgICAgICAgICBtZC5zZXREaXNwb3NhYmxlKGR1cmF0aW9uLnRha2UoMSkuc3Vic2NyaWJlKFxyXG4gICAgICAgICAgICAgIG5vb3AsXHJcbiAgICAgICAgICAgICAgZnVuY3Rpb24gKGV4bikge1xyXG4gICAgICAgICAgICAgICAgbWFwLmdldFZhbHVlcygpLmZvckVhY2goaGFuZGxlRXJyb3IoZXhuKSk7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4bik7XHJcbiAgICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgICBleHBpcmUpXHJcbiAgICAgICAgICAgICk7XHJcbiAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgdmFyIGVsZW1lbnQ7XHJcbiAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICBlbGVtZW50ID0gZWxlbWVudFNlbGVjdG9yKHgpO1xyXG4gICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICBtYXAuZ2V0VmFsdWVzKCkuZm9yRWFjaChoYW5kbGVFcnJvcihlKSk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICB3cml0ZXIub25OZXh0KGVsZW1lbnQpO1xyXG4gICAgICB9LCBmdW5jdGlvbiAoZXgpIHtcclxuICAgICAgICBtYXAuZ2V0VmFsdWVzKCkuZm9yRWFjaChoYW5kbGVFcnJvcihleCkpO1xyXG4gICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXgpO1xyXG4gICAgICB9LCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgbWFwL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JiAocmVzdWx0ID0gb2JzZXJ2YWJsZUZyb21Qcm9taXNlKHJlc3VsdCkpO1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdCk7XHJcbiAgICAgICAgfSxcclxuICAgICAgICBmdW5jdGlvbiAoZXJyKSB7XHJcbiAgICAgICAgICB2YXIgcmVzdWx0O1xyXG4gICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgcmVzdWx0ID0gb25FcnJvci5jYWxsKHRoaXNBcmcsIGVycik7XHJcbiAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgIH1cclxuICAgICAgICAgIGlzUHJvbWlzZShyZXN1bHQpICYmIChyZXN1bHQgPSBvYnNlcnZhYmxlRnJvbVByb21pc2UocmVzdWx0KSk7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0KTtcclxuICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgfSxcclxuICAgICAgICBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICB2YXIgcmVzdWx0O1xyXG4gICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgcmVzdWx0ID0gb25Db21wbGV0ZWQuY2FsbCh0aGlzQXJnKTtcclxuICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgICAgaXNQcm9taXNlKHJlc3VsdCkgJiYgKHJlc3VsdCA9IG9ic2VydmFibGVGcm9tUHJvbWlzZShyZXN1bHQpKTtcclxuICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChyZXN1bHQpO1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0Z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AgICByZXR1cm4gc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgIHZhciBjb21wYXJpc29uLCBrZXk7XHJcbiAgICAgICAgdHJ5IHtcclxuICAgICAgICAgIGtleSA9IGtleVNlbGVjdG9yKHgpO1xyXG4gICAgICAgIH0gY2F0Y2ggKGV4KSB7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4KTtcclxuICAgICAgICAgIHJldHVybjtcclxuICAgICAgICB9XHJcbiAgICAgICAgY29tcGFyaXNvbiA9IDA7XHJcbiAgICAgICAgaWYgKCFoYXNWYWx1ZSkge1xyXG4gICAgICAgICAgaGFzVmFsdWUgPSB0cnVlO1xyXG4gICAgICAgICAgbGFzdEtleSA9IGtleTtcclxuICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgY29tcGFyaXNvbiA9IGNvbXBhcmVyKGtleSwgbGFzdEtleSk7XHJcbiAgICAgICAgICB9IGNhdGNoIChleDEpIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleDEpO1xyXG4gICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGlmIChjb21wYXJpc29uID4gMCkge1xyXG4gICAgICAgICAgbGFzdEtleSA9IGtleTtcclxuICAgICAgICAgIGxpc3QgPSBbXTtcclxuICAgICAgICB9XHJcbiAgICAgICAgaWYgKGNvbXBhcmlzb24gPj0gMCkgeyBsaXN0LnB1c2goeCk7IH1cclxuICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIG9ic2VydmVyLm9uTmV4dChsaXN0KTtcclxuICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICB9KTtcclxuICAgIH0pO1xyXG4gIH1cclxuXHJcbiAgICBmdW5j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W5jZSBvZiB2YWx1ZXMuXHJcbiAgICAgKi9cclxuICAgIG9ic2VydmFibGVQcm90by5hdmVyYWdlID0gZnVuY3Rpb24gKGtleVNlbGVjdG9yLCB0aGlzQXJnKSB7XHJcbiAgICAgICAgcmV0dXJuIGtleVNlbGVjdG9yID9cclxuICAgICAgICAgICAgdGhpcy5zZWxlY3Qoa2V5U2VsZWN0b3IsIHRoaXNBcmcpLmF2ZXJhZ2UoKSA6XHJcbiAgICAgICAgICAgIHRoaXMuc2Nhbih7XHJcbiAgICAgICAgICAgICAgICBzdW06IDAsXHJcbiAgICAgICAgICAgICAgICBjb3VudDogMFxyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAocHJldiwgY3VyKSB7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4ge1xyXG4gICAgICAgICAgICAgICAgICAgIHN1bTogcHJldi5zdW0gKyBjdXIsXHJcbiAgICAgICAgICAgICAgICAgICAgY291bnQ6IHByZXYuY291bnQgKyAxXHJcbiAgICAgICAgICAgICAgICB9O1xyXG4gICAgICAgICAgICB9KS5maW5hbFZhbHVlKCkuc2VsZWN0KGZ1bmN0aW9uIChzKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAocy5jb3VudCA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcignVGhlIGlucHV0IHNlcXVlbmNlIHdhcyBlbXB0eScpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgcmV0dXJuIHMuc3VtIC8gcy5jb3VudDtcclxuICAgICAgICAgICAgfSk7XHJcbiAgICB9O1xyXG5cclxuICBmdW5jdGlvbiBzZXF1ZW5jZUVxdWFsQXJyYXkoZmlyc3QsIHNlY29uZCwgY29tcGFyZXIpIHtcclxuICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgdmFyIGNvdW50ID0gMCwgbGV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KTtcclxuICAgIGlmIChBcnJheS5pc0FycmF5KHNlY29uZCkpIHtcclxuICAgICAgcmV0dXJuIHNlcXVlbmNlRXF1YWxBcnJheShmaXJzdCwgc2Vjb25kLCBjb21wYXJlcik7XHJcbiAgICB9XHJcbiAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgIHZhciBkb25lbCA9IGZhbHNlLCBkb25lciA9IGZhbHNlLCBxbCA9IFtdLCBxciA9IFtdO1xyXG4gICAgICB2YXIgc3Vic2NyaXB0aW9uMSA9IGZpcnN0LnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgIHZhciBlcXVhbCwgdjtcclxuICAgICAgICBpZiAocXIubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgdiA9IHFyLnNoaWZ0KCk7XHJcbiAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICBlcXVhbCA9IGNvbXBhcmVyKHYsIHgpO1xyXG4gICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgICBpZiAoIWVxdWFsKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChmYWxzZSk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgfSBlbHNlIGlmIChkb25lcikge1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGZhbHNlKTtcclxuICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgIHFsLnB1c2goeCk7XHJcbiAgICAgICAgfVxyXG4gICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ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1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgIH0gZWxzZSBpZiAoZG9uZWwpIHtcclxuICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChmYWxzZSk7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICBxci5wdXNoKHgpO1xyXG4gICAgICAgIH1cclxuICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIGRvbmVyID0gdHJ1ZTtcclxuICAgICAgICBpZiAocXIubGVuZ3RoID09PSAwKSB7XHJcbiAgICAgICAgICBpZiAocWwubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoZmFsc2UpO1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgfSBlbHNlIGlmIChkb25lbCkge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQodHJ1ZSk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgfVxyXG4gICAgICB9KTtcclxuICAgICAgcmV0dXJuIG5ldyBDb21wb3NpdGVEaXNwb3NhYmxlKHN1YnNjcmlwdGlvbjEsIHN1YnNjcmlwdGlvbjIpO1xyXG4gICAgfSk7XHJcbiAgfTtcclxuXHJcbiAgICBmdW5jdGlvbiBlbGVtZW50QXRPckRlZmF1bHQoc291cmNlLCBpbmRleCwgaGFzRGVmYXVsdCwgZGVmYXVsdFZhbHVlKSB7XHJcbiAgICAgICAgaWYgKGluZGV4IDwgMCkge1xyXG4gICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoYXJndW1lbnRPdXRPZlJhbmdlKTtcclxuICAgICAgICB9XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgaSA9IGluZGV4O1xyXG4gICAgICAgICAgICByZXR1cm4gc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKGkgPT09IDApIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGktLTtcclxuICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKCFoYXNEZWZhdWx0KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihuZXcgRXJyb3IoYXJndW1lbnRPdXRPZlJhbmdlKSk7XHJcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChkZWZhdWx0VmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfVxyXG5cclxuICAgIC8qKlxyXG4gICAgICogUmV0dXJucyB0aGUgZWxlbWVudCBhdCBhIHNwZWNpZmllZCBpbmRleCBpbiBhIHNlcXVlbmNlLlxyXG4gICAgICogQGV4YW1wbGVcclxuICAgICAqIHZhciByZXMgPSBzb3VyY2UuZWxlbWVudEF0KDUpO1xyXG4gICAgICogQHBhcmFtIHtOdW1iZXJ9IGluZGV4IFRoZSB6ZXJvLWJhc2VkIGluZGV4IG9mIHRo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dFZhbHVlKTtcclxuICB9O1xyXG5cclxuICAgIGZ1bmN0aW9uIGZpcnN0T3JEZWZhdWx0QXN5bmMoc291cmNlLCBoYXNEZWZhdWx0LCBkZWZhdWx0VmFsdWUpIHtcclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHJldHVybiBzb3VyY2Uuc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoIWhhc0RlZmF1bHQpIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKG5ldyBFcnJvcihzZXF1ZW5jZUNvbnRhaW5zTm9FbGVtZW50cykpO1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoZGVmYXVsdFZhbHVlKTtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICB9KTtcclxuICAgIH1cclxuXHJcbiAgICAvKipcclxuICAgICAqIFJldHVybnMgdGhlIGZpcnN0IGVsZW1lbnQgb2YgYW4gb2JzZXJ2YWJsZSBzZXF1ZW5jZSB0aGF0IHNhdGlzZmllcyB0aGUgY29uZGl0aW9uIGluIHRoZSBwcmVkaWNhdGUgaWYgcHJlc2VudCBlbHNlIHRoZSBmaXJzdCBpdGVtIGluIHRoZSBzZXF1ZW5jZS5cclxuICAgICAqI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ZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgdmFyIHNob3VsZFJ1bjtcclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgc2hvdWxkUnVuID0gcHJlZGljYXRlLmNhbGwodGhpc0FyZywgeCwgaSwgc291cmNlKTtcclxuICAgICAgICAgICAgICAgIH0gY2F0Y2goZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaWYgKHNob3VsZFJ1bikge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh5aWVsZEluZGV4ID8gaSA6IHgpO1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgIGkrKztcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHlpZWxkSW5kZXggPyAtMSA6IHVuZGVmaW5lZCk7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICB9KTtcclxuICAgIH1cclxuXHJcbiAgICAvKipcclxuICAgICAqIFNlYXJjaGVzIGZvciBhbiBlbGVtZW50IHRoYXQgbWF0Y2hlcyB0aGUgY29uZGl0aW9ucyBkZWZpbmVkIGJ5IHRoZSBzcGVjaWZpZWQgcHJlZGljYXRlLCBhbmQgcmV0dXJucyB0aGUgZmlyc3Qgb2NjdXJyZW5jZSB3aXRoa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W5nbGUgdmFsdWUgb2YgYSBNYXAgY29udGFpbmluZyB0aGUgdmFsdWVzIGZyb20gdGhlIG9ic2VydmFibGUgc2VxdWVuY2UuXHJcbiAgICAqL1xyXG4gICAgb2JzZXJ2YWJsZVByb3RvLnRvTWFwID0gZnVuY3Rpb24gKGtleVNlbGVjdG9yLCBlbGVtZW50U2VsZWN0b3IpIHtcclxuICAgICAgdmFyIHNvdXJjZSA9IHRoaXM7XHJcbiAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICB2YXIgbSA9IG5ldyByb290Lk1hcCgpO1xyXG4gICAgICAgIHJldHVybiBzb3VyY2Uuc3Vic2NyaWJlKFxyXG4gICAgICAgICAgZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgdmFyIGtleTtcclxuICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICBrZXkgPSBrZXlTZWxlY3Rvcih4KTtcclxuICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICB2YXIgZWxlbWVudCA9IHg7XHJcbiAgICAgICAgICAgIGlmIChlbGVtZW50U2VsZWN0b3IpIHtcclxuICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgZWxlbWVudCA9IGVsZW1lbnRTZWxlY3Rvcih4KTtcclxuICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgbS5zZXQoa2V5LCBlbGVtZW50KTtcclxuICAgICAgICAgIH0sXHJcbiAgICAgICAgICBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLFxyXG4gICAgICAgICAgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQobSk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICB9KTtcclxuICAgICAgfSk7XHJcbiAgICB9O1xyXG4gIH1cclxuXHJcbiAgdmFyIGZuU3RyaW5nID0gJ2Z1bmN0aW9uJztcclxuXHJcbiAgZnVuY3Rpb24gdG9UaHVuayhvYmosIGN0eCkge1xyXG4gICAgaWYgKEFycmF5LmlzQXJyYXkob2JqKSkge1xyXG4gICAgICByZXR1cm4gb2JqZWN0VG9UaHVuay5jYWxsKGN0eCwgb2JqKTtcclxuICAgIH1cclxuXHJcbiAgICBpZiAoaXNHZW5lcmF0b3JGdW5jdGlvbihvYmopKSB7XHJcbiAgICAgIHJldHVybiBvYnNlcnZhYmxlU3Bhd24ob2JqLmNhbGwoY3R4KSk7XHJcbiAgICB9XHJcblxyXG4gICAgaWYgKGlzR2VuZXJhdG9yKG9iaikpIHtcclxuICAgICAgcmV0dXJuIG9ic2VydmFibGVTcGF3bihvYmopO1xyXG4gICAgfVxyXG5cclxuICAgIGlmIChpc09ic2VydmFibGUob2JqKSkge1xyXG4gICAgICByZXR1cm4gb2JzZXJ2YWJsZVRvVGh1bmsob2JqKTtcclxuICAgIH1cclxuXHJcbiAgICBpZiAoaXNQcm9taXNlKG9iaikpIHtcclxuICAgICAgcmV0dXJuIHByb21pc2VUb1RodW5rKG9iaik7XHJcbiAgICB9XHJcblxyXG4gICAgaWYgKHR5cGVvZiBvYmogPT09IGZuU3RyaW5nKSB7XHJcbiAgICAgIHJldHVybiBvYmo7XHJcbiAgICB9XHJcblxyXG4gICAgaWYgKGlzT2JqZWN0KG9iaikgfHwgQXJyYXkuaXNBcnJheShvYmopKSB7XHJcbiA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gICAgIH1cclxuXHJcbiAgICAgICAgICBmbi5jYWxsKGN0eCwgZnVuY3Rpb24oZXJyLCByZXMpe1xyXG4gICAgICAgICAgICBpZiAoZmluaXNoZWQpIHsgcmV0dXJuOyB9XHJcblxyXG4gICAgICAgICAgICBpZiAoZXJyKSB7XHJcbiAgICAgICAgICAgICAgZmluaXNoZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgIHJldHVybiBkb25lKGVycik7XHJcbiAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgIHJlc3VsdHNba2V5XSA9IHJlcztcclxuICAgICAgICAgICAgLS1wZW5kaW5nIHx8IGRvbmUobnVsbCwgcmVzdWx0cyk7XHJcbiAgICAgICAgICB9KTtcclxuICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICBmaW5pc2hlZCA9IHRydWU7XHJcbiAgICAgICAgICBkb25lKGUpO1xyXG4gICAgICAgIH1cclxuICAgICAgfVxyXG4gICAgfVxyXG4gIH1cclxuXHJcbiAgZnVuY3Rpb24gb2JzZXJ2YWJsZVRvVGhpbmsob2JzZXJ2YWJsZSkge1xyXG4gICAgcmV0dXJuIGZ1bmN0aW9uIChmbikge1xyXG4gICAgICB2YXIgdmFsdWUsIGhhc1ZhbHVlID0gZmFsc2U7XHJcbiAgICAgIG9ic2VydmFibGUuc3Vic2NyaWJlKFxyXG4gICAgICAgIGZ1bmN0aW9uICh2KSB7XHJcbiAgICAgICAgICB2YWx1ZSA9IHY7XHJcbiAgICAgICAgICBoYXNWYWx1ZSA9IHRydWU7XHJcbiAgICAgICAgfSxcclxuICAgICAgICBmbixcclxuICAgICAgICBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICBoYXNWYWx1ZSAmJiBmbihudWxsLCB2YWx1ZSk7XHJcbiAgICAgICAgfSk7XHJcbiAgICB9XHJcbiAgfVxyXG5cclxuICBmdW5jdGlvbiBwcm9taXNlVG9UaHVuayhwcm9taXNlKSB7XHJcbiAgICByZXR1cm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HJcbiAgICAgICAgaWYgKGVycikge1xyXG4gICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgcmV0ID0gZ2VuLnRocm93KGVycik7XHJcbiAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgIHJldHVybiBleGl0KGUpO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgaWYgKCFlcnIpIHtcclxuICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgIHJldCA9IGdlbi5uZXh0KHJlcyk7XHJcbiAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgIHJldHVybiBleGl0KGUpO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgaWYgKHJldC5kb25lKSAge1xyXG4gICAgICAgICAgcmV0dXJuIGV4aXQobnVsbCwgcmV0LnZhbHVlKTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIHJldC52YWx1ZSA9IHRvVGh1bmsocmV0LnZhbHVlLCBjdHgpO1xyXG5cclxuICAgICAgICBpZiAodHlwZW9mIHJldC52YWx1ZSA9PT0gZm5TdHJpbmcpIHtcclxuICAgICAgICAgIHZhciBjYWxsZWQgPSBmYWxzZTtcclxuICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgIHJldC52YWx1ZS5jYWxsKGN0eCwgZnVuY3Rpb24oKXtcclxuICAgICAgICAgICAgICBpZiAoY2FsbGVkKSB7XHJcbiAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICBjYWxsZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgIG5leHQuYXBwbHkoY3R4LCBhcmd1bWVudHMpO1xyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgdGltZW91dFNjaGVkdWxlci5zY2hlZHVsZShmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgaWYgKGNhbGxlZCkge1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgY2FsbGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICBuZXh0LmNhbGwoY3R4LCBlKTtcclxuICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICAvLyBOb3Qgc3VwcG9ydGVkXHJcbiAgICAgICAgbmV4dChuZXcgVHlwZUVycm9yKCdSeC5zcGF3biBvbmx5IHN1cHBvcnRzIGEgZnVuY3Rpb24sIFByb21pc2UsIE9ic2VydmFibGUsIE9iamVjdCBvciBBcnJheS4nKSk7XHJcbiAgICAgIH1cclxuICAgIH1cclxuICB9O1xyXG5cclxuICAvKipcclxuICAgKiBUYWtlcyBhIGZ1bmN0aW9uIHdpdGggYSBjYWxsYmFjayBhbmQgdHVybnMgaXQgaW50byBhIHRodW5rLlxyXG4gICAqIEBwYXJhbSB7RnVuY3Rpb259IEEgZnVuY3Rpb24gd2l0aCBhIGNhbGxiYWNrIHN1Y2ggYXMgZnMucmVhZEZpbGVcclxuICAgKiBAcmV0dXJucyB7RnVuY3Rpb259IEEgZnVuY3Rpb24sIHdoZW4gZXhlY3V0ZWQgd2lsbCBjb250aW51ZSB0aGUgc3RhdGUgbWFjaGluZS5cclxuICAgKi9cclxuICBSeC5kZW5vZGlmeSA9IGZ1bmN0aW9uIChmbikge1xyXG4gICAgcmV0dXJuIGZ1bmN0aW9uICgpe1xyXG4gICAgICB2YXIgYXJncyA9IHNsaWNlLmNhbGwoYXJndW1lbnRzKSxcclxuICAgICAgICByZXN1bHRzLFxyXG4gICAgICAgIGNhbGxlZCxcclxuICAgICAgICBjYWxsYmFjaztcclxuXHJcbiAgICAgIGFyZ3MucHVzaChmdW5jdGlvbigpe1xy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mxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgIGZ1bmN0aW9uIGhhbmRsZXIoZSkge1xyXG4gICAgICAgICAgdmFyIHJlc3VsdHMgPSBlO1xyXG5cclxuICAgICAgICAgIGlmIChzZWxlY3Rvcikge1xyXG4gICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgIHJlc3VsdHMgPSBzZWxlY3Rvcihhcmd1bWVudHMpO1xyXG4gICAgICAgICAgICB9IGNhdGNoIChlcnIpIHtcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGVycik7XHJcbiAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0cyk7XHJcbiAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICBpZiAocmVzdWx0cy5sZW5ndGggPD0gMSkge1xyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dC5hcHBseShvYnNlcnZlciwgcmVzdWx0cyk7XHJcbiAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdHMpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGFyZ3MucHVzaChoYW5kbGVyKTtcclxuICAgICAgICBmdW5jLmFwcGx5KGNvbnRleHQsIGFyZ3MpO1xyXG4gICAgICB9KS5wdWJsaXNoTGFzdCgpLnJlZkNvdW50KCk7XHJcbiAgICB9O1xyXG4gIH07XHJcblxyXG4gIC8qKlxyXG4gICAqIENvbnZlcnRzIGEgTm9kZS5qcyBjYWxsYmFjayBzdHlsZSBmdW5jdGlvbiB0byBhbiBvYnNlcnZhYmxlIHNlcXVlbmNlLiAgVGhpcyBtd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kVycm9yKGVycik7XHJcbiAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICB2YXIgcmVzdWx0cyA9IHNsaWNlLmNhbGwoYXJndW1lbnRzLCAxKTtcclxuXHJcbiAgICAgICAgICBpZiAoc2VsZWN0b3IpIHtcclxuICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICByZXN1bHRzID0gc2VsZWN0b3IocmVzdWx0cyk7XHJcbiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0cyk7XHJcbiAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICBpZiAocmVzdWx0cy5sZW5ndGggPD0gMSkge1xyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dC5hcHBseShvYnNlcnZlciwgcmVzdWx0cyk7XHJcbiAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdHMpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGFyZ3MucHVzaChoYW5kbGVyKTtcclxuICAgICAgICBmdW5jLmFwcGx5KGNvbnRleHQsIGFyZ3MpO1xyXG4gICAgICB9KS5wdWJsaXNoTGFzdCgpLnJlZkNvdW50KCk7XHJcbiAgICB9O1xyXG4gIH07XHJcblxyXG4gIGZ1bmN0aW9uIGNyZWF0ZUxpc3RlbmVyIChlbGVtZW50LCBuYW1lLCBoYW5kbGVyKSB7XHJcbiAgICBpZiAoZWxlbWVudC5hZGRFdmVudExpc3RlbmVyK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HNob3VsZEZpcmUpIHtcclxuICAgICAgICAgICAgcmV0dXJuIHsgZGF0YTogZGF0YSwgc2hvdWxkRmlyZTogc2hvdWxkRmlyZSB9O1xyXG4gICAgICAgICAgfSlcclxuICAgICAgICAgIC5zdWJzY3JpYmUoXHJcbiAgICAgICAgICAgIGZ1bmN0aW9uIChyZXN1bHRzKSB7XHJcbiAgICAgICAgICAgICAgaWYgKHByZXZpb3VzU2hvdWxkRmlyZSAhPT0gdW5kZWZpbmVkICYmIHJlc3VsdHMuc2hvdWxkRmlyZSAhPSBwcmV2aW91c1Nob3VsZEZpcmUpIHtcclxuICAgICAgICAgICAgICAgIHByZXZpb3VzU2hvdWxkRmlyZSA9IHJlc3VsdHMuc2hvdWxkRmlyZTtcclxuICAgICAgICAgICAgICAgIC8vIGNoYW5nZSBpbiBzaG91bGRGaXJlXHJcbiAgICAgICAgICAgICAgICBpZiAocmVzdWx0cy5zaG91bGRGaXJlKSB7XHJcbiAgICAgICAgICAgICAgICAgIHdoaWxlIChxLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocS5zaGlmdCgpKTtcclxuICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICBwcmV2aW91c1Nob3VsZEZpcmUgPSByZXN1bHRzLnNob3VsZEZpcmU7XHJcbiAgICAgICAgICAgICAgICAvLyBuZXcgZGF0YVxyXG4gICAgICAgICAgICAgICAgaWYgKHJlc3VsdHMuc2hvdWxkRmlyZSkge1xyXG4gICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0cy5kYXRhKTtcclxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgIHEucHVzaChyZXN1bHRzLmRhdGEpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgZnVuY3Rpb24gKGVycikge1xyXG4gICAgICAgICAgICAgIC8vIEVtcHR5IGJ1ZmZlciBiZWZvcmUgc2VuZGluZyBlcnJvclxyXG4gICAgICAgICAgICAgIHdoaWxlIChxLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChxLnNoaWZ0KCkpO1xyXG4gICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGVycik7XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAvLyBFbXB0eSBidWZmZXIgYmVmb3JlIHNlbmRpbmcgY29tcGxldGlvblxyXG4gICAgICAgICAgICAgIHdoaWxlIChxLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChxLnNoaWZ0KCkpO1xyXG4gICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICApO1xyXG4gICAgICByZXR1cm4gc3Vic2NyaXB0aW9uO1xyXG4gICAgfVxyXG5cclxuICAgIGZ1bmN0aW9uIFBhdXNhYmxlQnVmZmVyZWRPYnNlcnZhYmxlKHNvdXJjZSwgcGF1c2VyKSB7XHJcbiAgICAgIHRoaXMuc291cmNlID0gc291cmNlO1xyXG4gICAgICB0aGlzLmNvbnRyb2xsZXIgPSBuZXcgU3ViamVjdCgpO1xyXG5cclxuICAgICAgaWYgKHBhdXNlciAmJiBwYXVzZXIuc3Vic2NyaWJlKSB7XHJcbiAgICAgICAgdGhpcy5wYXVzZXIgPSB0aGlzLmNvbnRyb2xsZXIubWVyZ2UocGF1c2VyKTtcclxuICAgICAgfSBlbHNlIHtcclxuICAgICAgICB0aGlzLnBhdXNlciA9I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24gKF9zdXBlcikge1xyXG5cclxuICAgICAgICBmdW5jdGlvbiBzdWJzY3JpYmUgKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHJldHVybiB0aGlzLnN1YmplY3Quc3Vic2NyaWJlKG9ic2VydmVyKTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGluaGVyaXRzKENvbnRyb2xsZWRTdWJqZWN0LCBfc3VwZXIpO1xyXG5cclxuICAgICAgICBmdW5jdGlvbiBDb250cm9sbGVkU3ViamVjdChlbmFibGVRdWV1ZSkge1xyXG4gICAgICAgICAgICBpZiAoZW5hYmxlUXVldWUgPT0gbnVsbCkge1xyXG4gICAgICAgICAgICAgICAgZW5hYmxlUXVldWUgPSB0cnVlO1xyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICBfc3VwZXIuY2FsbCh0aGlzLCBzdWJzY3JpYmUpO1xyXG4gICAgICAgICAgICB0aGlzLnN1YmplY3QgPSBuZXcgU3ViamVjdCgpO1xyXG4gICAgICAgICAgICB0aGlzLmVuYWJsZVF1ZXVlID0gZW5hYmxlUXVldWU7XHJcbiAgICAgICAgICAgIHRoaXMucXVldWUgPSBlbmFibGVRdWV1ZSA/IFtdIDogbnVsbDtcclxuICAgICAgICAgICAgdGhpcy5yZXF1ZXN0ZWRDb3VudCA9IDA7XHJcbiAgICAgICAgICAgIHRoaXMucmVxdWVzdGVkRGlzcG9zYWJsZSA9IGRpc3Bvc2FibGVFbXB0eTtcclxuICAgICAgICAgICAgdGhpcy5lcnJvciA9IG51bGw7XHJcbiAgICAgICAgICAgIHRoaXMuaGFzRmFpbGVkID0gZmFsc2U7XHJcbiAgICAgICAgICAgIHRoaXMuaGFzQ29tcGxldGVkID0gZmFsc2U7XHJcbiAgICAgICAgICAgIHRoaXMuY29udHJvbGxlZERpc3Bvc2FibGUgPSBkaXNwb3NhYmxlRW1wdHk7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBhZGRQcm9wZXJ0aWVzKENvbnRyb2xsZWRTdWJqZWN0LnByb3RvdHlwZSwgT2JzZXJ2ZXIsIHtcclxuICAgICAgICAgICAgb25Db21wbGV0ZWQ6IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgICAgIHRoaXMuaGFzQ29tcGxldGVkID0gdHJ1ZTtcclxuXHJcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuZW5hYmxlUXVldWUgfHwgdGhpcy5xdWV1ZS5sZW5ndGggPT09IDApIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLnN1YmplY3Qub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgb25FcnJvcjogZnVuY3Rpb24gKGVycm9yKSB7XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmhhc0ZhaWxlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmVycm9yID0gZXJyb3I7XHJcblxyXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmVuYWJsZVF1ZXVlIHx8IHRoaXMucXVldWUubGVuZ3RoID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5zdWJqZWN0Lm9uRXJyb3IoZXJyb3IpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICBvbk5leHQ6IGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgdmFyIGhhc1JlcXVlc3RlZCA9IGZhbHNlO1xyXG5cclxuICAgICAgICAgICAgICAgIGlmICh0aGlzLnJlcXVlc3RlZENvdW50ID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMuZW5hYmxlUXVldWUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5xdWV1ZS5wdXNoKHZhbHVlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLnJlcXVlc3RlZENvdW50ICE9PSAtMSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5yZXF1ZXN0ZWRDb3VudC0tID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLmRpc3Bvc2VDdXJyZW50UmVxdWVzdCgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIGhhc1JlcXVlc3RlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgaWYgKGhhc1JlcXVlc3RlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuc3ViamVjdC5vbk5leHQodmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICBfcHJvY2Vzc1JlcXVlc3Q6IGZ1bmN0aW9uIChudW1iZXJPZkl0ZW1zKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5lbmFibGVRdWV1ZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIC8vY29uc29sZS5sb2coJ3F1ZXVlIGxlbmd0aCcsIHRoaXMucXVldWUubGVuZ3RoKTtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgd2hpbGUgKHRoaXMucXVldWUubGVuZ3RoID49IG51bWJlck9mSXRlbXMgJiYgbnVtYmVyT2ZJdGVtcyA+IDApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgLy9jb25zb2xlLmxvZygnbnVtYmVyIG9mIGl0ZW1zJywgbnVtYmVyT2ZJdGVtcyk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuc3ViamVjdC5vbk5leHQodGhpcy5xdWV1ZS5zaGlmdCgpKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgbnVtYmVyT2ZJdGVtcy0tO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMucXVldWUubGVuZ3RoICE9PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiB7IG51bWJlck9mSXRlbXM6IG51bWJlck9mSXRlbXMsIHJldHVyblZhbHVlOiB0cnVlIH07XHJcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHsgbnVtYmVyT2ZJdGVtczogbnVtYmVyT2ZJdGVtcywgcmV0dXJuVmFsdWU6IGZhbHNlIH07XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgIGlmICh0aGlzLmhhc0ZhaWxlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuc3ViamVjdC5vbkVycm9yKHRoaXMuZXJyb3IpO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuY29udHJvbGxlZERpc3Bvc2FibGUuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuY29udHJvbGxlZERpc3Bvc2FibGUgPSBkaXNwb3NhYmxlRW1wdHk7XHJcbiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHRoaXMuaGFzQ29tcGxldGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5zdWJqZWN0Lm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5jb250cm9sbGVkRGlzcG9zYWJsZS5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5jb250cm9sbGVkRGlzcG9zYWJsZSA9IGRpc3Bvc2FibGVFbXB0eTtcclxuICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICByZXR1cm4geyBudW1iZXJPZkl0ZW1zOiBudW1iZXJPZkl0ZW1zLCByZXR1cm5WYWx1ZTogZmFsc2UgfTtcclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgcmVxdWVzdDogZnVuY3Rpb24gKG51bWJlcikge1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgdGhpcy5kaXNwb3NlQ3VycmVudFJlcXVlc3QoKTtcclxuICAgICAgICAgICAgICAgIHZhciBzZWxmID0gdGhpcyxcclxuICAgICAgICAgICAgICAgICAgICByID0gdGhpcy5fcHJvY2Vzc1JlcXVlc3QobnVtYmVyKTtcclxuXHJcbiAgICAgICAgICAgICAgICBudW1iZXIgPSByLm51bWJlck9mSXRlbXM7XHJcbiAgICAgICAgICAgICAgICBpZiAoIXIucmV0dXJuVmFsdWUpIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLnJlcXVlc3RlZENvdW50ID0gbnVtYmVyO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMucmVxdWVzdGVkRGlzcG9zYWJsZSA9IGRpc3Bvc2FibGVDcmVhdGUoZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBzZWxmLnJlcXVlc3RlZENvdW50ID0gMDtcclxuICAgICAgICAgICAgICAgICAgICB9KTtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHRoaXMucmVxdWVzdGVkRGlzcG9zYWJsZVxyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gZGlzcG9zY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bmRleDEgPSBudW0gJSB0aGlzLmJ1Y2tldHMubGVuZ3RoLFxyXG4gICAgICAgICAgaW5kZXgyID0gLTE7XHJcbiAgICAgICAgZm9yICh2YXIgaW5kZXgzID0gdGhpcy5idWNrZXRzW2luZGV4MV07IGluZGV4MyA+PSAwOyBpbmRleDMgPSB0aGlzLmVudHJpZXNbaW5kZXgzXS5uZXh0KSB7XHJcbiAgICAgICAgICBpZiAodGhpcy5lbnRyaWVzW2luZGV4M10uaGFzaENvZGUgPT09IG51bSAmJiB0aGlzLmNvbXBhcmVyKHRoaXMuZW50cmllc1tpbmRleDNdLmtleSwga2V5KSkge1xyXG4gICAgICAgICAgICBpZiAoaW5kZXgyIDwgMCkge1xyXG4gICAgICAgICAgICAgIHRoaXMuYnVja2V0c1tpbmRleDFdID0gdGhpcy5lbnRyaWVzW2luZGV4M10ubmV4dDtcclxuICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICB0aGlzLmVudHJpZXNbaW5kZXgyXS5uZXh0ID0gdGhpcy5lbnRyaWVzW2luZGV4M10ubmV4dDtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB0aGlzLmVudHJpZXNbaW5kZXgzXS5oYXNoQ29kZSA9IC0xO1xyXG4gICAgICAgICAgICB0aGlzLmVudHJpZXNbaW5kZXgzXS5uZXh0ID0gdGhpcy5mcmVlTGlzdDtcclxuICAgICAgICAgICAgdGhpcy5lbnRyaWVzW2luZGV4M10ua2V5ID0gbnVsbDtcclxuICAgICAgICAgICAgdGhpcy5lbnRyaWVzW2luZGV4M10udmFsdWUgPSBudWxsO1xyXG4gICAgICAgICAgICB0aGlzLmZyZWVMaXN0ID0gaW5kZXgzO1xyXG4gICAgICAgICAgICArK3RoaXMuZnJlZUNvdW50O1xyXG4gICAgICAgICAgICByZXR1cm4gdHJ1ZTtcclxuICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgIGluZGV4MiA9IGluZGV4MztcclxuICAgICAgICAg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gICAgICAgICAgIHJldHVybiBpbmRleDtcclxuICAgICAgICAgIH1cclxuICAgICAgICB9XHJcbiAgICAgIH1cclxuICAgICAgcmV0dXJuIC0xO1xyXG4gICAgfTtcclxuXHJcbiAgICBkaWN0aW9uYXJ5UHJvdG8uY291bnQgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgIHJldHVybiB0aGlzLnNpemUgLSB0aGlzLmZyZWVDb3VudDtcclxuICAgIH07XHJcblxyXG4gICAgZGljdGlvbmFyeVByb3RvLnRyeUdldFZhbHVlID0gZnVuY3Rpb24gKGtleSkge1xyXG4gICAgICB2YXIgZW50cnkgPSB0aGlzLl9maW5kRW50cnkoa2V5KTtcclxuICAgICAgcmV0dXJuIGVudHJ5ID49IDAgP1xyXG4gICAgICAgIHRoaXMuZW50cmllc1tlbnRyeV0udmFsdWUgOlxyXG4gICAgICAgIHVuZGVmaW5lZDtcclxuICAgIH07XHJcblxyXG4gICAgZGljdGlvbmFyeVByb3RvLmdldFZhbHVlcyA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgdmFyIGluZGV4ID0gMCwgcmVzdWx0cyA9IFtdO1xyXG4gICAgICBpZiAodGhpcy5lbnRyaWVzKSB7XHJcbiAgICAgICAgZm9yICh2YXIgaW5kZXgxID0gMDsgaW5kZXgxIDwgdGhpcy5zaXplOyBpbmRleDErKykge1xyXG4gICAgICAgICAgaWYgKHRoaXMuZW50cmllc1tpbmRleDFdLmhhc2hDb2RlID49IDApIHtcclxuICAgICAgICAgICAgcmVzdWx0c1tpbmRleCsrXSA9IHRoaXMuZW50cmllc1tpbmRleDFdLnZhbHVlO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgIH1cclxuICAgICAgfVxyXG4gICAgICByZXR1cm4gcmVzdWx0cztcclxuICAgIH07XHJcblxyXG4gICAgZGljdGlvbmFyeVByb3RvLmdldCA9IGZ1bmN0aW9uIChrZXkpIHtcclxuICAgICAgdmFyIGVudHJ5ID0gdGhpcy5fZmluZEVudHJ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IG1kLnNldERpc3Bvc2FibGUoZHVyYXRpb24udGFrZSgxKS5zdWJzY3JpYmUobm9vcCwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZXhwaXJlKSk7XHJcblxyXG4gICAgICAgICAgcmlnaHRNYXAuZ2V0VmFsdWVzKCkuZm9yRWFjaChmdW5jdGlvbiAodikge1xyXG4gICAgICAgICAgICB2YXIgcmVzdWx0O1xyXG4gICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgIHJlc3VsdCA9IHJlc3VsdFNlbGVjdG9yKHZhbHVlLCB2KTtcclxuICAgICAgICAgICAgfSBjYXRjaCAoZXhuKSB7XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleG4pO1xyXG4gICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdCk7XHJcbiAgICAgICAgICB9KTtcclxuICAgICAgICB9LFxyXG4gICAgICAgIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksXHJcbiAgICAgICAgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgbGVmdERvbmUgPSB0cnVlO1xyXG4gICAgICAgICAgKHJpZ2h0RG9uZSB8fCBsZWZ0TWFwLmNvdW50KCkgPT09IDApICYmIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgfSlcclxuICAgICAgKTtcclxuXHJcbiAgICAgIGdyb3VwLmFkZChyaWdodC5zdWJzY3JpYmUoXHJcbiAgICAgICAgZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgICB2YXIgaWQgPSByaWdodElkKys7XHJcbiAgICAgICAgICB2YXIgbWQgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuXHJcbiAgICAgICAgICByaWdodE1hcC5hZGQoaWQsIHZhbHVlKTtcclxuICAgICAgICAgIGdyb3VwLmFkZChtZCk7XHJcblxyXG4gICAgICAgICAgdmFyIGV4cGlyZSA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgcmlnaHRNYXAucmVtb3ZlKGlkKSAmJiByaWdodE1hcC5jb3VudCgpID09PSAwICYmIHJpZ2h0RG9uZSAmJiBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICBncm91cC5yZW1vdmUobWQpO1xyXG4gICAgICAgICAgfTtcclxuXHJcbiAgICAgICAgICB2YXIgZHVyYXRpb247XHJcbiAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICBkdXJhdGlvbiA9IHJpZ2h0RHVyYXRpb25TZWxlY3Rvcih2YWx1ZSk7XHJcbiAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICBtZC5zZXREaXNwb3NhYmxlKGR1cmF0aW9uLnRha2UoMSkuc3Vic2NyaWJlKG5vb3AsIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGV4cGlyZSkpO1xyXG5cclxuICAgICAgICAgIGxlZnRNYXAuZ2V0VmFsdWVzKCkuZm9yRWFjaChmdW5jdGlvbiAodikge1xyXG4gICAgICAgICAgICB2YXIgcmVzdWx0O1xyXG4gICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgIHJlc3VsdCA9IHJlc3VsdFNlbGVjdG9yKHYsIHZhbHVlKTtcclxuICAgICAgICAgICAgfSBjYXRjaChleG4pIHtcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4bik7XHJcbiAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0KTtcclxuICAgICAgICAgIH0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ZXMoKS5mb3JFYWNoKGZ1bmN0aW9uICh2KSB7IHMub25OZXh0KHYpOyB9KTtcclxuXHJcbiAgICAgICAgICB2YXIgbWQgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgIGdyb3VwLmFkZChtZCk7XHJcblxyXG4gICAgICAgICAgdmFyIGV4cGlyZSA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgbGVmdE1hcC5yZW1vdmUoaWQpICYmIHMub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgZ3JvdXAucmVtb3ZlKG1kKTtcclxuICAgICAgICAgIH07XHJcblxyXG4gICAgICAgICAgdmFyIGR1cmF0aW9uO1xyXG4gICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgZHVyYXRpb24gPSBsZWZ0RHVyYXRpb25TZWxlY3Rvcih2YWx1ZSk7XHJcbiAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgIGxlZnRNYXAuZ2V0VmFsdWVzKCkuZm9yRWFjaChoYW5kbGVFcnJvcihlKSk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICBtZC5zZXREaXNwb3NhYmxlKGR1cmF0aW9uLnRha2UoMSkuc3Vic2NyaWJlKFxyXG4gICAgICAgICAgICBub29wLFxyXG4gICAgICAgICAgICBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgICAgIGxlZnRNYXAuZ2V0VmFsdWVzKCkuZm9yRWFjaChoYW5kbGVFcnJvcihlKSk7XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgZXhwaXJlKVxyXG4gICAgICAgICAgKTtcclxuICAgICAgICB9LFxyXG4gICAgICAgIGZ1bmN0aW9uIChlKSB7XHJcbiAgICAgICAgICBsZWZ0TWFwLmdldFZhbHVlcygpLmZvckVhY2goaGFuZGxlRXJyb3IoZSkpO1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICB9LFxyXG4gICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkLmJpbmQob2JzZXJ2ZXIpKVxyXG4gICAgICApO1xyXG5cclxuICAgICAgZ3JvdXAuYWRkKHJpZ2h0LnN1YnNjcmliZShcclxuICAgICAgICBmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgIHZhciBpZCA9IHJpZ2h0SWQrKztcclxuICAgICAgICAgIHJpZ2h0TWFwLmFkZChpZCwgdmFsdWUpO1xyXG5cclxuICAgICAgICAgIHZhciBtZCA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgZ3JvdXAuYWRkKG1kKTtcclxuXHJcbiAgICAgICAgICB2YXIgZXhwaXJlID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICByaWdodE1hcC5yZW1vdmUoaWQpO1xyXG4gICAgICAgICAgICBncm91cC5yZW1vdmUobWQpO1xyXG4gICAgICAgICAgfTtcclxuXHJcbiAgICAgICAgICB2YXIgZHVyYXRpb247XHJcbiAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICBkdXJhdGlvbiA9IHJpZ2h0RHVyYXRpb25TZWxlY3Rvcih2YWx1ZSk7XHJcbiAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgIGxlZnRNYXAuZ2V0VmFsdWVzKCkuZm9yRWFjaChoYW5kbGVFcnJvcihlKSk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgIH1cclxuICAgICAgICAgIG1kLnNldERpc3Bvc2FibGUoZHVyYXRpb24udGFrZSgxKS5zdWJzY3JpY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ICAgdmFyIHNvdXJjZSA9IHRoaXM7XHJcbiAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgIHZhciBxID0gW10sXHJcbiAgICAgICAgbSA9IG5ldyBTZXJpYWxEaXNwb3NhYmxlKCksXHJcbiAgICAgICAgZCA9IG5ldyBDb21wb3NpdGVEaXNwb3NhYmxlKG0pLFxyXG4gICAgICAgIGFjdGl2ZUNvdW50ID0gMCxcclxuICAgICAgICBpc0FjcXVpcmVkID0gZmFsc2U7XHJcblxyXG4gICAgICB2YXIgZW5zdXJlQWN0aXZlID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIHZhciBpc093bmVyID0gZmFsc2U7XHJcbiAgICAgICAgaWYgKHEubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgICBpc093bmVyID0gIWlzQWNxdWlyZWQ7XHJcbiAgICAgICAgICAgIGlzQWNxdWlyZWQgPSB0cnVlO1xyXG4gICAgICAgIH1cclxuICAgICAgICBpZiAoaXNPd25lcikge1xyXG4gICAgICAgICAgbS5zZXREaXNwb3NhYmxlKHNjaGVkdWxlci5zY2hlZHVsZVJlY3Vyc2l2ZShmdW5jdGlvbiAoc2VsZikge1xyXG4gICAgICAgICAgICB2YXIgd29yaztcclxuICAgICAgICAgICAgaWYgKHEubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgICAgIHdvcmsgPSBxLnNoaWZ0KCk7XHJcbiAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgaXNBY3F1aXJlZCA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB2YXIgbTEgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgZC5hZGQobTEpO1xyXG4gICAgICAgICAgICBtMS5zZXREaXNwb3NhYmxlKHdvcmsuc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHgpO1xyXG4gICAgICAgICAgICAgIHZhciByZXN1bHQgPSBudWxsO1xyXG4gICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICByZXN1bHQgPSBzZWxlY3Rvcih4KTtcclxuICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICBxLnB1c2gocmVzdWx0KTtcclxuICAgICAgICAgICAgICBhY3RpdmVDb3VudCsrO1xyXG4gICAgICAgICAgICAgIGVuc3VyZUFjdGl2ZSgpO1xyXG4gICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgZC5yZW1vdmUobTEpO1xyXG4gICAgICAgICAgICAgIGFjdGl2ZUNvdW50LS07XHJcbiAgICAgICAgICAgICAgaWYgKGFjdGl2ZUNvdW50ID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICBzZWxmKCk7XHJcbiAgICAgICAgICB9KSk7XHJcbiAgICAgICAgfVxyXG4gICAgICB9O1xyXG5cclxuICAgICAgcS5wdXNoKHNvdXJjZSk7XHJcbiAgICAgIGFjdGl2ZUNvdW50Kys7XHJcbiAgICAgIGVuc3VyZUFjdGl2ZSgpO1xyXG4gICAgICByZXR1cm4gZDtcclxuICAgIH0pO1xyXG4gIH07XHJcblxyXG4gICAvKipcclxuICAgKiAgUnVucyBhbGwgb2JzZXJ2YWJsZSBzZXF1ZW5jZXMgaW4gcGFyYWxsZWwgYW5kIGN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gaWR4IDwgY291bnQ7IGlkeCsrKSB7XHJcbiAgICAgICAgKGZ1bmN0aW9uIChpKSB7XHJcbiAgICAgICAgICB2YXIgc291cmNlID0gYWxsU291cmNlc1tpXTtcclxuICAgICAgICAgIGlzUHJvbWlzZShzb3VyY2UpICYmIChzb3VyY2UgPSBvYnNlcnZhYmxlRnJvbVByb21pc2Uoc291cmNlKSk7XHJcbiAgICAgICAgICBncm91cC5hZGQoXHJcbiAgICAgICAgICAgIHNvdXJjZS5zdWJzY3JpYmUoXHJcbiAgICAgICAgICAgICAgZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgICAgICAgaWYgKCFmaW5pc2hlZCkge1xyXG4gICAgICAgICAgICAgICAgaGFzUmVzdWx0c1tpXSA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICByZXN1bHRzW2ldID0gdmFsdWU7XHJcbiAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgICAgIGZpbmlzaGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICBzdWJzY3JpYmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgZ3JvdXAuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgaWYgKCFmaW5pc2hlZCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKCFoYXNSZXN1bHRzW2ldKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgc3Vic2NyaWJlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGhhc0NvbXBsZXRlZFtpXSA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICBmb3IgKHZhciBpeCA9IDA7IGl4IDwgY291bnQ7IGl4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KSB7XHJcbiAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgfSBlbHNlIGlmICghaGFzUmlnaHQpIHtcclxuICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgdmFyIHJlc3VsdDtcclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgIHJlc3VsdCA9IHJlc3VsdFNlbGVjdG9yKGxhc3RMZWZ0LCBsYXN0UmlnaHQpO1xyXG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0KTtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICB9KVxyXG4gICAgICApO1xyXG5cclxuICAgICAgcmlnaHRTdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZShcclxuICAgICAgICBzZWNvbmQuc3Vic2NyaWJlKGZ1bmN0aW9uIChyaWdodCkge1xyXG4gICAgICAgICAgaGFzUmlnaHQgPSB0cnVlO1xyXG4gICAgICAgICAgbGFzdFJpZ2h0ID0gcmlnaHQ7XHJcbiAgICAgICAgfSwgZnVuY3Rpb24gKGVycikge1xyXG4gICAgICAgICAgbGVmdFN1YnNjcmlwdGlvbi5kaXNwb3NlKCk7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGVycik7XHJcbiAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgcmlnaHRTdG9wcGVkID0gdHJ1ZTtcclxuICAgICAgICAgIGlmIChsZWZ0U3RvcHBlZCkge1xyXG4gICAgICAgICAgICBpZiAoIWhhc0xlZnQpIHtcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9IGVsc2UgaWYgKCFoYXNSaWdodCkge1xyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgdmFyIHJlc3VsdDtcclxuICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0U2VsZWN0b3IobGFzdExlZnQsIGxhc3RSaWdodCk7XHJcbiAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdCk7XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgfVxyXG4gICAgICAgIH0pXHJcbiAgICAgICk7XHJcblxyXG4gICAgICByZXR1cm4gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUobGVmdFN1YnNjcmlwdGlvbiwgcmlnaHRTdWJzY3JpcHRpb24pO1xyXG4gICAgfSk7XHJcbiAgfTtcclxuXHJcbiAgLyoqXHJcbiAgICogQ29tb25hZGljIGJpbmQgb3BlcmF0b3IuXHJcbiAgICogQHBhcmFtIHtGdW5jdGlvbn0gc2VsZWN0b3IgQSB0cmFuc2Zvcm0gZnVuY3Rpb24gdG8gYXBwbHkgdG8gZWFjaCBlbGVtZW50LlxyXG4gICAqIEBwYXJhbSB7T2JqZWN0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ZHVsZVJlY3Vyc2l2ZVdpdGhSZWxhdGl2ZShkdWVUaW1lLCBmdW5jdGlvbiAoc2VsZikge1xyXG4gICAgICAgICAgICAgIHZhciBlLCByZWN1cnNlRHVlVGltZSwgcmVzdWx0LCBzaG91bGRSZWN1cnNlO1xyXG4gICAgICAgICAgICAgIGlmIChleGNlcHRpb24gIT09IG51bGwpIHtcclxuICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgcnVubmluZyA9IHRydWU7XHJcbiAgICAgICAgICAgICAgZG8ge1xyXG4gICAgICAgICAgICAgICAgcmVzdWx0ID0gbnVsbDtcclxuICAgICAgICAgICAgICAgIGlmIChxLmxlbmd0aCA+IDAgJiYgcVswXS50aW1lc3RhbXAgLSBzY2hlZHVsZXIubm93KCkgPD0gMCkge1xyXG4gICAgICAgICAgICAgICAgICByZXN1bHQgPSBxLnNoaWZ0KCkudmFsdWU7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBpZiAocmVzdWx0ICE9PSBudWxsKSB7XHJcbiAgICAgICAgICAgICAgICAgIHJlc3VsdC5hY2NlcHQob2JzZXJ2ZXIpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgIH0gd2hpbGUgKHJlc3VsdCAhPT0gbnVsbCk7XHJcbiAgICAgICAgICAgICAgc2hvdWxkUmVjdXJzZSA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgIHJlY3Vyc2VEdWVUaW1lID0gMDtcclxuICAgICAgICAgICAgICBpZiAocS5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICAgICAgICBzaG91bGRSZWN1cnNlID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIHJlY3Vyc2VEdWVUaW1lID0gTWF0aC5tYXgoMCwgcVswXS50aW1lc3RhbXAgLSBzY2hlZHVsZXIubm93KCkpO1xyXG4gICAgICAgICAgICAgIH0gZWxzZSB7XHJcbi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IHZhciBuZXdJZCA9ICsrd2luZG93SWQ7XHJcbiAgICAgICAgICBzLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICBzID0gbmV3IFN1YmplY3QoKTtcclxuICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChhZGRSZWYocywgcmVmQ291bnREaXNwb3NhYmxlKSk7XHJcbiAgICAgICAgICBjcmVhdGVUaW1lcihuZXdJZCk7XHJcbiAgICAgICAgfSkpO1xyXG4gICAgICB9XHJcbiAgICAgIFxyXG4gICAgICBvYnNlcnZlci5vbk5leHQoYWRkUmVmKHMsIHJlZkNvdW50RGlzcG9zYWJsZSkpO1xyXG4gICAgICBjcmVhdGVUaW1lcigwKTtcclxuXHJcbiAgICAgIGdyb3VwRGlzcG9zYWJsZS5hZGQoc291cmNlLnN1YnNjcmliZShcclxuICAgICAgICBmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgdmFyIG5ld0lkID0gMCwgbmV3V2luZG93ID0gZmFsc2U7XHJcbiAgICAgICAgICBzLm9uTmV4dCh4KTtcclxuICAgICAgICAgIGlmICgrK24gPT09IGNvdW50KSB7XHJcbiAgICAgICAgICAgIG5ld1dpbmRvdyA9IHRydWU7XHJcbiAgICAgICAgICAgIG4gPSAwO1xyXG4gICAgICAgICAgICBuZXdJZCA9ICsrd2luZG93SWQ7XHJcbiAgICAgICAgICAgIHMub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgcyA9IG5ldyBTdWJqZWN0KCk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChhZGRSZWYocywgcmVmQ291bnREaXNwb3NhYmxlKSk7XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgICBuZXdXaW5kb3cgJiYgY3JlYXRlVGltZXIobmV3SWQpO1xyXG4gICAgICAgIH0sIFxyXG4gICAgICAgIGZ1bmN0aW9uIChlKSB7XHJcbiAgICAgICAgICBzLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICBvYnNlcnZlci5v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XksIGRlbGF5RHVyYXRpb25TZWxlY3Rvcikge1xyXG4gICAgICAgIHZhciBzb3VyY2UgPSB0aGlzLCBzdWJEZWxheSwgc2VsZWN0b3I7XHJcbiAgICAgICAgaWYgKHR5cGVvZiBzdWJzY3JpcHRpb25EZWxheSA9PT0gJ2Z1bmN0aW9uJykge1xyXG4gICAgICAgICAgICBzZWxlY3RvciA9IHN1YnNjcmlwdGlvbkRlbGF5O1xyXG4gICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgIHN1YkRlbGF5ID0gc3Vic2NyaXB0aW9uRGVsYXk7XHJcbiAgICAgICAgICAgIHNlbGVjdG9yID0gZGVsYXlEdXJhdGlvblNlbGVjdG9yO1xyXG4gICAgICAgIH1cclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBkZWxheXMgPSBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZSgpLCBhdEVuZCA9IGZhbHNlLCBkb25lID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKGF0RW5kICYmIGRlbGF5cy5sZW5ndGggPT09IDApIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LCBzdWJzY3JpcHRpb24gPSBuZXcgU2VyaWFsRGlzcG9zYWJsZSgpLCBzdGFydCA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHN1YnNjcmlwdGlvbi5zZXREaXNwb3NhYmxlKHNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgZGVsYXk7XHJcbiAgICAgICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZGVsYXkgPSBzZWxlY3Rvcih4KTtcclxuICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlcnJvcikge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGVycm9yKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICB2YXIgZCA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIGRlbGF5cy5hZGQoZCk7XHJcbiAgICAgICAgICAgICAgICAgICAgZC5zZXREaXNwb3NhYmxlKGRlbGF5LnN1YnNjcmliZShmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh4KTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZGVsYXlzLnJlbW92ZShkKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZG9uZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkZWxheXMucmVtb3ZlKGQpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkb25lKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGF0RW5kID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICBzdWJzY3JpcHRpb24uZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIGRvbmUoKTtcclxuICAgICAgICAgICAgICAgIH0pKT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bmFsID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcblxyXG4gICAgICAgIHN1YnNjcmlwdGlvbi5zZXREaXNwb3NhYmxlKG9yaWdpbmFsKTtcclxuXHJcbiAgICAgICAgdmFyIGlkID0gMCwgc3dpdGNoZWQgPSBmYWxzZTtcclxuXHJcbiAgICAgICAgZnVuY3Rpb24gc2V0VGltZXIodGltZW91dCkge1xyXG4gICAgICAgICAgdmFyIG15SWQgPSBpZDtcclxuXHJcbiAgICAgICAgICBmdW5jdGlvbiB0aW1lcldpbnMgKCkge1xyXG4gICAgICAgICAgICByZXR1cm4gaWQgPT09IG15SWQ7XHJcbiAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgdmFyIGQgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgIHRpbWVyLnNldERpc3Bvc2FibGUoZCk7XHJcbiAgICAgICAgICBkLnNldERpc3Bvc2FibGUodGltZW91dC5zdWJzY3JpYmUoZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICB0aW1lcldpbnMoKSAmJiBzdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZShvdGhlci5zdWJzY3JpYmUob2JzZXJ2ZXIpKTtcclxuICAgICAgICAgICAgZC5kaXNwb3NlKCk7XHJcbiAgICAgICAgICB9LCBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgICB0aW1lcldpbnMoKSAmJiBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICB0aW1lcldpbnMoKSAmJiBzdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZShvdGhlci5zdWJzY3JpYmUob2JzZXJ2ZXIpKTtcclxuICAgICAgICAgIH0pKTtcclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICBzZXRUaW1lcihmaXJzdFRpbWVvdXQpO1xyXG5cclxuICAgICAgICBmdW5jdGlvbiBvYnNlcnZlcldpbnMoKSB7XHJcbiAgICAgICAgICB2YXIgcmVzID0gIXN3aXRjaGVkO1xyXG4gICAgICAgICAgaWYgKHJlcykgeyBpZCsrOyB9XHJcbiAgICAgICAgICByZXR1cm4gcmVzO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgb3JpZ2luYWwuc2V0RGlzcG9zYWJsZShzb3VyY2Uuc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICBpZiAob2JzZXJ2ZXJXaW5zKCkpIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHgpO1xyXG4gICAgICAgICAgICB2YXIgdGltZW91dDtcclxuICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICB0aW1lb3V0ID0gdGltZW91dGR1cmF0aW9uU2VsZWN0b3IoeCk7XHJcbiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICBzZXRUaW1lcihpc1Byb21pc2UodGltZW91dCkgPyBvYnNlcnZhYmxlRnJvbVByb21pc2UodGltZW91dCkgOiB0aW1lb3V0KTtcclxuICAgICAgICAgIH1cclxuICAgICAgICB9LCBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgb2JzZXJ2ZXJXaW5zKCkgJiYgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICBvYnNlcnZlcldpbnMoKSAmJiBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgIH0pKTtcclxuICAgICAgICByZXR1cm4gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUoc3Vic2NyaXB0aW9uLCB0aW1lcik7XHJcbiAgICAgIH0pO1xyXG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AgICAgIGlzUHJvbWlzZShpbm5lclNvdXJjZSkgJiYgKGlubmVyU291cmNlID0gb2JzZXJ2YWJsZUZyb21Qcm9taXNlKGlubmVyU291cmNlKSk7XHJcblxyXG4gICAgICAgICAgICB2YXIgaW5uZXJTdWJzY3JpcHRpb24gPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgZy5hZGQoaW5uZXJTdWJzY3JpcHRpb24pO1xyXG5cclxuICAgICAgICAgICAgaW5uZXJTdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZShpbm5lclNvdXJjZS5zdWJzY3JpYmUoXHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0LmJpbmQob2JzZXJ2ZXIpLFxyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksXHJcbiAgICAgICAgICAgICAgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgZy5yZW1vdmUoaW5uZXJTdWJzY3JpcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgaGFzQ3VycmVudCA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgaWYgKGlzU3RvcHBlZCAmJiBnLmxlbmd0aCA9PT0gMSkge1xyXG4gICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgfSxcclxuICAgICAgICBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLFxyXG4gICAgICAgIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgIGlzU3RvcHBlZCA9IHRydWU7XHJcbiAgICAgICAgICBpZiAoIWhhc0N1cnJlbnQgJiYgZy5sZW5ndGggPT09IDEpIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtccl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AgICAgbSA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpLFxyXG4gICAgICAgIGcgPSBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZSgpO1xyXG5cclxuICAgICAgZy5hZGQobSk7XHJcblxyXG4gICAgICBtLnNldERpc3Bvc2FibGUoc291cmNlcy5zdWJzY3JpYmUoXHJcbiAgICAgICAgZnVuY3Rpb24gKGlubmVyU291cmNlKSB7XHJcblxyXG4gICAgICAgICAgaWYgKCFoYXNDdXJyZW50KSB7XHJcbiAgICAgICAgICAgIGhhc0N1cnJlbnQgPSB0cnVlO1xyXG5cclxuICAgICAgICAgICAgaW5uZXJTdWJzY3JpcHRpb24gPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgZy5hZGQoaW5uZXJTdWJzY3JpcHRpb24pO1xyXG5cclxuICAgICAgICAgICAgaXNQcm9taXNlKGlubmVyU291cmNlKSAmJiAoaW5uZXJTb3VyY2UgPSBvYnNlcnZhYmxlRnJvbVByb21pc2UoaW5uZXJTb3VyY2UpKTtcclxuXHJcbiAgICAgICAgICAgIGlubmVyU3Vic2NyaXB0aW9uLnNldERpc3Bvc2FibGUoaW5uZXJTb3VyY2Uuc3Vic2NyaWJlKFxyXG4gICAgICAgICAgICAgIGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgcmVzdWx0O1xyXG4gICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgcmVzdWx0ID0gc2VsZWN0b3IuY2FsbCh0aGlzQXJnLCB4LCBpbmRleCsrLCBpbm5lclNvdXJjZSk7XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0KTtcclxuICAgICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksXHJcbiAgICAgICAgICAgICAgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgZy5yZW1vdmUoaW5uZXJTdWJzY3JpcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgaGFzQ3VycmVudCA9IGZhbHNlO1xyXG5cclxuICAgICAgICAgICAgICAgIGlmIChpc1N0b3BwZWQgJiYgZy5sZW5ndGggPT09IDEpIHtcclxuICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgfSxcclxuICAgICAgICBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLFxyXG4gICAgICAgIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgIGlzU3RvcHBlZCA9IHRydWU7XHJcbiAgICAgICAgICBpZiAoZy5sZW5ndGggPT09IDEgJiYgIWhhc0N1cnJlbnQpIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgIH1cclxuICAgICAgICB9KSk7XHJcbiAgICAgIHJldHVybiBnO1xyXG4gICAgfSk7XHJcbiAgfTtcclxuXHJcbiAgLyoqIFByb3ZpZGVzIGEgc2V0IG9mIGV4dGVuc2lvbiBtZXRob2RzIGZvciB2aXJ0dWFsIHRpbWUgc2NoZWR1bGluZy4gKi9cclxuICBSeC5WaXJ0dWFsVGltZVNjaGVkdWxlciA9IChmdW5jdGlvbiAoX19zdXBlcl9fKSB7XHJcblxyXG4gICAgZnVuY3Rpb24gbm90SW1wbGVtZW50ZWQoKSB7XHJcbiAgICAgICAgdGhyb3cgbmV3IEVycm9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c3VwZXIpIHtcclxuICAgICAgICBpbmhlcml0cyhBdXRvRGV0YWNoT2JzZXJ2ZXIsIF9zdXBlcik7XHJcblxyXG4gICAgICAgIGZ1bmN0aW9uIEF1dG9EZXRhY2hPYnNlcnZlcihvYnNlcnZlcikge1xyXG4gICAgICAgICAgICBfc3VwZXIuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgdGhpcy5vYnNlcnZlciA9IG9ic2VydmVyO1xyXG4gICAgICAgICAgICB0aGlzLm0gPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIHZhciBBdXRvRGV0YWNoT2JzZXJ2ZXJQcm90b3R5cGUgPSBBdXRvRGV0YWNoT2JzZXJ2ZXIucHJvdG90eXBlO1xyXG5cclxuICAgICAgICBBdXRvRGV0YWNoT2JzZXJ2ZXJQcm90b3R5cGUubmV4dCA9IGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgICB2YXIgbm9FcnJvciA9IGZhbHNlO1xyXG4gICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5vYnNlcnZlci5vbk5leHQodmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgbm9FcnJvciA9IHRydWU7XHJcbiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgIHRocm93IGU7XHJcbiAgICAgICAgICAgIH0gZmluYWxseSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoIW5vRXJyb3IpIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIEF1dG9EZXRhY2hPYnNlcnZlclByb3RvdHlwZS5lcnJvciA9IGZ1bmN0aW9uIChleG4pIHtcclxuICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICA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ICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICByZXR1cm4gZGlzcG9zYWJsZUVtcHR5O1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgaW5oZXJpdHMoU3ViamVjdCwgX3N1cGVyKTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQ3JlYXRlcyBhIHN1YmplY3QuXHJcbiAgICAgICAgICogQGNvbnN0cnVjdG9yXHJcbiAgICAgICAgICovXHJcbiAgICAgICAgZnVuY3Rpb24gU3ViamVjdCgpIHtcclxuICAgICAgICAgICAgX3N1cGVyLmNhbGwodGhpcywgc3Vic2NyaWJlKTtcclxuICAgICAgICAgICAgdGhpcy5pc0Rpc3Bvc2VkID0gZmFsc2UsXHJcbiAgICAgICAgICAgIHRoaXMuaXNTdG9wcGVkID0gZmFsc2UsXHJcbiAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzID0gW107XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBhZGRQcm9wZXJ0aWVzKFN1YmplY3QucHJvdG90eXBlLCBPYnNlcnZlciwge1xyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogSW5kaWNhdGVzIHdoZXRoZXIgdGhlIHN1YmplY3QgaGFzIG9ic2VydmVycyBzdWJzY3JpYmVkIHRvIGl0LlxyXG4gICAgICAgICAgICAgKiBAcmV0dXJucyB7Qm9vbGVhbn0gSW5kaWNhdGVzIHdoZXRoZXIgdGhlIHN1YmplY3QgaGFzIG9ic2VydmVycyBzdWJzY3JpYmVkIHRvIGl0LlxyXG4gICAgICAgICAgICAgKi9cclxuICAgICAgICAgICAgaGFzT2JzZXJ2ZXJzOiBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gdGhpcy5vYnNlcnZlcnMubGVuZ3RoID4gMDtcclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgLyoqXHJcbiAgICAgICAgICAgICAqIE5vdGlmaWVzIGFsbCBzdWJzY3JpYmVkIG9ic2VydmVycyBhYm91dCB0aGUgZW5kIG9mIHRoZSBzZXF1ZW5jZS5cclxuICAgICAgICAgICAgICovXHJcbiAgICAgICAgICAgIG9uQ29tcGxldGVkOiBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIG9zID0gdGhpcy5vYnNlcnZlcnMuc2xpY2UoMCk7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5pc1N0b3BwZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSBvcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvc1tpXS5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5vYnNlcnZlcnMgPSBbXTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgLyoqXHJcbiAgICAgICAgICAgICAqIE5vdGlmaWVzIGFsbCBzdWJzY3JpYmVkIG9ic2VydmVycyBhYm91dCB0aGUgZXhjZXB0aW9uLlxyXG4gICAgICAgICAgICAgKiBAcGFyYW0ge01peGVkfSBlcnJvciBUaGUgZXhjZXB0aW9uIHRvIHNlbmQgdG8gYWxsIG9ic2VydmVycy5cclxuICAgICAgICAgICAgICovXHJcbiAgICAgICAgICAgIG9uRXJyb3I6IGZ1bmN0aW9uIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgb3MgPSB0aGlzLm9ic2VydmVycy5zbGljZSgwKTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmlzU3RvcHBlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5leGNlcHRpb24gPSBleGNlcHRpb247XHJcbiAgICAgICAgICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IG9zLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9zW2ldLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzID0gW107XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBOb3RpZmllcyBhbGwgc3Vic2NyaWJlZCBvYnNlcnZlcnMgYWJvdXQgdGhlIGFycml2YWwgb2YgdGhlIHNwZWNpZmllZCBlbGVtZW50IGluIHRoZSBzZXF1ZW5jZS5cclxuICAgICAgICAgICAgICogQHBhcmFtIHtNaXhlZH0gdmFsdWUgVGhlIHZhbHVlIHRvIHNlbmQgdG8gYWxsIG9ic2VydmVycy5cclxuICAgICAgICAgICAgICovXHJcbiAgICAgICAgICAgIG9uTmV4dDogZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIG9zID0gdGhpcy5vYnNlcnZlcnMuc2xpY2UoMCk7XHJcbiAgICAgICAgICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IG9zLmxlbmd0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xuICAgICAgICogQHJldHVybnMge0Jvb2xlYW59IEluZGljYXRlcyB3aGV0aGVyIHRoZSBzdWJqZWN0IGhhcyBvYnNlcnZlcnMgc3Vic2NyaWJlZCB0byBpdC5cclxuICAgICAgICovXHJcbiAgICAgIGhhc09ic2VydmVyczogZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICByZXR1cm4gdGhpcy5vYnNlcnZlcnMubGVuZ3RoID4gMDtcclxuICAgICAgfSxcclxuICAgICAgLyoqXHJcbiAgICAgICAqIE5vdGlmaWVzIGFsbCBzdWJzY3JpYmVkIG9ic2VydmVycyBhYm91dCB0aGUgZW5kIG9mIHRoZSBzZXF1ZW5jZSwgYWxzbyBjYXVzaW5nIHRoZSBsYXN0IHJlY2VpdmVkIHZhbHVlIHRvIGJlIHNlbnQgb3V0IChpZiBhbnkpLlxyXG4gICAgICAgKi9cclxuICAgICAgb25Db21wbGV0ZWQ6IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICB2YXIgbywgaSwgbGVuO1xyXG4gICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICBpZiAoIXRoaXMuaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICB0aGlzLmlzU3RvcHBlZCA9IHRydWU7XHJcbiAgICAgICAgICB2YXIgb3MgPSB0aGlzLm9ic2VydmVycy5zbGljZSgwKSxcclxuICAgICAgICAgICAgdiA9IHRoaXMudmFsdWUsXHJcbiAgICAgICAgICAgIGh2ID0gdGhpcy5oYXNWYWx1ZTtcclxuXHJcbiAgICAgICAgICBpZiAoaHYpIHtcclxuICAgICAgICAgICAgZm9yIChpID0gMCwgbGVuID0gb3MubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICBvID0gb3NbaV07XHJcbiAgICAgICAgICAgICAgby5vbk5leHQodik7XHJcbiAgICAgICAgICAgICAgby5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICBmb3IgKGkgPSAwLCBsZW4gPSBvcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgIG9zW2ldLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICB0aGlzLm9ic2VydmVycyA9IFtdO1xyXG4gICAgICAgIH1cclxuICAgICAgfSxcclxuICAgICAgLyoqXHJcbiAgICAgICAqIE5vdGlmaWVzIGFsbCBzdWJzY3JpYmVkIG9ic2VydmVycyBhYm91dCB0aGUgZXJyb3IuXHJcbiAgICAgICAqIEBwYXJhbSB7TWl4ZWR9IGVycm9yIFRoZSBFcnJvciB0byBzZW5kIHRvIGFsbCBvYnNlcnZlcnMuXHJcbiAgICAgICAqL1xyXG4gICAgICBvbkVycm9yOiBmdW5jdGlvbiAoZXJyb3IpIHtcclxuICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgaWYgKCF0aGlzLmlzU3RvcHBlZCkge1xyXG4gICAgICAgICAgdmFyIG9zID0gdGhpcy5vYnNlcnZlcnMuc2xpY2UoMCk7XHJcbiAgICAgICAgICB0aGlzLmlzU3RvcHBlZCA9IHRydWU7XHJcbiAgICAgICAgICB0aGlzLmV4Y2VwdGlvbiA9IGVycm9yO1xyXG5cclxuICAgICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSBvcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICBvc1tpXS5vbkVycm9yKGVycm9yKTtcclxuICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICB0aGlzLm9ic2VydmVycyA9IFtdO1xyXG4gICAgICAgIH1cclxuICAgICAgfSxcclxuICAgICAgLyoqXHJcbiAgICAgICAqIFNlbmRzIGEgdmFsd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ICAgICAgICAgICAgX3N1cGVyLmNhbGwodGhpcywgc3Vic2NyaWJlKTtcclxuICAgICAgICAgICAgdmFyIG1lc3NhZ2UsIG5vdGlmaWNhdGlvbiwgb2JzZXJ2YWJsZSA9IHRoaXM7XHJcbiAgICAgICAgICAgIHRoaXMuc2NoZWR1bGVyID0gc2NoZWR1bGVyO1xyXG4gICAgICAgICAgICB0aGlzLm1lc3NhZ2VzID0gbWVzc2FnZXM7XHJcbiAgICAgICAgICAgIHRoaXMuc3Vic2NyaXB0aW9ucyA9IFtdO1xyXG4gICAgICAgICAgICB0aGlzLm9ic2VydmVycyA9IFtdO1xyXG4gICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gdGhpcy5tZXNzYWdlcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgbWVzc2FnZSA9IHRoaXMubWVzc2FnZXNbaV07XHJcbiAgICAgICAgICAgICAgICBub3RpZmljYXRpb24gPSBtZXNzYWdlLnZhbHVlO1xyXG4gICAgICAgICAgICAgICAgKGZ1bmN0aW9uIChpbm5lck5vdGlmaWNhdGlvbikge1xyXG4gICAgICAgICAgICAgICAgICAgIHNjaGVkdWxlci5zY2hlZHVsZUFic29sdXRlV2l0aFN0YXRlKG51bGwsIG1lc3NhZ2UudGltZSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB2YXIgb2JzID0gb2JzZXJ2YWJsZS5vYnNlcnZlcnMuc2xpY2UoMCk7XHJcblxyXG4gICAgICAgICAgICAgICAgICAgICAgICBmb3IgKHZhciBqID0gMCwgakxlbiA9IG9icy5sZW5ndGg7IGogPCBqTGVuOyBqKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlubmVyTm90aWZpY2F0aW9uLmFjY2VwdChvYnNbal0pO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBkaXNwb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xsLCBtZXNzYWdlLnRpbWUsIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaW5uZXJOb3RpZmljYXRpb24uYWNjZXB0KG9ic2VydmVyKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGRpc3Bvc2FibGVFbXB0eTtcclxuICAgICAgICAgICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICAgICAgICB9KShub3RpZmljYXRpb24pO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIHJldHVybiBkaXNwb3NhYmxlQ3JlYXRlKGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIG9ic2VydmFibGUuc3Vic2NyaXB0aW9uc1tpbmRleF0gPSBuZXcgU3Vic2NyaXB0aW9uKG9ic2VydmFibGUuc3Vic2NyaXB0aW9uc1tpbmRleF0uc3Vic2NyaWJlLCBvYnNlcnZhYmxlLnNjaGVkdWxlci5jbG9jayk7XHJcbiAgICAgICAgICAgICAgICBkLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBpbmhlcml0cyhDb2xkT2JzZXJ2YWJsZSwgX3N1cGVyKTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgKiBAY29uc3RydWN0b3JcclxuICAgICAgICAgKi9cclxuICAgICAgICBmdW5jdGlvbiBDb2xkT2JzZXJ2YWJsZShzY2hlZHVsZXIsIG1lc3NhZ2VzKSB7XHJcbiAgICAgICAgICAgIF9zdXBlci5jYWxsKHRoaXMsIHN1YnNjcmliZSk7XHJcbiAgICAgICAgICAgIHRoaXMuc2NoZWR1bGVyID0gc2NoZWR1bGVyO1xyXG4gICAgICAgICAgICB0aGlzLm1lc3NhZ2VzID0gbWVzc2FnZXM7XHJcbiAgICAgICAgICAgIHRoaXMuc3Vic2NyaXB0aW9ucyA9IFtdO1xyXG4gICA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lKSB7XHJcbiAgICAgICAgICAgIHJldHVybiBhYnNvbHV0ZSArIHJlbGF0aXZlO1xyXG4gICAgICAgIH07XHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQ29udmVydHMgdGhlIGFic29sdXRlIHZpcnR1YWwgdGltZSB2YWx1ZSB0byBhIERhdGVUaW1lT2Zmc2V0IHZhbHVlLlxyXG4gICAgICAgICAqXHJcbiAgICAgICAgICogQHBhcmFtIGFic29sdXRlIEFic29sdXRlIHZpcnR1YWwgdGltZSB2YWx1ZSB0byBjb252ZXJ0LlxyXG4gICAgICAgICAqIEByZXR1cm4gQ29ycmVzcG9uZGluZyBEYXRlVGltZU9mZnNldCB2YWx1ZS5cclxuICAgICAgICAgKi9cclxuICAgICAgICBUZXN0U2NoZWR1bGVyLnByb3RvdHlwZS50b0RhdGVUaW1lT2Zmc2V0ID0gZnVuY3Rpb24gKGFic29sdXRlKSB7XHJcbiAgICAgICAgICAgIHJldHVybiBuZXcgRGF0ZShhYnNvbHV0ZSkuZ2V0VGltZSgpO1xyXG4gICAgICAgIH07XHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQ29udmVydHMgdGhlIFRpbWVTcGFuIHZhbHVlIHRvIGEgcmVsYXRpdmUgdmlydHVhbCB0aW1lIHZhbHVlLlxyXG4gICAgICAgICAqXHJcbiAgICAgICAgICogQHBhcmFtIHRpbWVTcGFuIFRpbWVTcGFuIHZhbHVlIHRvIGNvbnZlcnQuXHJcbiAgICAgICAgICogQHJldHVybiBDb3JyZXNwb25kaW5nIHJlbGF0aXZlIHZpcnR1YWwgdGltZSB2YWx1ZS5cclxuICAgICAgICAgKi9cclxuICAgICAgICBUZXN0U2NoZWR1bGVyLnByb3RvdHlwZS50b1JlbGF0aXZlID0gZnVuY3Rpb24gKHRpbWVTcGFuKSB7XHJcbiAgICAgICAgICAgIHJldHVybiB0aW1lU3BhbjtcclxuICAgICAgICB9O1xyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIF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WYWx1ZVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxufVxuXG5mdW5jdGlvbiByZW1vdmVQcm9wZXJ0eShub2RlLCBwcm9wcywgcHJldmlvdXMsIHByb3BOYW1lKSB7XG4gICAgaWYgKHByZXZpb3VzKSB7XG4gICAgICAgIHZhciBwcmV2aW91c1ZhbHVlID0gcHJldmlvdXNbcHJvcE5hbWVdXG5cbiAgICAgICAgaWYgKCFpc0hvb2socHJldmlvdXNWYWx1ZSkpIHtcbiAgICAgICAgICAgIGlmIChwcm9wTmFtZSA9PT0gXCJhdHRyaWJ1dGVzXCIpIHtcbiAgICAgICAgICAgICAgICBmb3IgKHZhciBhdHRyTmFtZSBpbiBwcmV2aW91c1ZhbHVlKSB7XG4gICAgICAgICAgICAgICAgICAgIG5vZGUucmVtb3ZlQXR0cmlidXRlKGF0dHJOYW1lKVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSBpZiAocHJvcE5hbWUgPT09IFwic3R5bGVcIikge1xuICAgICAgICAgICAgICAgIGZvciAodmFyIGkgaW4gcHJldmlvdXNWYWx1ZSkge1xuICAgICAgICAgICAgICAgICAgICBub2RlLnN0eWxlW2ldID0gXCJcIlxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIHByZXZpb3VzVmFsdWUgPT09IFwic3RyaW5nXCIpIHtcbiAgICAgICAgICAgICAgICBub2RlW3Byb3BOYW1lXSA9IFwiXCJcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgbm9kZVtwcm9wTmFtZV0gPSBudWxsXG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG59XG5cbmZ1bmN0aW9uIHBhdGNoT2JqZWN0KG5vZGUsIHByb3BzLCBwcmV2aW91cywgcHJvcE5hbWUsIHByb3BWYWx1ZSkge1xuICAgIHZhciBwcmV2aW91c1ZhbHVlID0gcHJldmlvdXMgPyB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dkNoaWxkcmVuID0gdHJlZS5jaGlsZHJlblxuXG4gICAgICAgIGlmICh2Q2hpbGRyZW4pIHtcblxuICAgICAgICAgICAgdmFyIGNoaWxkTm9kZXMgPSByb290Tm9kZS5jaGlsZE5vZGVzXG5cbiAgICAgICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgdHJlZS5jaGlsZHJlbi5sZW5ndGg7IGkrKykge1xuICAgICAgICAgICAgICAgIHJvb3RJbmRleCArPSAxXG5cbiAgICAgICAgICAgICAgICB2YXIgdkNoaWxkID0gdkNoaWxkcmVuW2ldIHx8IG5vQ2hpbGRcbiAgICAgICAgICAgICAgICB2YXIgbmV4dEluZGV4ID0gcm9vdEluZGV4ICsgKHZDaGlsZC5jb3VudCB8fCAwKVxuXG4gICAgICAgICAgICAgICAgLy8gc2tpcCByZWN1cnNpb24gZG93biB0aGUgdHJlZSBpZiB0aGVyZSBhcmUgbm8gbm9kZXMgZG93biBoZXJlXG4gICAgICAgICAgICAgICAgaWYgKGluZGV4SW5SYW5nZShpbmRpY2VzLCByb290SW5kZXgsIG5leHRJbmRleCkpIHtcbiAgICAgICAgICAgICAgICAgICAgcmVjdXJzZShjaGlsZE5vZGVzW2ldLCB2Q2hpbGQsIGluZGljZXMsIG5vZGVzLCByb290SW5kZXgpXG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgcm9vdEluZGV4ID0gbmV4dEluZGV4XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICByZXR1cm4gbm9kZXNcbn1cblxuLy8gQmluYXJ5IHNlYXJjaCBmb3IgYW4gaW5kZXggaW4gdGhlIGludGVydmFsIFtsZWZ0LCByaWdodF1cbmZ1bmN0aW9uIGluZGV4SW5SYW5nZShpbmRpY2VzLCBsZWZ0LCByaWdodCkge1xuICAgIGlmIChpbmRpY2VzLmxlbmd0aCA9PT0gMCkge1xuICAgICAgICByZXR1cm4gZmFsc2VcbiAgICB9XG5cbiAgICB2YXI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ICAgICAgdmFyIGFWYWx1ZSA9IGFbYUtleV1cbiAgICAgICAgdmFyIGJWYWx1ZSA9IGJbYUtleV1cblxuICAgICAgICBpZiAoaG9va3MgJiYgYUtleSBpbiBob29rcykge1xuICAgICAgICAgICAgZGlmZiA9IGRpZmYgfHwge31cbiAgICAgICAgICAgIGRpZmZbYUtleV0gPSBiVmFsdWVcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGlmIChpc09iamVjdChhVmFsdWUpICYmIGlzT2JqZWN0KGJWYWx1ZSkpIHtcbiAgICAgICAgICAgICAgICBpZiAoZ2V0UHJvdG90eXBlKGJWYWx1ZSkgIT09IGdldFByb3RvdHlwZShhVmFsdWUpKSB7XG4gICAgICAgICAgICAgICAgICAgIGRpZmYgPSBkaWZmIHx8IHt9XG4gICAgICAgICAgICAgICAgICAgIGRpZmZbYUtleV0gPSBiVmFsdWVcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICB2YXIgb2JqZWN0RGlmZiA9IGRpZmZQcm9wcyhhVmFsdWUsIGJWYWx1ZSlcbiAgICAgICAgICAgICAgICAgICAgaWYgKG9iamVjdERpZmYpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGRpZmYgPSBkaWZmIHx8IHt9XG4gICAgICAgICAgICAgICAgICAgICAgICBkaWZmW2FLZXldID0gb2JqZWN0RGlmZlxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIGlmIChhVmFsdWUgIT09IGJWYWx1ZSkge1xuICAgICAgICAgICAgICAgIGRpZmYgPSBkaWZmIHx8IHt9XG4gICAgICAgICAgICAgICAgZGlmZlthS2V5XSA9IGJWYWx1ZVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgZm9yICh2YXIgYktleSBpbiBiKSB7XG4gICAgICAgIGlmICghKGJLZXkgaW4gYSkpIHtcbiAgICAgICAgICAgI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ZhciByZW1vdmVzID0gbW92ZXMucmVtb3ZlcyA9IHt9XG4gICAgdmFyIHJldmVyc2UgPSBtb3Zlcy5yZXZlcnNlID0ge31cbiAgICB2YXIgaGFzTW92ZXMgPSBmYWxzZVxuXG4gICAgd2hpbGUgKGZyZWVJbmRleCA8IGxlbikge1xuICAgICAgICB2YXIgbW92ZSA9IGFNYXRjaFtpXVxuICAgICAgICBpZiAobW92ZSAhPT0gdW5kZWZpbmVkKSB7XG4gICAgICAgICAgICBzaHVmZmxlW2ldID0gYkNoaWxkcmVuW21vdmVdXG4gICAgICAgICAgICBpZiAobW92ZSAhPT0gbW92ZUluZGV4KSB7XG4gICAgICAgICAgICAgICAgbW92ZXNbbW92ZV0gPSBtb3ZlSW5kZXhcbiAgICAgICAgICAgICAgICByZXZlcnNlW21vdmVJbmRleF0gPSBtb3ZlXG4gICAgICAgICAgICAgICAgaGFzTW92ZXMgPSB0cnVlXG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBtb3ZlSW5kZXgrK1xuICAgICAgICB9IGVsc2UgaWYgKGkgaW4gYU1hdGNoKSB7XG4gICAgICAgICAgICBzaHVmZmxlW2ldID0gdW5kZWZpbmVkXG4gICAgICAgICAgICByZW1vdmVzW2ldID0gbW92ZUluZGV4KytcbiAgICAgICAgICAgIGhhc01vdmVzID0gdHJ1ZVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgd2hpbGUgKGJNYXRjaFtmcmVlSW5kZXhdICE9PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgICAgICBmcmVlSW5kZXgrK1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAoZnJlZUluZGV4IDwgbGVuKSB7XG4gICAgICAgICAgICAgICAgdmFyIGZyZWVDaGlsZCA9IGJDaGlsZHJlbltmcmVlSW5kZXhdXG4gICAgICAgICAgICAgICAgaWYgKGZyZWVDaGlsZCkge1xuICAgICAgICAgICAgICAgICAgICBzaHVmZmxlW2ldID0gZnJlZUNoaWxkXG4gICAgICAgICAgICAgICAgICAgIGlmIChmcmVlSW5kZXggIT09IG1vdmVJbmRleCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgaGFzTW92ZXMgPSB0cnVlXG4gICAgICAgICAgICAgICAgICAgICAgICBtb3Zlc1tmcmVlSW5kZXhdID0gbW92ZUluZGV4XG4gICAgICAgICAgICAgICAgICAgICAgICByZXZlcnNlW21vdmVJbmRleF0gPSBmcmVlSW5kZXhcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICBtb3ZlSW5kZXgrK1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBmcmVlSW5kZXgrK1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIGkrK1xuICAgIH1cblxuICAgIGlmIChoYXNNb3Zlcykge1xuICAgICAgICBzaHVmZmxlLm1vdmVzID0gbW92ZXNcbiAgICB9XG5cbiAgICByZXR1cm4gc2h1ZmZsZVxufVxuXG5mdW5jdGlvbiBrZXlJbmRleChjaGlsZHJlbikge1xuICAgIHZhciBpLCBrZXlzXG5cbiAgICBmb3IgKGkgPSAwOyBpIDwgY2hpbGRyZW4ubGVuZ3RoOyBpKyspIHtcbiAgICAgICAgdmFyIGNoaWxkID0gY2hpbGRyZW5baV1cblxuICAgICAgICBpZiAoY2hpbGQua2V5ICE9PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgIGtleXMgPSBrZXlzIHx8IHt9XG4gICAgICAgICAgICBrZXlzW2NoaWxkLmtleV0gPSBpXG4gICAgICAgIH1cbiAgICB9XG5cbiAgICByZXR1cm4ga2V5c1xufVxuXG5mdW5jdGlvbiBhcHBlbmRQYXRjaChhcHBseSwgcGF0Y2gpIHtcbiAgICBpZiAoYXBwbHkpIHtcbiAgICAgICAgaWYgKGlzQXJyYXkoYXBwbHkpKSB7XG4gICAgICAgICAgICBhcHBseS5wdXNoKHBhdGNoKVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgIC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yIGhhc1dpZGdldHMgPSBmYWxzZVxuICAgIHZhciBkZXNjZW5kYW50SG9va3MgPSBmYWxzZVxuICAgIHZhciBob29rc1xuXG4gICAgZm9yICh2YXIgcHJvcE5hbWUgaW4gcHJvcGVydGllcykge1xuICAgICAgICBpZiAocHJvcGVydGllcy5oYXNPd25Qcm9wZXJ0eShwcm9wTmFtZSkpIHtcbiAgICAgICAgICAgIHZhciBwcm9wZXJ0eSA9IHByb3BlcnRpZXNbcHJvcE5hbWVdXG4gICAgICAgICAgICBpZiAoaXNWSG9vayhwcm9wZXJ0eSkpIHtcbiAgICAgICAgICAgICAgICBpZiAoIWhvb2tzKSB7XG4gICAgICAgICAgICAgICAgICAgIGhvb2tzID0ge31cbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICBob29rc1twcm9wTmFtZV0gPSBwcm9wZXJ0eVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgZm9yICh2YXIgaSA9IDA7IGkgPCBjb3VudDsgaSsrKSB7XG4gICAgICAgIHZhciBjaGlsZCA9IGNoaWxkcmVuW2ldXG4gICAgICAgIGlmIChpc1ZOb2RlKGNoaWxkKSkge1xuICAgICAgICAgICAgZGVzY2VuZGFudHMgKz0gY2hpbGQuY291bnQgfHwgMFxuXG4gICAgICAgICAgICBpZiAoIWhhc1dpZGdldHMgJiYgY2hpbGQuaGFzV2lkZ2V0cykge1xuICAgICAgICAgICAgICAgIGhhc1dpZGdldHMgPSB0cnVlXG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmICghZGVzY2VuZGFudEhvb2tzICYmIChjaGlsZC5ob29rcyB8fCBjaGlsZC5kZXNjZW5kYW50SG9va3MpKSB7XG4gICAgICAgICAgICAgICAgZGVzY2VuZGFudEhvb2tzID0gdHJ1ZVxuICAgICAgICAgICAgfVxuICAgICAgICB9IGVsc2UgaWYgKCFoYXNXaWRnZXRzICYmIGlzV2lkZ2V0KGNoaWxkKSkge1xuIC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pIHtcbiAgZG9tRGVsZWdhdG9yID0gRE9NRGVsZWdhdG9yKCk7XG4gIHJlbmRlclZUcmVlU3RyZWFtKE9wZXJhdG9yc01lbnVWaWV3LnZ0cmVlJCwgXCIuanMtb3BlcmF0b3JzTWVudUNvbnRhaW5lclwiKTtcbiAgcmVuZGVyVlRyZWVTdHJlYW0oU2FuZGJveFZpZXcudnRyZWUkLCBcIi5qcy1zYW5kYm94Q29udGFpbmVyXCIpO1xuICByZW5kZXJBcHBWZXJzaW9uT25jZSgpO1xuICByZW5kZXJSeFZlcnNpb25PbmNlKCk7XG59XG5cbm1vZHVsZS5leHBvcnRzID0ge1xuICBpbml0OiBpbml0XG59O1xuXG59KS5jYWxsKHRoaXMscmVxdWlyZShcIjFZaVo1U1wiKSx0eXBlb2Ygc2VsZiAhPT0gXCJ1bmRlZmluZWRcIiA/IHNlbGYgOiB0eXBlb2Ygd2luZG93ICE9PSBcInVuZGVmaW5lZFwiID8gd2luZG93IDoge30scmVxdWlyZShcImJ1ZmZlclwiKS5CdWZmZXIsYXJndW1lbnRzWzNdLGFyZ3VtZW50c1s0XSxhcmd1bWVudHNbNV0sYXJndW1lbnRzWzZdLFwiL2Zha2VfMjk5NDhjZS5qc1wiLFwiL1wiKSJdfQ== +}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/fake_2b763f98.js","/") +},{"1YiZ5S":19,"buffer":15,"dom-delegator":3,"package.json":20,"rxmarbles/views/operators-menu":28,"rxmarbles/views/sandbox":32,"virtual-dom/diff":33,"virtual-dom/patch":52,"virtual-hyperscript":57}]},{},[77]) +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi9Vc2Vycy9hbWVkL0hvYmJ5L3J4bWFyYmxlcy9ub2RlX21vZHVsZXMvZ3VscC1icm93c2VyaWZ5L25vZGVfbW9kdWxlcy9icm93c2Vy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gICAgICAgaWYgKCF0aGlzLmRpc3Bvc2FibGUuaXNEaXNwb3NlZCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmlzSW5uZXJEaXNwb3NlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuaXNJbm5lckRpc3Bvc2VkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmRpc3Bvc2FibGUuY291bnQtLTtcclxuICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5kaXNwb3NhYmxlLmNvdW50ID09PSAwICYmIHRoaXMuZGlzcG9zYWJsZS5pc1ByaW1hcnlEaXNwb3NlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLmRpc3Bvc2FibGUuaXNEaXNwb3NlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuZGlzcG9zYWJsZS51bmRlcmx5aW5nRGlzcG9zYWJsZS5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogSW5pdGlhbGl6ZXMgYSBuZXcgaW5zdGFuY2Ugb2YgdGhlIFJlZkNvdW50RGlzcG9zYWJsZSB3aXRoIHRoZSBzcGVjaWZpZWQgZGlzcG9zYWJsZS5cclxuICAgICAgICAgKiBAY29uc3RydWN0b3JcclxuICAgICAgICAgKiBAcGFyYW0ge0Rpc3Bvc2FibGV9IGRpc3Bvc2FibGUgVW5kZXJseWluZyBkaXNwb3NhYmxlLlxyXG4gICAgICAgICAgKi9cclxuICAgICAgICBmdW5jdGlvbiBSZWZDb3VudERpc3Bvc2FibGUoZGlzcG9zYWJsZSkge1xyXG4gICAgICAgICAgICB0aGlzLnVuZGVybHlpbmdEaXNwb3NhYmxlID0gZGlzcG9zYWJsZTtcclxuICAgICAgICAgICAgdGhpcy5pc0Rpc3Bvc2VkID0gZmFsc2U7XHJcbiAgICAgICAgICAgIHRoaXMuaXNQcmltYXJ5RGlzcG9zZWQgPSBmYWxzZTtcclxuICAgICAgICAgICAgdGhpcy5jb3VudCA9IDA7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBEaXNwb3NlcyB0aGUgdW5kZXJseWluZyBkaXNwb3NhYmxlIG9ubHkgd2hlbiBhbGwgZGVwZW5kZW50IGRpc3Bvc2FibGVzIGhhdmUgYmVlbiBkaXNwb3NlZFxyXG4gICAgICAgICAqL1xyXG4gICAgICAgIFJlZkNvdW50RGlzcG9zYWJsZS5wcm90b3R5cGUuZGlzcG9zZSA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgaWYgKCF0aGlzLmlzRGlzcG9zZWQpIHtcclxuICAgICAgICAgICAgICAgIGlmICghdGhpcy5pc1ByaW1hcnlEaXNwb3NlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuaXNQcmltYXJ5RGlzcG9zZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLmNvdW50ID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuaXNEaXNwb3NlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMudW5kZXJseWluZ0Rpc3Bvc2FibGUuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIFJldHVybnMgYSBkZXBlbmRlbnQgZGlzcG9zYWJsZSB0aGF0IHdoZW4gZGlzcG9zZWQgZGVjcmVhc2VzIHRoZSByZWZjb3VudCBvbiB0aGUgdW5kZXJseWluZyBkaXNwb3NhYmxlLlxyXG4gICAgICAgICAqI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sXHJcbiAgICAgICAgICBkID0gc2NoZWR1bGVyW21ldGhvZF0uY2FsbChzY2hlZHVsZXIsIHN0YXRlMiwgZHVlVGltZTEsIGZ1bmN0aW9uIChzY2hlZHVsZXIxLCBzdGF0ZTMpIHtcclxuICAgICAgICAgICAgaWYgKGlzQWRkZWQpIHtcclxuICAgICAgICAgICAgICBncm91cC5yZW1vdmUoZCk7XHJcbiAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgaXNEb25lID0gdHJ1ZTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICByZWN1cnNpdmVBY3Rpb24oc3RhdGUzKTtcclxuICAgICAgICAgICAgcmV0dXJuIGRpc3Bvc2FibGVFbXB0eTtcclxuICAgICAgICAgIH0pO1xyXG4gICAgICAgICAgaWYgKCFpc0RvbmUpIHtcclxuICAgICAgICAgICAgZ3JvdXAuYWRkKGQpO1xyXG4gICAgICAgICAgICBpc0FkZGVkID0gdHJ1ZTtcclxuICAgICAgICAgIH1cclxuICAgICAgICB9KTtcclxuICAgICAgfTtcclxuICAgICAgcmVjdXJzaXZlQWN0aW9uKHN0YXRlKTtcclxuICAgICAgcmV0dXJuIGdyb3VwO1xyXG4gICAgfVxyXG5cclxuICAgIGZ1bmN0aW9uIGludm9rZUFjdGlvbihzY2hlZHVsZXIsIGFjdGlvbikge1xyXG4gICAgICBhY3Rpb24oKTtcclxuICAgICAgcmV0dXJuIGRpc3Bvc2FibGVFbXB0eTtcclxuICAgIH1cclxuXHJcbiAgICB2YXIgc2NoZWR1bGVyUHJvdG8gPSBTY2hlZHVsZXIucHJvdG90eXBlO1xyXG5cclxuICAgIC8qKlxyXG4gICAgICogU2NoZWR1bGVzIGFuIGFjdGlvbiB0byBiZSBleGVjdXRlZC5cclxuICAgICAqIEBwYXJhbSB7RnVuY3Rpb259IGFjdGlvbiBBY3Rpb24gdG8gZXhlY3V0ZS5cclxuICAgICAqIEByZXR1cm5zIHtEaXNwb3NhYmxlfSB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tcclxuICAgICAgICAgICAgdmFyIHBhcmVudCA9IHRoaXM7XHJcbiAgICAgICAgICAgIHJldHVybiBmdW5jdGlvbiAoc2VsZiwgc3RhdGUpIHtcclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGFjdGlvbihwYXJlbnQuX2dldFJlY3Vyc2l2ZVdyYXBwZXIoc2VsZiksIHN0YXRlKTtcclxuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICBpZiAoIXBhcmVudC5faGFuZGxlcihlKSkgeyB0aHJvdyBlOyB9XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGRpc3Bvc2FibGVFbXB0eTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfTtcclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICAvKiogQHByaXZhdGUgKi9cclxuICAgICAgICBDYXRjaFNjaGVkdWxlci5wcm90b3R5cGUuX2dldFJlY3Vyc2l2ZVdyYXBwZXIgPSBmdW5jdGlvbiAoc2NoZWR1bGVyKSB7XHJcbiAgICAgICAgICAgIGlmICh0aGlzLl9yZWN1cnNpdmVPcmlnaW5hbCAhPT0gc2NoZWR1bGVyKSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLl9yZWN1cnNpdmVPcmlnaW5hbCA9IHNjaGVkdWxlcjtcclxuICAgICAgICAgICAgICAgIHZhciB3cmFwcGVyID0gdGhpcy5fY2xvbmUoc2NoZWR1bGVyKTtcclxuICAgICAgICAgICAgICAgIHdyYXBwZXIuX3JlY3Vyc2l2ZU9yaWdpbmFsID0gc2NoZWR1bGVyO1xyXG4gICAgICAgICAgICAgICAgd3JhcHBlci5fcmVjdXJzaXZlV3JhcHBlciA9IHdyYXBwZXI7XHJcbiAgICAgICAgICAgICAgICB0aGlzLl9yZWN1cnNpdmVXcmFwcGVyID0gd3JhcHBlcjtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICByZXR1cm4gdGhpcy5fcmVjdXJzaXZlV3JhcHBlcjtcclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICAvKiogQHByaXZhdGUgKi9cclxuICAgICAgICBDYXRjaFNjaGVkdWxlci5wcm90b3R5cGUuc2NoZWR1bGVQZXJpb2RpY1dpdGhTdGF0ZSA9IGZ1bmN0aW9uIChzdGF0ZSwgcGVyaW9kLCBhY3Rpb24pIHtcclxuICAgICAgICAgICAgdmFyIHNlbGYgPSB0aGlzLCBmYWlsZWQgPSBmYWxzZSwgZCA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG5cclxuICAgICAgICAgICAgZC5zZXREaXNwb3NhYmxlKHRoaXMuX3NjaGVkdWxlci5zY2hlZHVsZVBlcmlvZGljV2l0aFN0YXRlKHN0YXRlLCBwZXJpb2QsIGZ1bmN0aW9uIChzdGF0ZTEpIHtcclxuICAgICAgICAgICAgICAgIGlmIChmYWlsZWQpIHsgcmV0dXJuIG51bGw7IH1cclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGFjdGlvbihzdGF0ZTEpO1xyXG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIGZhaWxlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKCFzZWxmLl9oYW5kbGVyKGUpKSB7IHRocm93IGU7IH1cclxuICAgICAgICAgICAgICAgICAgICBkLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gbnVsbDtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSkpO1xyXG5cclxuICAgICAgICAgICAgcmV0dXJuIGQ7XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgcmV0dXJuIENhdGNoU2NoZWR1bGVyO1xyXG4gICAgfShTY2hlZHVsZXIpKT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BjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgdGhyb3cgZTtcclxuICAgICAgICAgICAgfSBmaW5hbGx5IHtcclxuICAgICAgICAgICAgICAgIHRoaXMuX3N0YXRlID0gMjtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIENoZWNrZWRPYnNlcnZlclByb3RvdHlwZS5vbkNvbXBsZXRlZCA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgdGhpcy5jaGVja0FjY2VzcygpO1xyXG4gICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5fb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgdGhyb3cgZTtcclxuICAgICAgICAgICAgfSBmaW5hbGx5IHtcclxuICAgICAgICAgICAgICAgIHRoaXMuX3N0YXRlID0gMjtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIENoZWNrZWRPYnNlcnZlclByb3RvdHlwZS5jaGVja0FjY2VzcyA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgaWYgKHRoaXMuX3N0YXRlID09PSAxKSB7IHRocm93IG5ldyBFcnJvcignUmUtZW50cmFuY3kgZGV0ZWN0ZWQnKTsgfVxyXG4gICAgICAgICAgICBpZiAodGhpcy5fc3RhdGUgPT09IDIpIHsgdGhyb3cgbmV3IEVycm9yKCdPYnNlcnZlciBjb21wbGV0ZWQnKTsgfVxyXG4gICAgICAgICAgICBpZiAodGhpcy5fc3RhdGUgPT09IDApIHsgdGhpcy5fc3RhdGUgPSAxOyB9XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgcmV0dXJuIENoZWNrZWRPYnNlcnZlcjtcclxuICAgIH0oT2JzZXJ2ZXIpKTtcclxuXHJcbiAgdmFyIFNjaGVkdWxlZE9ic2VydmVyID0gUngu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9IE9iamVjdChpdGVyYWJsZSksXHJcbiAgICAgICAgb2JqSXNJdGVyYWJsZSA9IGlzSXRlcmFibGUobGlzdCksXHJcbiAgICAgICAgbGVuID0gb2JqSXNJdGVyYWJsZSA/IDAgOiB0b0xlbmd0aChsaXN0KSxcclxuICAgICAgICBpdCA9IG9iaklzSXRlcmFibGUgPyBsaXN0WyRpdGVyYXRvciRdKCkgOiBudWxsLFxyXG4gICAgICAgIGkgPSAwO1xyXG4gICAgICByZXR1cm4gc2NoZWR1bGVyLnNjaGVkdWxlUmVjdXJzaXZlKGZ1bmN0aW9uIChzZWxmKSB7XHJcbiAgICAgICAgaWYgKGkgPCBsZW4gfHwgb2JqSXNJdGVyYWJsZSkge1xyXG4gICAgICAgICAgdmFyIHJlc3VsdDtcclxuICAgICAgICAgIGlmIChvYmpJc0l0ZXJhYmxlKSB7XHJcbiAgICAgICAgICAgIHZhciBuZXh0ID0gaXQubmV4dCgpO1xyXG4gICAgICAgICAgICBpZiAobmV4dC5kb25lKSB7XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgIHJlc3VsdCA9IG5leHQudmFsdWU7XHJcbiAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICByZXN1bHQgPSBsaXN0W2ldO1xyXG4gICAgICAgICAgfVxyXG5cclxuICAgICAgICAgIGlmIChtYXBGbiAmJiBpc0NhbGxhYmxlKG1hcEZuKSkge1xyXG4gICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgIHJlc3VsdCA9IHRoaXNBcmcgPyBtYXBGbi5jYWxsKHRoaXNBcmcsIHJlc3VsdCwgaSkgOiBtYXBGbihyZXN1bHQsIGkpO1xyXG4gICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTt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YmUoZnVuY3Rpb24gKGxlZnQpIHtcclxuICAgICAgICBjaG9pY2VMKCk7XHJcbiAgICAgICAgaWYgKGNob2ljZSA9PT0gbGVmdENob2ljZSkge1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGxlZnQpO1xyXG4gICAgICAgIH1cclxuICAgICAgfSwgZnVuY3Rpb24gKGVycikge1xyXG4gICAgICAgIGNob2ljZUwoKTtcclxuICAgICAgICBpZiAoY2hvaWNlID09PSBsZWZ0Q2hvaWNlKSB7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGVycik7XHJcbiAgICAgICAgfVxyXG4gICAgICB9LCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgY2hvaWNlTCgpO1xyXG4gICAgICAgIGlmIChjaG9pY2UgPT09IGxlZnRDaG9pY2UpIHtcclxuICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgfVxyXG4gICAgICB9KSk7XHJcblxyXG4gICAgICByaWdodFN1YnNjcmlwdGlvbi5zZXREaXNwb3NhYmxlKHJpZ2h0U291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAocmlnaHQpIHtcclxuICAgICAgICBjaG9pY2VSKCk7XHJcbiAgICAgICAgaWYgKGNob2ljZSA9PT0gcmlnaHRDaG9pY2UpIHtcclxuICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChyaWdodCk7XHJcbiAgICAgICAgfVxyXG4gICAgICB9LCBmdW5jdGlvbiAoZXJyKSB7XHJcbiAgICAgICAgY2hvaWNlUigpO1xyXG4gICAgICAgIGlmIChjaG9pY2UgPT09IHJpZ2h0Q2hvaWNlKSB7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGVycik7XHJcbiAgICAgICAgfVxyXG4gICAgICB9LCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgY2hvaWNlUigpO1xyXG4gICAgICAgIGlmIChjaG9pY2UgPT09IHJpZ2h0Q2hv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LCBiYXNlZCBvbiBhIGNvbXB1dGVkIGtleSB2YWx1ZSwgZnJvbSB0aGUgc291cmNlIHNlcXVlbmNlLlxyXG4gICAgICovXHJcbiAgICBvYnNlcnZhYmxlUHJvdG8uZGlzdGluY3RVbnRpbENoYW5nZWQgPSBmdW5jdGlvbiAoa2V5U2VsZWN0b3IsIGNvbXBhcmVyKSB7XHJcbiAgICAgICAgdmFyIHNvdXJjZSA9IHRoaXM7XHJcbiAgICAgICAga2V5U2VsZWN0b3IgfHwgKGtleVNlbGVjdG9yID0gaWRlbnRpdHkpO1xyXG4gICAgICAgIGNvbXBhcmVyIHx8IChjb21wYXJlciA9IGRlZmF1bHRDb21wYXJlcik7XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgaGFzQ3VycmVudEtleSA9IGZhbHNlLCBjdXJyZW50S2V5O1xyXG4gICAgICAgICAgICByZXR1cm4gc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgICAgIHZhciBjb21wYXJlckVxdWFscyA9IGZhbHNlLCBrZXk7XHJcbiAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgIGtleSA9IGtleVNlbGVjdG9yKHZhbHVlKTtcclxuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGV4Y2VwdGlvbikge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBpZiAoaGFzQ3VycmVudEtleSkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGNvbXBhcmVyRXF1YWxzID0gY29tcGFyZXIoY3VycmVudEtleSwga2V5KTtcclxuICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaWYgKCFoYXNDdXJyZW50S2V5IHx8ICFjb21wYXJlckVxdWFscykge1xyXG4gICAgICAgICAgICAgICAgICAgIGhhc0N1cnJlbnRLZXkgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIGN1cnJlbnRLZXkgPSBrZXk7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHZhbHVlKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgb2JzZXJ2ZXIub25Db21wbGV0ZWQuYmluZChvYnNlcnZlcikpO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgLyoqXHJcbiAgICogIEludm9rZXMgYW4gYWN0aW9uIGZvciBlYWNoIGVsZW1lbnQgaW4gdGhlIG9ic2VydmFibGUgc2VxdWVuY2UgYW5kIGludm9rZXMgYW4gYWN0aW9uIHVwb24gZ3JhY2VmdWwgb3IgZXhjZXB0aW9uYWwgdGVybWluYXRpb24gb2YgdGhlIG9ic2VydmFibGUgc2VxdWVuY2UuXHJcbiAgICogIFRoaXMgbWV0aG9kIGNhbiBiZSB1c2VkIGZvciBkZWJ1Z2dpbmcsIGxvZ2dpbmcsIGV0Yy4gb2YgcXVlcnkgYmVoYXZpb3IgYnkgaW50ZXJjZXB0aW5nIHRoZSBtZXNzYWdlIHN0cmVhbSB0byBydW4gYXJiaXRyYXJ5IGFjdGlvbnMgZm9yIG1lc3NhZ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yT3JPbk5leHQgPT09ICdmdW5jdGlvbicpIHtcclxuICAgICAgb25OZXh0RnVuYyA9IG9ic2VydmVyT3JPbk5leHQ7XHJcbiAgICB9IGVsc2Uge1xyXG4gICAgICBvbk5leHRGdW5jID0gb2JzZXJ2ZXJPck9uTmV4dC5vbk5leHQuYmluZChvYnNlcnZlck9yT25OZXh0KTtcclxuICAgICAgb25FcnJvciA9IG9ic2VydmVyT3JPbk5leHQub25FcnJvci5iaW5kKG9ic2VydmVyT3JPbk5leHQpO1xyXG4gICAgICBvbkNvbXBsZXRlZCA9IG9ic2VydmVyT3JPbk5leHQub25Db21wbGV0ZWQuYmluZChvYnNlcnZlck9yT25OZXh0KTtcclxuICAgIH1cclxuICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgcmV0dXJuIHNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICB0cnkge1xyXG4gICAgICAgICAgb25OZXh0RnVuYyh4KTtcclxuICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgIH1cclxuICAgICAgICBvYnNlcnZlci5vbk5leHQoeCk7XHJcbiAgICAgIH0sIGZ1bmN0aW9uIChlcnIpIHtcclxuICAgICAgICBpZiAob25FcnJvcikge1xyXG4gICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgb25FcnJvcihlcnIpO1xyXG4gICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgIH1cclxuICAgICAgICBvYnNlcnZlci5vbkVycm9yKGVycik7XHJcbiAgICAgIH0sIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICBpZiAob25Db21wbGV0ZWQpIHtcclxuICAgICAgICAgIHRyeS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O1xyXG4gICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgICBpc1Byb21pc2UocmVzdWx0KSAmJiAocmVzdWx0ID0gb2JzZXJ2YWJsZUZyb21Qcm9taXNlKHJlc3VsdCkpO1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdCk7XHJcbiAgICAgICAgfSxcclxuICAgICAgICBmdW5jdGlvbiAoZXJyKSB7XHJcbiAgICAgICAgICB2YXIgcmVzdWx0O1xyXG4gICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgcmVzdWx0ID0gb25FcnJvci5jYWxsKHRoaXNBcmcsIGVycik7XHJcbiAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgIH1cclxuICAgICAgICAgIGlzUHJvbWlzZShyZXN1bHQpICYmIChyZXN1bHQgPSBvYnNlcnZhYmxlRnJvbVByb21pc2UocmVzdWx0KSk7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0KTtcclxuICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgfSxcclxuICAgICAgICBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICB2YXIgcmVzdWx0O1xyXG4gICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgcmVzdWx0ID0gb25Db21wbGV0ZWQuY2FsbCh0aGlzQXJnKTtcclxuICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgICAgaXNQcm9ta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hdWx0VmFsdWUpIHtcclxuICAgICAgICB2YXIgc291cmNlID0gdGhpcztcclxuICAgICAgICBpZiAoZGVmYXVsdFZhbHVlID09PSB1bmRlZmluZWQpIHtcclxuICAgICAgICAgICAgZGVmYXVsdFZhbHVlID0gbnVsbDtcclxuICAgICAgICB9XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgZm91bmQgPSBmYWxzZTtcclxuICAgICAgICAgICAgcmV0dXJuIHNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgIGZvdW5kID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh4KTtcclxuICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKCFmb3VuZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChkZWZhdWx0VmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgfSk7XHJcbiAgICB9O1xyXG5cclxuICAvLyBTd2FwIG91dCBmb3IgQXJyYXkuZmluZEluZGV4XHJcbiAgZnVuY3Rpb24gYXJyYXlJbmRleE9mQ29tcGFyZXIoYXJyYXksIGl0ZW0sIGNvbXBhcmVyKSB7XHJcbiAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gYXJyYXkubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgaWYgKGNvbXBhcmVyKGFycmF5W2ldLCBpdGVtKSkgeyByZXR1cm4gaTsgfVxyXG4gICAgfVxyXG4gICAg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dNYXBFbnRyeSkge1xyXG4gICAgICAgICAgICB2YXIgZ3JvdXAgPSBuZXcgR3JvdXBlZE9ic2VydmFibGUoa2V5LCB3cml0ZXIsIHJlZkNvdW50RGlzcG9zYWJsZSksXHJcbiAgICAgICAgICAgICAgZHVyYXRpb25Hcm91cCA9IG5ldyBHcm91cGVkT2JzZXJ2YWJsZShrZXksIHdyaXRlcik7XHJcbiAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgZHVyYXRpb24gPSBkdXJhdGlvblNlbGVjdG9yKGR1cmF0aW9uR3JvdXApO1xyXG4gICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgbWFwLmdldFZhbHVlcygpLmZvckVhY2goaGFuZGxlRXJyb3IoZSkpO1xyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoZ3JvdXApO1xyXG5cclxuICAgICAgICAgICAgdmFyIG1kID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgICAgIGdyb3VwRGlzcG9zYWJsZS5hZGQobWQpO1xyXG5cclxuICAgICAgICAgICAgdmFyIGV4cGlyZSA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICBtYXAucmVtb3ZlKGtleSkgJiYgd3JpdGVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgZ3JvdXBEaXNwb3NhYmxlLnJlbW92ZShtZCk7XHJcbiAgICAgICAgICAgIH07XHJcblxyXG4gICAgICAgICAgICBtZC5zZXREaXNwb3NhYmxlKGR1cmF0aW9uLnRha2UoMSkuc3Vic2NyaWJlKFxyXG4gICAgICAgICAgICAgIG5vb3AsXHJcbiAgICAgICAgICAgICAgZnVuY3Rpb24gKGV4bikge1xyXG4gICAgICAgICAgICAgICAgbWFwLmdldFZhbHVlcygpLmZvckVhY2goaGFuZGxlRXJyb3IoZXhuKSk7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4bik7XHJcbiAgICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgICBleHBpcmUpXHJcbiAgICAgICAgICAgICk7XHJcbiAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgdmFyIGVsZW1lbnQ7XHJcbiAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICBlbGVtZW50ID0gZWxlbWVudFNlbGVjdG9yKHgpO1xyXG4gICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICBtYXAuZ2V0VmFsdWVzKCkuZm9yRWFjaChoYW5kbGVFcnJvcihlKSk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICB3cml0ZXIub25OZXh0KGVsZW1lbnQpO1xyXG4gICAgICB9LCBmdW5jdGlvbiAoZXgpIHtcclxuICAgICAgICBtYXAuZ2V0VmFsdWVzKCkuZm9yRWFjaChoYW5kbGVFcnJvcihleCkpO1xyXG4gICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXgpO1xyXG4gICAgICB9LCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgbWFwLmdldFZhbHVlcygpLmZvckVhY2goZnVuY3Rpb24gKGl0ZW0pIHsgaXRlbS5vbkNvbXBsZXRlZCgpOyB9KTtcclxuICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICB9KSk7XHJcblxyXG4gICAgICByZXR1cm4gcmVmQ291bnREaXNwb3NhYmxlO1xyXG4gICAgfSk7XHJcbiAgfTtcclxuXHJcbiAgLyoqXHJcbiAgICogIFByb2plY3RzIGVhY2ggZWxlbWVudCBvZiBhbiBvYnNlcnZh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vcm0gZnVuY3Rpb24gY29ycmVzcG9uZGluZyB0byBlYWNoIG5vdGlmaWNhdGlvbiBpbiB0aGUgaW5wdXQgc2VxdWVuY2UuXHJcbiAgICovXHJcbiAgb2JzZXJ2YWJsZVByb3RvLmZsYXRNYXBPYnNlcnZlciA9IG9ic2VydmFibGVQcm90by5zZWxlY3RNYW55T2JzZXJ2ZXIgPSBmdW5jdGlvbiAob25OZXh0LCBvbkVycm9yLCBvbkNvbXBsZXRlZCwgdGhpc0FyZykge1xyXG4gICAgdmFyIHNvdXJjZSA9IHRoaXM7XHJcbiAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgIHZhciBpbmRleCA9IDA7XHJcblxyXG4gICAgICByZXR1cm4gc291cmNlLnN1YnNjcmliZShcclxuICAgICAgICBmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgdmFyIHJlc3VsdDtcclxuICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgIHJlc3VsdCA9IG9uTmV4dC5jYWxsKHRoaXNBcmcsIHgsIGluZGV4KyspO1xyXG4gICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgICBpc1Byb21pc2UocmVzdWx0KSAmJiAocmVzdWx0ID0gb2JzZXJ2YWJsZUZyb21Qcm9taXNlKHJlc3VsdCkpO1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdCk7XHJcbiAgICAgICAgfSxcclxuICAgICAgICBmdW5jdGlvbiAoZXJyKSB7XHJcbiAgICAgICAgICB2YXIgcmVzdWx0O1xyXG4gICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgcmVzdWx0ID0gb25FcnJvci5jYWxsKHRoaXNBcmcsIGVycik7XHJcbiAgICAgIC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aXNvbiA9IDA7XHJcbiAgICAgICAgaWYgKCFoYXNWYWx1ZSkge1xyXG4gICAgICAgICAgaGFzVmFsdWUgPSB0cnVlO1xyXG4gICAgICAgICAgbGFzdEtleSA9IGtleTtcclxuICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgY29tcGFyaXNvbiA9IGNvbXBhcmVyKGtleSwgbGFzdEtleSk7XHJcbiAgICAgICAgICB9IGNhdGNoIChleDEpIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleDEpO1xyXG4gICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGlmIChjb21wYXJpc29uID4gMCkge1xyXG4gICAgICAgICAgbGFzdEtleSA9IGtleTtcclxuICAgICAgICAgIGxpc3QgPSBbXTtcclxuICAgICAgICB9XHJcbiAgICAgICAgaWYgKGNvbXBhcmlzb24gPj0gMCkgeyBsaXN0LnB1c2goeCk7IH1cclxuICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIG9ic2VydmVyLm9uTmV4dChsaXN0KTtcclxuICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICB9KTtcclxuICAgIH0pO1xyXG4gIH1cclxuXHJcbiAgICBmdW5jdGlvbiBmaXJzdE9ubHkoeCkge1xyXG4gICAgICAgIGlmICh4Lmxlbmd0aCA9PT0gMCkge1xyXG4gICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3Ioc2VxdWVuY2VDb250YWluc05vRWxlbWVudHMpO1xyXG4gICAgICAgIH1cclxuICAgICAgICByZXR1cm4geFswXTtcclxuICAgIH1cclxuXHJcbiAgICAvKipcclxuICAgICAqIEFwcGxpZXMgYW4gYWNjdW11bGF0b3IgZnVuY3Rpb24gb3ZlciBhbiBvYnNlcnZhYm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ICAgICAgICBzdW06IDAsXHJcbiAgICAgICAgICAgICAgICBjb3VudDogMFxyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAocHJldiwgY3VyKSB7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4ge1xyXG4gICAgICAgICAgICAgICAgICAgIHN1bTogcHJldi5zdW0gKyBjdXIsXHJcbiAgICAgICAgICAgICAgICAgICAgY291bnQ6IHByZXYuY291bnQgKyAxXHJcbiAgICAgICAgICAgICAgICB9O1xyXG4gICAgICAgICAgICB9KS5maW5hbFZhbHVlKCkuc2VsZWN0KGZ1bmN0aW9uIChzKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAocy5jb3VudCA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcignVGhlIGlucHV0IHNlcXVlbmNlIHdhcyBlbXB0eScpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgcmV0dXJuIHMuc3VtIC8gcy5jb3VudDtcclxuICAgICAgICAgICAgfSk7XHJcbiAgICB9O1xyXG5cclxuICBmdW5jdGlvbiBzZXF1ZW5jZUVxdWFsQXJyYXkoZmlyc3QsIHNlY29uZCwgY29tcGFyZXIpIHtcclxuICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgdmFyIGNvdW50ID0gMCwgbGVuID0gc2Vjb25kLmxlbmd0aDtcclxuICAgICAgcmV0dXJuIGZpcnN0LnN1YnNjcmliZShmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICB2YXIgZXF1YWwgPSBmYWxzZTtcclxuICAgICAgICB0cnkge1xyXG4gICAgICAgICAgY291bnQgPCBsZW4gJiYgKGVxdWFsID0gY29tcGFyZXIodmFsdWUsIHNlY29uZFtjb3VudCsrXSkpO1xyXG4gICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgIG9ic2VydmV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4gICAgICB2YXIgc3Vic2NyaXB0aW9uMSA9IGZpcnN0LnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgIHZhciBlcXVhbCwgdjtcclxuICAgICAgICBpZiAocXIubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgdiA9IHFyLnNoaWZ0KCk7XHJcbiAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICBlcXVhbCA9IGNvbXBhcmVyKHYsIHgpO1xyXG4gICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgICBpZiAoIWVxdWFsKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChmYWxzZSk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgfSBlbHNlIGlmIChkb25lcikge1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGZhbHNlKTtcclxuICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgIHFsLnB1c2goeCk7XHJcbiAgICAgICAgfVxyXG4gICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgZG9uZWwgPSB0cnVlO1xyXG4gICAgICAgIGlmIChxbC5sZW5ndGggPT09IDApIHtcclxuICAgICAgICAgIGlmIChxci5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChmYWxzZSk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICB9IGVsc2UgaWYgKGRvbmVyKSB7XHJcbiAgIC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b24gKCkge1xyXG4gICAgICAgIGRvbmVyID0gdHJ1ZTtcclxuICAgICAgICBpZiAocXIubGVuZ3RoID09PSAwKSB7XHJcbiAgICAgICAgICBpZiAocWwubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoZmFsc2UpO1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgfSBlbHNlIGlmIChkb25lbCkge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQodHJ1ZSk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgfVxyXG4gICAgICB9KTtcclxuICAgICAgcmV0dXJuIG5ldyBDb21wb3NpdGVEaXNwb3NhYmxlKHN1YnNjcmlwdGlvbjEsIHN1YnNjcmlwdGlvbjIpO1xyXG4gICAgfSk7XHJcbiAgfTtcclxuXHJcbiAgICBmdW5jdGlvbiBlbGVtZW50QXRPckRlZmF1bHQoc291cmNlLCBpbmRleCwgaGFzRGVmYXVsdCwgZGVmYXVsdFZhbHVlKSB7XHJcbiAgICAgICAgaWYgKGluZGV4IDwgMCkge1xyXG4gICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoYXJndW1lbnRPdXRPZlJhbmdlKTtcclxuICAgICAgICB9XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgaSA9IGluZGV4O1xyXG4gICAgICAgICAgICByZXR1cm4gc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKGkgPT09IDApIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGktLTtcclxuICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKCFoYXNEZWZhdWx0KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihuZXcgRXJyb3IoYXJndW1lbnRPdXRPZlJhbmdlKSk7XHJcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChkZWZhdWx0VmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfVxyXG5cclxuICAgIC8qKlxyXG4gICAgICogUmV0dXJucyB0aGUgZWxlbWVudCBhdCBhIHNwZWNpZmllZCBpbmRleCBpbiBhIHNlcXVlbmNlLlxyXG4gICAgICogQGV4YW1wbGVcclxuICAgICAqIHZhciByZXMgPSBzb3VyY2UuZWxlbWVudEF0KDUpO1xyXG4gICAgICogQHBhcmFtIHtOdW1iZXJ9IGluZGV4IFRoZSB6ZXJvLWJhc2VkIGluZGV4IG9mIHRoZSBlbGVtZW50IHRvIHJldHJpZXZlLlxyXG4gICAgICogQHJldHVybnMge09ic2VydmFibGV9IEFuIG9ic2VydmFibGUgc2VxdWVuY2UgdGhhdCBwcm9kdWNlcyB0aGUgZWxlbWVudCBhdCB0aGUgc3BlY2lmaWVkIHBvc2l0aW9uIGluIHRoZSBzb3VyY2Ugc2VxdWVuY2UuXHJcbiAgICAgKi9cclxuICAgIG9ic2VydmFibGVQcm90by5lbGVtZW50QXQgPSAgZnVuY3Rpb24gKGluZGV4KSB7XHJcbiAgICAg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kaWNhdGUpLmZpcnN0T3JEZWZhdWx0KG51bGwsIGRlZmF1bHRWYWx1ZSkgOlxyXG4gICAgICAgICAgICBmaXJzdE9yRGVmYXVsdEFzeW5jKHRoaXMsIHRydWUsIGRlZmF1bHRWYWx1ZSk7XHJcbiAgICB9O1xyXG5cclxuICAgIGZ1bmN0aW9uIGxhc3RPckRlZmF1bHRBc3luYyhzb3VyY2UsIGhhc0RlZmF1bHQsIGRlZmF1bHRWYWx1ZSkge1xyXG4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIHZhbHVlID0gZGVmYXVsdFZhbHVlLCBzZWVuVmFsdWUgPSBmYWxzZTtcclxuICAgICAgICAgICAgcmV0dXJuIHNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgIHZhbHVlID0geDtcclxuICAgICAgICAgICAgICAgIHNlZW5WYWx1ZSA9IHRydWU7XHJcbiAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIGlmICghc2VlblZhbHVlICYmICFoYXNEZWZhdWx0KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihuZXcgRXJyb3Ioc2VxdWVuY2VDb250YWluc05vRWxlbWVudHMpKTtcclxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHZhbHVlKTtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICB9KTtcclxuICAgIH1cclxuXHJcbiAgICAvKipcclxuICAgICAqIFJldHVybn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mdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICB2YXIgbSA9IG5ldyByb290Lk1hcCgpO1xyXG4gICAgICAgIHJldHVybiBzb3VyY2Uuc3Vic2NyaWJlKFxyXG4gICAgICAgICAgZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgdmFyIGtleTtcclxuICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICBrZXkgPSBrZXlTZWxlY3Rvcih4KTtcclxuICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICB2YXIgZWxlbWVudCA9IHg7XHJcbiAgICAgICAgICAgIGlmIChlbGVtZW50U2VsZWN0b3IpIHtcclxuICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgZWxlbWVudCA9IGVsZW1lbnRTZWxlY3Rvcih4KTtcclxuICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgbS5zZXQoa2V5LCBlbGVtZW50KTtcclxuICAgICAgICAgIH0sXHJcbiAgICAgICAgICBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLFxyXG4gICAgICAgICAgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQobSk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICB9KTtcclxuICAgICAgfSk7XHJcbiAgICB9O1xyXG4gIH1cclxuXHJcbiAgdmFyIGZuU3RyaW5nID0gJ2Z1bmN0aW9uJztcclxuXHJcbiAgZnVuY3Rpb24gdG9UaHVuayhvYmosIGN0eCkge1xyXG4gICAgaWYgKEFycmF5LmlzQXJyYXkob2JqKSkge1xyXG4gICAgICByZXR1cm4gb2JqZWN0VG9UaHVuay5jYWxsKGN0eCwgb2JqKTtcclxuICAgIH1cclxuXHJcbiAgICBpZiAoaXNHZW5lcmF0b3JGdW5jdGlvbihvYmopKSB7XHJcbiAgICAgIHJldHVybiBvYnNlcnZhYmxlU3Bhd24ob2JqLmNhbGwoY3R4KSk7XHJcbiAgICB9XHJcblxyXG4gICAgaWYgKGlzR2VuZXJhdG9yKG9iaikpIHtcclxuICAgICAgcmV0dXJuIG9ic2VydmFibGVTcGF3bihvYmopO1xyXG4gICAgfVxyXG5cclxuICAgIGlmIChpc09ic2VydmFibGUob2JqKSkge1xyXG4gICAgICByZXR1cm4gb2JzZXJ2YWJsZVRvVGh1bmsob2JqKTtcclxuICAgIH1cclxuXHJcbiAgICBpZiAoaXNQcm9taXNlKG9iaikpIHtcclxuICAgICAgcmV0dXJuIHByb21pc2VUb1RodW5rKG9iaik7XHJcbiAgICB9XHJcblxyXG4gICAgaWYgKHR5cGVvZiBvYmogPT09IGZuU3RyaW5nKSB7XHJcbiAgICAgIHJldHVybiBvYmo7XHJcbiAgICB9XHJcblxyXG4gICAgaWYgKGlzT2JqZWN0KG9iaikgfHwgQXJyYXkuaXNBcnJheShvYmopKSB7XHJcbiAgICAgIHJldHVybiBvYmplY3RUb1RodW5rLmNhbGwoY3R4LCBvYmopO1xyXG4gICAgfVxyXG5cclxuICAgIHJldHVybiBvYmo7XHJcbiAgfVxyXG5cclxuICBmdW5jdGlvbiBvYmplY3RUb1RodW5rKG9iaikge1xyXG4gICAgdmFyIGN0eCA9IHRoaXM7XHJcblxyXG4gICAgcmV0dXJuIGZ1bmN0aW9uIChkb25lKSB7XHJcbiAgICAgIHZhciBrZXlzID0gT2JqZWN0LmtleXMob2JqKSxcclxuICAgICAgICAgIHBlbmRpbmcgPSBrZXlzLmxlbmd0aCxcclxuICAgICAgICAgIHJlc3VsdHMgPSBuZXcgb2JqLmNvbnN0cnVjdG9yKCksXHJcbiAgICAgICAgICBmaW5pc2hlZDtcclxuXHJcbiAgICAgIGlmICghcGVuZGluZykge1xyXG4gICAgICAgIHRpbWVvdXRTY2hlZHVsZXIuc2NoZWR1bGUoZnVuY3Rpb24gKCkgeyBkb25lKG51bGwsIHJlc3VsdHMpOyB9KTtcclxuICAgICAgICByZXR1cm47XHJcbiAgICAgIH1cclxuXHJcbiAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSBrZXlzLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgcnVuKG9ialtrZXlzW2ldXSwga2V5c1tpXSk7XHJcbiAgICAgIH1cclxuXHJcbiAgICAgIGZ1bmN0aW9uIHJ1bihmbiwga2V5KSB7XHJcbiAgICAgICAgaWYgKGZpbmlzaGVkKSB7IHJldHVybjsgfVxyXG4gICAgICAgIHRyeSB7XHJcbiAgICAgICAgICBmbiA9IHRvVGh1bmsoZm4sIGN0eCk7XHJcblxyXG4gICAgICAgICAgaWYgKHR5cGVvZiBmbiAhPT0gZm5TdHJpbmcpIHtcclxuICAgICAgICAgICAgcmVzdWx0c1trZXldID0gZm47XHJcbiAgICAgICAgICAgIHJldHVybiAtLXBlbmRpbmcgfHwgZG9uZShudWxsLCByZXN1bHRzKTtcclxuICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICBmbi5jYWxsKGN0eCwgZnVuY3Rpb24oZXJyLCByZXMpe1xyXG4gICAgICAgICAgICBpZiAoZmluaXNoZWQpIHsgcmV0dXJuOyB9XHJcblxyXG4gICAgICAgICAgICBpZiAoZXJyKSB7XHJcbiAgICAgICAgICAgICAgZmluaXNoZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgIHJldHVybiBkb25lKGVycik7XHJcbiAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgIHJlc3Vs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dlbkZ1bikge1xyXG4gICAgICAgIHZhciBhcmdzID0gc2xpY2UuY2FsbChhcmd1bWVudHMpLFxyXG4gICAgICAgICAgbGVuID0gYXJncy5sZW5ndGgsXHJcbiAgICAgICAgICBoYXNDYWxsYmFjayA9IGxlbiAmJiB0eXBlb2YgYXJnc1tsZW4gLSAxXSA9PT0gZm5TdHJpbmc7XHJcblxyXG4gICAgICAgIGRvbmUgPSBoYXNDYWxsYmFjayA/IGFyZ3MucG9wKCkgOiBlcnJvcjtcclxuICAgICAgICBnZW4gPSBmbi5hcHBseSh0aGlzLCBhcmdzKTtcclxuICAgICAgfSBlbHNlIHtcclxuICAgICAgICBkb25lID0gZG9uZSB8fCBlcnJvcjtcclxuICAgICAgfVxyXG5cclxuICAgICAgbmV4dCgpO1xyXG5cclxuICAgICAgZnVuY3Rpb24gZXhpdChlcnIsIHJlcykge1xyXG4gICAgICAgIHRpbWVvdXRTY2hlZHVsZXIuc2NoZWR1bGUoZG9uZS5iaW5kKGN0eCwgZXJyLCByZXMpKTtcclxuICAgICAgfVxyXG5cclxuICAgICAgZnVuY3Rpb24gbmV4dChlcnIsIHJlcykge1xyXG4gICAgICAgIHZhciByZXQ7XHJcblxyXG4gICAgICAgIC8vIG11bHRpcGxlIGFyZ3NcclxuICAgICAgICBpZiAoYXJndW1lbnRzLmxlbmd0aCA+IDIpIHJlcyA9IHNsaWNlLmNhbGwoYXJndW1lbnRzLCAxKTtcclxuXHJcbiAgICAgICAgaWYgKGVycikge1xyXG4gICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgcmV0ID0gZ2VuLnRocm93KGVycik7XHJcbiAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgIHJldHVybiBleGl0KGUpO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgaWYgKCFlcnIpIHtcclxuICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgIHJldCA9IGdlbi5uZXh0KHJlcyk7XHJcbiAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgIHJldHVybiBleGl0KGUpO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgaWYgKHJldC5kb25lKSAge1xyXG4gICAgICAgICAgcmV0dXJuIGV4aXQobnVsbCwgcmV0LnZhbHVlKTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIHJldC52YWx1ZSA9IHRvVGh1bmsocmV0LnZhbHVlLCBjdHgpO1xyXG5cclxuICAgICAgICBpZiAodHlwZW9mIHJldC52YWx1ZSA9PT0gZm5TdHJpbmcpIHtcclxuICAgICAgICAgIHZhciBjYWxsZWQgPSBmYWxzZTtcclxuICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgIHJldC52YWx1ZS5jYWxsKGN0eCwgZnVuY3Rpb24oKXtcclxuICAgICAgICAgICAgICBpZiAoY2FsbGVkKSB7XHJcbiAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICBjYWxsZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgIG5leHQuYXBwbHkoY3R4LCBhcmd1bWVudHMpO1xyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgdGltZW91dFNjaGVkdWxlci5zY2hlZHVsZShmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgaWYgKGNhbGxlZCkge1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgY2FsbGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICBuZXh0LmNhbGwoY3R4LCBlKTtcclxuICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICA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xuICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0cyk7XHJcbiAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICBpZiAocmVzdWx0cy5sZW5ndGggPD0gMSkge1xyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dC5hcHBseShvYnNlcnZlciwgcmVzdWx0cyk7XHJcbiAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdHMpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGFyZ3MucHVzaChoYW5kbGVyKTtcclxuICAgICAgICBmdW5jLmFwcGx5KGNvbnRleHQsIGFyZ3MpO1xyXG4gICAgICB9KS5wdWJsaXNoTGFzdCgpLnJlZkNvdW50KCk7XHJcbiAgICB9O1xyXG4gIH07XHJcblxyXG4gIGZ1bmN0aW9uIGNyZWF0ZUxpc3RlbmVyIChlbGVtZW50LCBuYW1lLCBoYW5kbGVyKSB7XHJcbiAgICBpZiAoZWxlbWVudC5hZGRFdmVudExpc3RlbmVyKSB7XHJcbiAgICAgIGVsZW1lbnQuYWRkRXZlbnRMaXN0ZW5lcihuYW1lLCBoYW5kbGVyLCBmYWxzZSk7XHJcbiAgICAgIHJldHVybiBkaXNwb3NhYmxlQ3JlYXRlKGZ1bmN0aW9uICgpIHtcclxuICAgICAgICBlbGVtZW50LnJlbW92ZUV2ZW50TGlzdGVuZXIobmFtZSwgaGFuZGxlciwgZmFsc2UpO1xyXG4gICAgICB9KTtcclxuICAgIH1cclxuICAgIHRocm93IG5ldyBFcnJvcignTm8gbGlzdGVuZ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SAhPSBwcmV2aW91c1Nob3VsZEZpcmUpIHtcclxuICAgICAgICAgICAgICAgIHByZXZpb3VzU2hvdWxkRmlyZSA9IHJlc3VsdHMuc2hvdWxkRmlyZTtcclxuICAgICAgICAgICAgICAgIC8vIGNoYW5nZSBpbiBzaG91bGRGaXJlXHJcbiAgICAgICAgICAgICAgICBpZiAocmVzdWx0cy5zaG91bGRGaXJlKSB7XHJcbiAgICAgICAgICAgICAgICAgIHdoaWxlIChxLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocS5zaGlmdCgpKTtcclxuICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICBwcmV2aW91c1Nob3VsZEZpcmUgPSByZXN1bHRzLnNob3VsZEZpcmU7XHJcbiAgICAgICAgICAgICAgICAvLyBuZXcgZGF0YVxyXG4gICAgICAgICAgICAgICAgaWYgKHJlc3VsdHMuc2hvdWxkRmlyZSkge1xyXG4gICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0cy5kYXRhKTtcclxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgIHEucHVzaChyZXN1bHRzLmRhdGEpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgZnVuY3Rpb24gKGVycikge1xyXG4gICAgICAgICAgICAgIC8vIEVtcHR5IGJ1ZmZlciBiZWZvcmUgc2VuZGluZyBlcnJvclxyXG4gICAgICAgICAgICAgIHdoaWxlIChxLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChxLnNoaWZ0KCkpO1xyXG4gICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm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1ZS5sZW5ndGggPT09IDApIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLnN1YmplY3Qub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgb25FcnJvcjogZnVuY3Rpb24gKGVycm9yKSB7XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmhhc0ZhaWxlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmVycm9yID0gZXJyb3I7XHJcblxyXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmVuYWJsZVF1ZXVlIHx8IHRoaXMucXVldWUubGVuZ3RoID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5zdWJqZWN0Lm9uRXJyb3IoZXJyb3IpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICBvbk5leHQ6IGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgdmFyIGhhc1JlcXVlc3RlZCA9IGZhbHNlO1xyXG5cclxuICAgICAgICAgICAgICAgIGlmICh0aGlzLnJlcXVlc3RlZENvdW50ID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMuZW5hYmxlUXVldWUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5xdWV1ZS5wdXNoKHZhbHVlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLnJlcXVlc3RlZENvdW50ICE9PSAtMSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5yZXF1ZXN0ZWRDb3VudC0tID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLmRpc3Bvc2VDdXJyZW50UmVxdWVzdCgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIGhhc1JlcXVlc3RlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgaWYgKGhhc1JlcXVlc3RlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuc3ViamVjdC5vbk5leHQodmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICBfcHJvY2Vzc1JlcXVlc3Q6IGZ1bmN0aW9uIChudW1iZXJPZkl0ZW1zKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5lbmFibGVRdWV1ZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIC8vY29uc29sZS5sb2coJ3F1ZXVlIGxlbmd0aCcsIHRoaXMucXVldWUubGVuZ3RoKTtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgd2hpbGUgKHRoaXMucXVldWUubGVuZ3RoID49IG51bWJlck9mSXRlbXMgJiYgbnVtYmVyT2ZJdGVtcyA+IDApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgLy9jb25zb2xlLmxvZygnbnVtYmVyIG9mIGl0ZW1zJywgbnVtYmVyT2ZJdGVtcyk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuc3ViamVjdC5vbk5leHQodGhpcy5xdWV1ZS5zaGlmdCgpKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgbnVtYmVyT2ZJdGVtcy0tO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMucXVldWUubGVuZ3RoICE9PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiB7IG51bWJlck9mSXRlbXM6IG51bWJlck9mSXRlbXMsIHJldHVyblZhbHVlOiB0cnVlIH07XHJcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHsgbnVtYmVyT2ZJdGVtczogbnVtYmVyT2ZJdGVtcywgcmV0dXJuVmFsdWU6IGZhbHNlIH07XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgIGlmICh0aGlzLmhhc0ZhaWxlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuc3ViamVjdC5vbkVycm9yKHRoaXMuZXJyb3IpO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuY29udHJvbGxlZERpc3Bvc2FibGUuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuY29udHJvbGxlZERpc3Bvc2FibGUgPSBkaXNwb3NhYmxlRW1wdHk7XHJcbiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHRoaXMuaGFzQ29tcGxldGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5zdWJqZWN0Lm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5jb250cm9sbGVkRGlzcG9zYWJsZS5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5jb250cm9sbGVkRGlzcG9zYWJsZSA9IGRpc3Bvc2FibGVFbXB0eTtcclxuICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICByZXR1cm4geyBudW1iZXJPZkl0ZW1zOiBudW1iZXJPZkl0ZW1zLCByZXR1cm5WYWx1ZTogZmFsc2UgfTtcclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgcmVxdWVzdDogZnVuY3Rpb24gKG51bWJlcikge1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgdGhpcy5kaXNwb3NlQ3VycmVudFJlcXVlc3QoKTtcclxuICAgICAgICAgICAgICAgIHZhciBzZWxmID0gdGhpcyxcclxuICAgICAgICAgICAgICAgICAgICByID0gdGhpcy5fcHJvY2Vzc1JlcXVlc3QobnVtYmVyKTtcclxuXHJcbiAgICAgICAgICAgICAgICBudW1iZXIgPSByLm51bWJlck9mSXRlbXM7XHJcbiAgICAgICAgICAgICAgICBpZiAoIXIucmV0dXJuVmFsdWUpIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLnJlcXVlc3RlZENvdW50ID0gbnVtYmVyO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMucmVxdWVzdGVkRGlzcG9zYWJsZSA9IGRpc3Bvc2FibGVDcmVhdGUoZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBzZWxmLnJlcXVlc3RlZENvdW50ID0gMDtcclxuICAgICAgICAgICAgICAgICAgICB9KTtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHRoaXMucmVxdWVzdGVkRGlzcG9zYWJsZVxyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gZGlzcG9zYWJsZUVtcHR5O1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICBkaXNwb3NlQ3VycmVudFJlcXVlc3Q6IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMucmVxdWVzdGVkRGlzcG9zYWJsZS5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgICAgICB0aGlzLnJlcXVlc3RlZERpc3Bvc2FibGUgPSBkaXNwb3NhYmxlRW1wdHk7XHJcbiAgICAgICAgIC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bXBhcmVyKHRoaXMuZW50cmllc1tpbmRleDNdLmtleSwga2V5KSkge1xyXG4gICAgICAgICAgICBpZiAoaW5kZXgyIDwgMCkge1xyXG4gICAgICAgICAgICAgIHRoaXMuYnVja2V0c1tpbmRleDFdID0gdGhpcy5lbnRyaWVzW2luZGV4M10ubmV4dDtcclxuICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICB0aGlzLmVudHJpZXNbaW5kZXgyXS5uZXh0ID0gdGhpcy5lbnRyaWVzW2luZGV4M10ubmV4dDtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB0aGlzLmVudHJpZXNbaW5kZXgzXS5oYXNoQ29kZSA9IC0xO1xyXG4gICAgICAgICAgICB0aGlzLmVudHJpZXNbaW5kZXgzXS5uZXh0ID0gdGhpcy5mcmVlTGlzdDtcclxuICAgICAgICAgICAgdGhpcy5lbnRyaWVzW2luZGV4M10ua2V5ID0gbnVsbDtcclxuICAgICAgICAgICAgdGhpcy5lbnRyaWVzW2luZGV4M10udmFsdWUgPSBudWxsO1xyXG4gICAgICAgICAgICB0aGlzLmZyZWVMaXN0ID0gaW5kZXgzO1xyXG4gICAgICAgICAgICArK3RoaXMuZnJlZUNvdW50O1xyXG4gICAgICAgICAgICByZXR1cm4gdHJ1ZTtcclxuICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgIGluZGV4MiA9IGluZGV4MztcclxuICAgICAgICAgIH1cclxuICAgICAgICB9XHJcbiAgICAgIH1cclxuICAgICAgcmV0dXJuIGZhbHNlO1xyXG4gICAgfTtcclxuXHJcbiAgICBkaWN0aW9uYXJ5UHJvdG8uY2xlYXIgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgIHZhciBpbmRleCwgbGVuO1xyXG4gICAgICBpZiAodGhpcy5zaXplIDw9IDApIHsgcmV0dXJuOyB9XHJcbiAgICAgIGZvciAoaW5kZXggPSAwLCBsZW4gPSB0aGlzLmJ1Y2tldHMubGVuZ3RoOyBpbmRleCA8IGxlbjsgKytpbmRleCkge1xyXG4gICAgICAgIHRoaXMuYnVja2V0c1tpbmRleF0gPSAtMTtcclxuICAgICAgfVxyXG4gICAgICBmb3IgKGluZGV4ID0gMDsgaW5kZXggPCB0aGlzLnNpemU7ICsraW5kZXgpIHtcclxuICAgICAgICB0aGlzLmVudHJpZXNbaW5kZXhdID0gbmV3RW50cnkoKTtcclxuICAgICAgfVxyXG4gICAgICB0aGlzLmZyZWVMaXN0ID0gLTE7XHJcbiAgICAgIHRoaXMuc2l6ZSA9IDA7XHJcbiAgICB9O1xyXG5cclxuICAgIGRpY3Rpb25hcnlQcm90by5fZmluZEVudHJ5ID0gZnVuY3Rpb24gKGtleSkge1xyXG4gICAgICBpZiAodGhpcy5idWNrZXRzKSB7XHJcbiAgICAgICAgdmFyIG51bSA9IGdldEhhc2hDb2RlKGtleSkgJiAyMTQ3NDgzNjQ3O1xyXG4gICAgICAgIGZvciAodmFyIGluZGV4ID0gdGhpcy5idWNrZXRzW251bSAlIHRoaXMuYnVja2V0cy5sZW5ndGhdOyBpbmRleCA+PSAwOyBpbmRleCA9IHRoaXMuZW50cmllc1tpbmRleF0ubmV4dCkge1xyXG4gICAgICAgICAgaWYgKHRoaXMuZW50cmllc1tpbmRleF0uaGFzaENvZGUgPT09IG51bSAmJiB0aGlzLmNvbXBhcmVyKHRoaXMuZW50cmllc1tpbmRleF0ua2V5LCBrZXkpKSB7XHJcbiAgICAgICAgICAgIHJldHVybiBpbmRleDtcclxuICAgICAgICAgIH1cclxuICAgICAgICB9XHJcbiAgICAgIH1cclxuICAgICAgcmV0dXJuIC0xO1xyXG4gICAgfTtcclxuXHJcbiAgICBkaWN0aW9uYXJ5UHJvdG8uY291bnQgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgIHJldHVybiB0aGlzLnNpemUgLSB0aGlzLmZyZWVDb3VudDtcclxuICAgIH07XHJcblxyXG4gICAgZGljdGlvbmFyeVByb3RvLnRyeUdldFZhbHVlID0gZnVuY3Rpb24gKGtleSkge1xyXG4gICAgICB2YXIgZW50cnkgPSB0aGlzLl9maW5kRW50cnkoa2V5KTtcclxuICAgICAgcmV0dXJuIGVudHJ5ID49IDAgP1xyXG4gICAgICAgIHRoaXMuZW50cmllc1tlbnRyeV0udmFsdWUgOlxyXG4gICAgICAgIHVuZGVmaW5lZDtcclxuICAgIH07XHJcblxyXG4gICAgZGljdGlvbmFyeVByb3RvLmdldFZhbHVlcyA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgdmFyIGluZGV4ID0gMCwgcmVzdWx0cyA9IFtdO1xyXG4gICAgICBpZiAodGhpcy5lbnRyaWVzKSB7XHJcbiAgICAgICAgZm9yICh2YXIgaW5kZXgxID0gMDsgaW5kZXgxIDwgdGhpcy5zaXplOyBpbmRleDErKykge1xyXG4gICAgICAgICAgaWYgKHRoaXMuZW50cmllc1tpbmRleDFdLmhhc2hDb2RlID49IDApIHtcclxuICAgICAgICAgICAgcmVzdWx0c1tpbmRleCsrXSA9IHRoaXMuZW50cmllc1tpbmRleDFdLnZhbHVlO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgIH1cclxuICAgICAgfVxyXG4gICAgICByZXR1cm4gcmVzdWx0cztcclxuICAgIH07XHJcblxyXG4gICAgZGljdGlvbmFyeVByb3RvLmdldCA9IGZ1bmN0aW9uIChrZXkpIHtcclxuICAgICAgdmFyIGVudHJ5ID0gdGhpcy5fZmluZEVudHJ5KGtleSk7XHJcbiAgICAgIGlmIChlbnRyeSA+PSAwKSB7IHJldHVybiB0aGlzLmVudHJpZXNbZW50cnldLnZhbHVlOyB9XHJcbiAgICAgIHRocm93IG5ldyBFcnJvcihub1N1Y2hrZXkpO1xyXG4gICAgfTtcclxuXHJcbiAgICBkaWN0aW9uYXJ5UHJvdG8uc2V0ID0gZnVuY3Rpb24gKGtleSwgdmFsdWUpIHtcclxuICAgICAgdGhpcy5faW5zZXJ0KGtleSwgdmFsdWUsIGZhbHNlKTtcclxuICAgIH07X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wLmFkZChsZWZ0LnN1YnNjcmliZShcclxuICAgICAgICBmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgIHZhciBpZCA9IGxlZnRJZCsrO1xyXG4gICAgICAgICAgdmFyIG1kID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcblxyXG4gICAgICAgICAgbGVmdE1hcC5hZGQoaWQsIHZhbHVlKTtcclxuICAgICAgICAgIGdyb3VwLmFkZChtZCk7XHJcblxyXG4gICAgICAgICAgdmFyIGV4cGlyZSA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgbGVmdE1hcC5yZW1vdmUoaWQpICYmIGxlZnRNYXAuY291bnQoKSA9PT0gMCAmJiBsZWZ0RG9uZSAmJiBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICBncm91cC5yZW1vdmUobWQpO1xyXG4gICAgICAgICAgfTtcclxuXHJcbiAgICAgICAgICB2YXIgZHVyYXRpb247XHJcbiAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICBkdXJhdGlvbiA9IGxlZnREdXJhdGlvblNlbGVjdG9yKHZhbHVlKTtcclxuICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgfVxyXG5cclxuICAgICAgICAgIG1kLnNldERpc3Bvc2FibGUoZHVyYXRpb24udGFrZSgxKS5zdWJzY3JpYmUobm9vcCwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZXhwaXJlKSk7XHJcblxyXG4gICAgICAgICAgcmlnaHRNYXAuZ2V0VmFsdWVzKCkuZm9yRWFjaChmdW5jdGlvbiAodikge1xyXG4gICAgICAgICAgICB2YXIgcmVzdWx0O1xyXG4gICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgIHJlc3VsdCA9IHJlc3VsdFNlbGVjdG9yKHZhbHVlLCB2KTtcclxuICAgICAgICAgICAgfSBjYXRjaCAoZXhuKSB7XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleG4pO1xyXG4gICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdCk7XHJcbiAgICAgICAgICB9KTtcclxuICAgICAgICB9LFxyXG4gICAgICAgIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksXHJcbiAgICAgICAgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgbGVmdERvbmUgPSB0cnVlO1xyXG4gICAgICAgICAgKHJpZ2h0RG9uZSB8fCBsZWZ0TWFwLmNvdW50KCkgPT09IDApICYmIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgfSlcclxuICAgICAgKTtcclxuXHJcbiAgICAgIGdyb3VwLmFkZChyaWdodC5zdWJzY3JpYmUoXHJcbiAgICAgICAgZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgICB2YXIgaWQgPSByaWdodElkKys7XHJcbiAgICAgICAgICB2YXIgbWQgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuXHJcbiAgICAgICAgICByaWdodE1hcC5hZGQoaWQsIHZhbHVlKTtcclxuICAgICAgICAgIGdyb3VwLmFkZChtZCk7XHJcblxyXG4gICAgICAgICAgdmFyIGV4cGlyZSA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgcmlnaHRNYXAucmVtb3ZlKGlkKSAmJiByaWdodE1hcC5jb3VudCgpID09PSAwICYmIHJpZ2h0RG9uZSAmJiBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICBncm91cC5yZW1vdmUobWQpO1xyXG4gICAgICAgICAgfTtcclxuXHJcbiAgICAgICAgICB2YXIgZHVyYXRpb247XHJcbiAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICBkdXJhdGlvbiA9IHJpZ2h0RHVyYXRpb25TZWxlY3Rvcih2YWx1ZSk7XHJcbiAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICBtZC5zZXREaXNwb3NhYmxlKGR1cmF0aW9uLnRha2UoMSkuc3Vic2NyaWJlKG5vb3AsIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGV4cGlyZSkpO1xyXG5cclxuICAgICAgICAgIGxlZnRNYXAuZ2V0VmFsdWVzKCkuZm9yRWFjaChmdW5jdGlvbiAodikge1xyXG4gICAgICAgICAgICB2YXIgcmVzdWx0O1xyXG4gICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgIHJlc3VsdCA9IHJlc3VsdFNlbGVjdG9yKHYsIHZhbHVlKTtcclxuICAgICAgICAgICAgfSBjYXRjaChleG4pIHtcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4bik7XHJcbiAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0KTtcclxuICAgICAgICAgIH0pO1xyXG4gICAgICAgIH0sXHJcbiAgICAgICAgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSxcclxuICAgICAgICBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICByaWdodERvbmUgPSB0cnVlO1xyXG4gICAgICAgICAgKGxlZnREb25lIHx8IHJpZ2h0TWFwLmNvdW50KCkgPT09IDApICYmIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgfSlcclxuICAgICAgKTtcclxuICAgICAgcmV0dXJuI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TtcclxuICAgICAgICAgICAgZ3JvdXAucmVtb3ZlKG1kKTtcclxuICAgICAgICAgIH07XHJcblxyXG4gICAgICAgICAgdmFyIGR1cmF0aW9uO1xyXG4gICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgZHVyYXRpb24gPSBsZWZ0RHVyYXRpb25TZWxlY3Rvcih2YWx1ZSk7XHJcbiAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgIGxlZnRNYXAuZ2V0VmFsdWVzKCkuZm9yRWFjaChoYW5kbGVFcnJvcihlKSk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICBtZC5zZXREaXNwb3NhYmxlKGR1cmF0aW9uLnRha2UoMSkuc3Vic2NyaWJlKFxyXG4gICAgICAgICAgICBub29wLFxyXG4gICAgICAgICAgICBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgICAgIGxlZnRNYXAuZ2V0VmFsdWVzKCkuZm9yRWFjaChoYW5kbGVFcnJvcihlKSk7XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgZXhwaXJlKVxyXG4gICAgICAgICAgKTtcclxuICAgICAgICB9LFxyXG4gICAgICAgIGZ1bmN0aW9uIChlKSB7XHJcbiAgICAgICAgICBsZWZ0TWFwLmdldFZhbHVlcygpLmZvckVhY2goaGFuZGxlRXJyb3IoZSkpO1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICB9LFxyXG4gICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkLmJpbmQob2JzZXJ2ZXIpKVxyXG4gICAgICApO1xyXG5cclxuICAgICAgZ3JvdXAuYWRkKHJpZ2h0LnN1YnNjcmliZShcclxuICAgICAgICBmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgIHZhciBpZCA9IHJpZ2h0SWQrKztcclxuICAgICAgICAgIHJpZ2h0TWFwLmFkZChpZCwgdmFsdWUpO1xyXG5cclxuICAgICAgICAgIHZhciBtZCA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgZ3JvdXAuYWRkKG1kKTtcclxuXHJcbiAgICAgICAgICB2YXIgZXhwaXJlID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICByaWdodE1hcC5yZW1vdmUoaWQpO1xyXG4gICAgICAgICAgICBncm91cC5yZW1vdmUobWQpO1xyXG4gICAgICAgICAgfTtcclxuXHJcbiAgICAgICAgICB2YXIgZHVyYXRpb247XHJcbiAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICBkdXJhdGlvbiA9IHJpZ2h0RHVyYXRpb25TZWxlY3Rvcih2YWx1ZSk7XHJcbiAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgIGxlZnRNYXAuZ2V0VmFsdWVzKCkuZm9yRWFjaChoYW5kbGVFcnJvcihlKSk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgIH1cclxuICAgICAgICAgIG1kLnNldERpc3Bvc2FibGUoZHVyYXRpb24udGFrZSgxKS5zdWJzY3JpYmUoXHJcbiAgICAgICAgICAgIG5vb3AsXHJcbiAgICAgICAgICAgIGZ1bmN0aW9uIChlKSB7XHJcbiAgICAgICAgICAgICAgbGVmdE1hcC5nZXRWYWx1ZXMoKS5mb3JFYWNoKGhhbmRsZUVycm9yKGUpKTtcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICBleHBpcmUpXHJcbiAgICAgICAgICApO1xyXG5cclxuICAgICAgICAgIGxlZnRNYXAu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pcmVkID0gZmFsc2U7XHJcblxyXG4gICAgICB2YXIgZW5zdXJlQWN0aXZlID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIHZhciBpc093bmVyID0gZmFsc2U7XHJcbiAgICAgICAgaWYgKHEubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgICBpc093bmVyID0gIWlzQWNxdWlyZWQ7XHJcbiAgICAgICAgICAgIGlzQWNxdWlyZWQgPSB0cnVlO1xyXG4gICAgICAgIH1cclxuICAgICAgICBpZiAoaXNPd25lcikge1xyXG4gICAgICAgICAgbS5zZXREaXNwb3NhYmxlKHNjaGVkdWxlci5zY2hlZHVsZVJlY3Vyc2l2ZShmdW5jdGlvbiAoc2VsZikge1xyXG4gICAgICAgICAgICB2YXIgd29yaztcclxuICAgICAgICAgICAgaWYgKHEubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgICAgIHdvcmsgPSBxLnNoaWZ0KCk7XHJcbiAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgaXNBY3F1aXJlZCA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB2YXIgbTEgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgZC5hZGQobTEpO1xyXG4gICAgICAgICAgICBtMS5zZXREaXNwb3NhYmxlKHdvcmsuc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHgpO1xyXG4gICAgICAgICAgICAgIHZhciByZXN1bHQgPSBudWxsO1xyXG4gICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICByZXN1bHQgPSBzZWxlY3Rvcih4KTtcclxuICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICBxLnB1c2gocmVzdWx0KTtcclxuICAgICAgICAgICAgICBhY3RpdmVDb3VudCsrO1xyXG4gICAgICAgICAgICAgIGVuc3VyZUFjdGl2ZSgpO1xyXG4gICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgZC5yZW1vdmUobTEpO1xyXG4gICAgICAgICAgICAgIGFjdGl2ZUNvdW50LS07XHJcbiAgICAgICAgICAgICAgaWYgKGFjdGl2ZUNvdW50ID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICBzZWxmKCk7XHJcbiAgICAgICAgICB9KSk7XHJcbiAgICAgICAgfVxyXG4gICAgICB9O1xyXG5cclxuICAgICAgcS5wdXNoKHNvdXJjZSk7XHJcbiAgICAgIGFjdGl2ZUNvdW50Kys7XHJcbiAgICAgIGVuc3VyZUFjdGl2ZSgpO1xyXG4gICAgICByZXR1cm4gZDtcclxuICAgIH0pO1xyXG4gIH07XHJcblxyXG4gICAvKipcclxuICAgKiAgUnVucyBhbGwgb2JzZXJ2YWJsZSBzZXF1ZW5jZXMgaW4gcGFyYWxsZWwgYW5kIGNvbGxlY3QgdGhlaXIgbGFzdCBlbGVtZW50cy5cclxuICAgKlxyXG4gICAqIEBleGFtcGxlXHJcbiAgICogIDEgLSByZXMgPSBSeC5PYnNlcnZhYmxlLmZvcmtKb2luKFtvYnMxLCBvYnMyXSk7XHJcbiAgICogIDEgLSByZXMgPSBSeC5PYnNlcnZhYmxlLmZvcmtKb2luKG9iczEsIG9iczIsIC4uLik7XHJcbiAgICogQHJldHVybnMge09ic2VydmFibGV9IEFuIG9ic2VydmFibGUgc2VxdWVuY2Ugd2l0aCBh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AgICAgICAgZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgICAgICAgaWYgKCFmaW5pc2hlZCkge1xyXG4gICAgICAgICAgICAgICAgaGFzUmVzdWx0c1tpXSA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICByZXN1bHRzW2ldID0gdmFsdWU7XHJcbiAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgICAgIGZpbmlzaGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICBzdWJzY3JpYmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgZ3JvdXAuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgaWYgKCFmaW5pc2hlZCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKCFoYXNSZXN1bHRzW2ldKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgc3Vic2NyaWJlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGhhc0NvbXBsZXRlZFtpXSA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICBmb3IgKHZhciBpeCA9IDA7IGl4IDwgY291bnQ7IGl4KyspIHtcclxuICAgICAgICAgICAgICAgICAgaWYgKCFoYXNDb21wbGV0ZWRbaXhdKSB7IHJldHVybjsgfVxyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgZmluaXNoZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgc3Vic2NyaWJlci5vbk5leHQocmVzdWx0cyk7XHJcbiAgICAgICAgICAgICAgICBzdWJzY3JpYmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgfVxyXG4gICAgICAgIC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0LCBsYXN0UmlnaHQsXHJcbiAgICAgICAgbGVmdFN1YnNjcmlwdGlvbiA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpLCByaWdodFN1YnNjcmlwdGlvbiA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG5cclxuICAgICAgaXNQcm9taXNlKHNlY29uZCkgJiYgKHNlY29uZCA9IG9ic2VydmFibGVGcm9tUHJvbWlzZShzZWNvbmQpKTtcclxuXHJcbiAgICAgIGxlZnRTdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZShcclxuICAgICAgICAgIGZpcnN0LnN1YnNjcmliZShmdW5jdGlvbiAobGVmdCkge1xyXG4gICAgICAgICAgICBoYXNMZWZ0ID0gdHJ1ZTtcclxuICAgICAgICAgICAgbGFzdExlZnQgPSBsZWZ0O1xyXG4gICAgICAgICAgfSwgZnVuY3Rpb24gKGVycikge1xyXG4gICAgICAgICAgICByaWdodFN1YnNjcmlwdGlvbi5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXJyKTtcclxuICAgICAgICAgIH0sIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgbGVmdFN0b3BwZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICBpZiAocmlnaHRTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgaWYgKCFoYXNMZWZ0KSB7XHJcbiAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgfSBlbHNlIGlmICghaGFzUmlnaHQpIHtcclxuICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgdmFyIHJlc3VsdDtcclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgIHJlc3VsdCA9IHJlc3VsdFNlbGVjdG9yKGxhc3RMZWZ0LCBsYXN0UmlnaHQpO1xyXG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0KTtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICB9KVxyXG4gICAgICApO1xyXG5cclxuICAgICAgcmlnaHRTdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZShcclxuICAgICAgICBzZWNvbmQuc3Vic2NyaWJlKGZ1bmN0aW9uIChyaWdodCkge1xyXG4gICAgICAgICAgaGFzUmlnaHQgPSB0cnVlO1xyXG4gICAgICAgICAgbGFzdFJpZ2h0ID0gcmlnaHQ7XHJcbiAgICAgICAgfSwgZnVuY3Rpb24gKGVycikge1xyXG4gICAgICAgICAgbGVmdFN1YnNjcmlwdGlvbi5kaXNwb3NlKCk7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGVycik7XHJcbiAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgcmlnaHRTdG9wcGVkID0gdHJ1ZTtcclxuICAgICAgICAgIGlmIChsZWZ0U3RvcHBlZCkge1xyXG4gICAgICAgICAgICBpZiAoIWhhc0xlZnQpIHtcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9IGVsc2UgaWYgKCFoYXNSaWdodCkge1xyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgIC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AqL1xyXG4gIG9ic2VydmFibGVQcm90by5tYW55U2VsZWN0ID0gZnVuY3Rpb24gKHNlbGVjdG9yLCBzY2hlZHVsZXIpIHtcclxuICAgIGlzU2NoZWR1bGVyKHNjaGVkdWxlcikgfHwgKHNjaGVkdWxlciA9IGltbWVkaWF0ZVNjaGVkdWxlcik7XHJcbiAgICB2YXIgc291cmNlID0gdGhpcztcclxuICAgIHJldHVybiBvYnNlcnZhYmxlRGVmZXIoZnVuY3Rpb24gKCkge1xyXG4gICAgICB2YXIgY2hhaW47XHJcblxyXG4gICAgICByZXR1cm4gc291cmNlXHJcbiAgICAgICAgLm1hcChmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgdmFyIGN1cnIgPSBuZXcgQ2hhaW5PYnNlcnZhYmxlKHgpO1xyXG5cclxuICAgICAgICAgIGNoYWluICYmIGNoYWluLm9uTmV4dCh4KTtcclxuICAgICAgICAgIGNoYWluID0gY3VycjtcclxuXHJcbiAgICAgICAgICByZXR1cm4gY3VycjtcclxuICAgICAgICB9KVxyXG4gICAgICAgIC50YXAoXHJcbiAgICAgICAgICBub29wLFxyXG4gICAgICAgICAgZnVuY3Rpb24gKGUpIHsgY2hhaW4gJiYgY2hhaW4ub25FcnJvcihlKTsgfSxcclxuICAgICAgICAgIGZ1bmN0aW9uICgpIHsgY2hhaW4gJiYgY2hhaW4ub25Db21wbGV0ZWQoKTsgfVxyXG4gICAgICAgIClcclxuICAgICAgICAub2JzZXJ2ZU9uKHNjaGVkdWxlcilcclxuICAgICAgICAubWFwKHNlbGVjdG9yKTtcclxuICAgIH0pO1xyXG4gIH07XHJcblxyXG4gIHZhciBDaGFpbk9ic2VydmFibGUgPSAoZnVuY3Rpb24gKF9fc3VwZXJfXykge1xyXG5cclxuICAgIGZ1bmN0aW9uIHN1YnNjcmliZSAob2JzZXJ2ZXIpIHtcclxuICAgICAgdmFyIHNlbGYgPSB0aGlzLCBnID0gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUoKT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ge1xyXG4gICAgICAgICAgcSA9IFtdO1xyXG4gICAgICAgICAgcS5wdXNoKG5vdGlmaWNhdGlvbik7XHJcbiAgICAgICAgICBleGNlcHRpb24gPSBub3RpZmljYXRpb24udmFsdWUuZXhjZXB0aW9uO1xyXG4gICAgICAgICAgc2hvdWxkUnVuID0gIXJ1bm5pbmc7XHJcbiAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgIHEucHVzaCh7IHZhbHVlOiBub3RpZmljYXRpb24udmFsdWUsIHRpbWVzdGFtcDogbm90aWZpY2F0aW9uLnRpbWVzdGFtcCArIGR1ZVRpbWUgfSk7XHJcbiAgICAgICAgICBzaG91bGRSdW4gPSAhYWN0aXZlO1xyXG4gICAgICAgICAgYWN0aXZlID0gdHJ1ZTtcclxuICAgICAgICB9XHJcbiAgICAgICAgaWYgKHNob3VsZFJ1bikge1xyXG4gICAgICAgICAgaWYgKGV4Y2VwdGlvbiAhPT0gbnVsbCkge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICBkID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgICAgIGNhbmNlbGFibGUuc2V0RGlzcG9zYWJsZShkKTtcclxuICAgICAgICAgICAgZC5zZXREaXNwb3NhYmxlKHNjaGVkdWxlci5zY2hlZHVsZVJlY3Vyc2l2ZVdpdGhSZWxhdGl2ZShkdWVUaW1lLCBmdW5jdGlvbiAoc2VsZikge1xyXG4gICAgICAgICAgICAgIHZhciBlLCByZWN1cnNlRHVlVGltZSwgcmVzdWx0LCBzaG91bGRSZWN1cnNlO1xyXG4gICAgICAgICAgICAgIGlmIChleGNlcHRpb24gIT09IG51bGwpIHtcclxuICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgcnVubmluZyA9IHRydWU7XHJcbiAgICAgICAgICAgICAgZG8ge1xyXG4gICAgICAgICAgICAgICAgcmVzdWx0ID0gbnVsbDtcclxuICAgICAgICAgICAgICAgIGlmIChxLmxlbmd0aCA+IDAgJiYgcVswXS50aW1lc3RhbXAgLSBzY2hlZHVsZXIubm93KCkgPD0gMCkge1xyXG4gICAgICAgICAgICAgICAgICByZXN1bHQgPSBxLnNoaWZ0KCkudmFsdWU7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBpZiAocmVzdWx0ICE9PSBudWxsKSB7XHJcbiAgICAgICAgICAgICAgICAgIHJlc3VsdC5hY2NlcHQob2JzZXJ2ZXIpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgIH0gd2hpbGUgKHJlc3VsdCAhPT0gbnVsbCk7XHJcbiAgICAgICAgICAgICAgc2hvdWxkUmVjdXJzZSA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgIHJlY3Vyc2VEdWVUaW1lID0gMDtcclxuICAgICAgICAgICAgICBpZiAocS5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICAgICAgICBzaG91bGRSZWN1cnNlID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIHJlY3Vyc2VEdWVUaW1lID0gTWF0aC5tYXgoMCwgcVswXS50aW1lc3RhbXAgLSBzY2hlZHVsZXIubm93KCkpO1xyXG4gICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICBhY3RpdmUgPSBmYWxzZTtcclxuICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgZSA9IGV4Y2VwdGlvbjtcclxuICAgICAgICAgICAgICBydW5uaW5nID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgaWYgKGUgIT09IG51bGwpIHtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgfSBlbHNlIGlmIChzaG91bGRSZWN1cnNlKSB7XHJcbiA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lvbiA9IHNvdXJjZS5zdWJzY3JpYmUoXHJcbiAgICAgICAgZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgIGhhc3ZhbHVlID0gdHJ1ZTtcclxuICAgICAgICAgIHZhbHVlID0geDtcclxuICAgICAgICAgIGlkKys7XHJcbiAgICAgICAgICB2YXIgY3VycmVudElkID0gaWQsXHJcbiAgICAgICAgICAgIGQgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgIGNhbmNlbGFibGUuc2V0RGlzcG9zYWJsZShkKTtcclxuICAgICAgICAgIGQuc2V0RGlzcG9zYWJsZShzY2hlZHVsZXIuc2NoZWR1bGVXaXRoUmVsYXRpdmUoZHVlVGltZSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICBoYXN2YWx1ZSAmJiBpZCA9PT0gY3VycmVudElkICYmIG9ic2VydmVyLm9uTmV4dCh2YWx1ZSk7XHJcbiAgICAgICAgICAgIGhhc3ZhbHVlID0gZmFsc2U7XHJcbiAgICAgICAgICB9KSk7XHJcbiAgICAgICAgfSxcclxuICAgICAgICBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgY2FuY2VsYWJsZS5kaXNwb3NlKCk7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgaGFzdmFsdWUgPSBmYWxzZTtcclxuICAgICAgICAgIGlkKys7XHJcbiAgICAgICAgfSxcclxuICAgICAgICBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICBjYW5jZWxhYmxlLmRpc3Bvc2UoKTtcclxuICAgICAgICAgIGhhc3ZhbHVlICYmIG9ic2VydmVyLm9uTmV4dCh2YWx1ZSk7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgaGFzdmFsdWUgPSBmYWxzZTtcclxuICAgICAgICAgIGlkKys7XHJcbiAgICAgICAgfSk7XHJcbiAgIC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3IENvbXBvc2l0ZURpc3Bvc2FibGUodGltZXJEKSxcclxuICAgICAgICByZWZDb3VudERpc3Bvc2FibGUgPSBuZXcgUmVmQ291bnREaXNwb3NhYmxlKGdyb3VwRGlzcG9zYWJsZSk7XHJcblxyXG4gICAgICAgZnVuY3Rpb24gY3JlYXRlVGltZXIgKCkge1xyXG4gICAgICAgIHZhciBtID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCksXHJcbiAgICAgICAgICBpc1NwYW4gPSBmYWxzZSxcclxuICAgICAgICAgIGlzU2hpZnQgPSBmYWxzZTtcclxuICAgICAgICB0aW1lckQuc2V0RGlzcG9zYWJsZShtKTtcclxuICAgICAgICBpZiAobmV4dFNwYW4gPT09IG5leHRTaGlmdCkge1xyXG4gICAgICAgICAgaXNTcGFuID0gdHJ1ZTtcclxuICAgICAgICAgIGlzU2hpZnQgPSB0cnVlO1xyXG4gICAgICAgIH0gZWxzZSBpZiAobmV4dFNwYW4gPCBuZXh0U2hpZnQpIHtcclxuICAgICAgICAgICAgaXNTcGFuID0gdHJ1ZTtcclxuICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgaXNTaGlmdCA9IHRydWU7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHZhciBuZXdUb3RhbFRpbWUgPSBpc1NwYW4gPyBuZXh0U3BhbiA6IG5leHRTaGlmdCxcclxuICAgICAgICAgIHRzID0gbmV3VG90YWxUaW1lIC0gdG90YWxUaW1lO1xyXG4gICAgICAgIHRvdGFsVGltZSA9IG5ld1RvdGFsVGltZTtcclxuICAgICAgICBpZiAoaXNTcGFuKSB7XHJcbiAgICAgICAgICBuZXh0U3BhbiArPSB0aW1lU2hpZnQ7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGlmIChpc1NoaWZ0KSB7XHJcbiAgICAgICAgICBuZXh0U2hpZnQgKz0gdGltZVNoaWZ0O1xyXG4gICAgICAgIH1cclxuICAgICAgICBtLnNldERpc3Bvc2FibGU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ci5vbk5leHQoYWRkUmVmKHMsIHJlZkNvdW50RGlzcG9zYWJsZSkpO1xyXG4gICAgICBjcmVhdGVUaW1lcigwKTtcclxuXHJcbiAgICAgIGdyb3VwRGlzcG9zYWJsZS5hZGQoc291cmNlLnN1YnNjcmliZShcclxuICAgICAgICBmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgdmFyIG5ld0lkID0gMCwgbmV3V2luZG93ID0gZmFsc2U7XHJcbiAgICAgICAgICBzLm9uTmV4dCh4KTtcclxuICAgICAgICAgIGlmICgrK24gPT09IGNvdW50KSB7XHJcbiAgICAgICAgICAgIG5ld1dpbmRvdyA9IHRydWU7XHJcbiAgICAgICAgICAgIG4gPSAwO1xyXG4gICAgICAgICAgICBuZXdJZCA9ICsrd2luZG93SWQ7XHJcbiAgICAgICAgICAgIHMub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgcyA9IG5ldyBTdWJqZWN0KCk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChhZGRSZWYocywgcmVmQ291bnREaXNwb3NhYmxlKSk7XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgICBuZXdXaW5kb3cgJiYgY3JlYXRlVGltZXIobmV3SWQpO1xyXG4gICAgICAgIH0sIFxyXG4gICAgICAgIGZ1bmN0aW9uIChlKSB7XHJcbiAgICAgICAgICBzLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgIH0sIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgIHMub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgfVxyXG4gICAgICApKTtcclxuICAgICAgcmV0dXJuIHJlZkNvdW50RGlzcG9zYWJsZTtcclxuICAgIH0pO1xyXG4gIH07XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiAgUHJvamVjdHMgZWFjaCBlbGVtZW50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0gc3Vic2NyaXB0aW9uRGVsYXk7XHJcbiAgICAgICAgICAgIHNlbGVjdG9yID0gZGVsYXlEdXJhdGlvblNlbGVjdG9yO1xyXG4gICAgICAgIH1cclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBkZWxheXMgPSBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZSgpLCBhdEVuZCA9IGZhbHNlLCBkb25lID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKGF0RW5kICYmIGRlbGF5cy5sZW5ndGggPT09IDApIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LCBzdWJzY3JpcHRpb24gPSBuZXcgU2VyaWFsRGlzcG9zYWJsZSgpLCBzdGFydCA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHN1YnNjcmlwdGlvbi5zZXREaXNwb3NhYmxlKHNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgZGVsYXk7XHJcbiAgICAgICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZGVsYXkgPSBzZWxlY3Rvcih4KTtcclxuICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlcnJvcikge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGVycm9yKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICB2YXIgZCA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIGRlbGF5cy5hZGQoZCk7XHJcbiAgICAgICAgICAgICAgICAgICAgZC5zZXREaXNwb3NhYmxlKGRlbGF5LnN1YnNjcmliZShmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh4KTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZGVsYXlzLnJlbW92ZShkKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZG9uZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkZWxheXMucmVtb3ZlKGQpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkb25lKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGF0RW5kID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICBzdWJzY3JpcHRpb24uZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIGRvbmUoKTtcclxuICAgICAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgfTtcclxuXHJcbiAgICAgICAgICAgIGlmICghc3ViRGVsYXkpIHtcclxuICAgICAgICAgICAgICAgIHN0YXJ0KCk7XHJcbiAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICBzdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZShzdWJEZWxheS5zdWJzY3JpYmUoZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHN0YXJ0KCk7XHJcbiAgICAgICAgICAgICAgICB9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5jdGlvbiB0aW1lcldpbnMgKCkge1xyXG4gICAgICAgICAgICByZXR1cm4gaWQgPT09IG15SWQ7XHJcbiAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgdmFyIGQgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgIHRpbWVyLnNldERpc3Bvc2FibGUoZCk7XHJcbiAgICAgICAgICBkLnNldERpc3Bvc2FibGUodGltZW91dC5zdWJzY3JpYmUoZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICB0aW1lcldpbnMoKSAmJiBzdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZShvdGhlci5zdWJzY3JpYmUob2JzZXJ2ZXIpKTtcclxuICAgICAgICAgICAgZC5kaXNwb3NlKCk7XHJcbiAgICAgICAgICB9LCBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgICB0aW1lcldpbnMoKSAmJiBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICB0aW1lcldpbnMoKSAmJiBzdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZShvdGhlci5zdWJzY3JpYmUob2JzZXJ2ZXIpKTtcclxuICAgICAgICAgIH0pKTtcclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICBzZXRUaW1lcihmaXJzdFRpbWVvdXQpO1xyXG5cclxuICAgICAgICBmdW5jdGlvbiBvYnNlcnZlcldpbnMoKSB7XHJcbiAgICAgICAgICB2YXIgcmVzID0gIXN3aXRjaGVkO1xyXG4gICAgICAgICAgaWYgKHJlcykgeyBpZCsrOyB9XHJcbiAgICAgICAgICByZXR1cm4gcmVzO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgb3JpZ2luYWwuc2V0RGlzcG9zYWJsZShzb3VyY2Uuc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICBpZiAob2JzZXJ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cHRpb24uc2V0RGlzcG9zYWJsZShpbm5lclNvdXJjZS5zdWJzY3JpYmUoXHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0LmJpbmQob2JzZXJ2ZXIpLFxyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksXHJcbiAgICAgICAgICAgICAgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgZy5yZW1vdmUoaW5uZXJTdWJzY3JpcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgaGFzQ3VycmVudCA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgaWYgKGlzU3RvcHBlZCAmJiBnLmxlbmd0aCA9PT0gMSkge1xyXG4gICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgfSxcclxuICAgICAgICBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLFxyXG4gICAgICAgIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgIGlzU3RvcHBlZCA9IHRydWU7XHJcbiAgICAgICAgICBpZiAoIWhhc0N1cnJlbnQgJiYgZy5sZW5ndGggPT09IDEpIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgIH1cclxuICAgICAgICB9KSk7XHJcblxyXG4gICAgICByZXR1cm4gZztcclxuICAgIH0pO1xyXG4gIH07XHJcblxyXG4gIC8qXHJcbiAgICogUGVyZm9ybXMgYSBleGNsdXNpdmUgbWFwIHdhaXRpbmcgZm9yIHRoZSBmaXJzdCB0byBmaW5pc2ggYmVmb3JlIHN1YnNjcmliaW5nIHRvIGFub3RoZXIgb2JzZXJ2YWJsZS5cclxuICAgKiBPYnNlcnZhYmxlcyB0aGF0IGNvbWUgaW4gYmV0d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cbiAgICAgICAgICAgIGhhc0N1cnJlbnQgPSB0cnVlO1xyXG5cclxuICAgICAgICAgICAgaW5uZXJTdWJzY3JpcHRpb24gPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgZy5hZGQoaW5uZXJTdWJzY3JpcHRpb24pO1xyXG5cclxuICAgICAgICAgICAgaXNQcm9taXNlKGlubmVyU291cmNlKSAmJiAoaW5uZXJTb3VyY2UgPSBvYnNlcnZhYmxlRnJvbVByb21pc2UoaW5uZXJTb3VyY2UpKTtcclxuXHJcbiAgICAgICAgICAgIGlubmVyU3Vic2NyaXB0aW9uLnNldERpc3Bvc2FibGUoaW5uZXJTb3VyY2Uuc3Vic2NyaWJlKFxyXG4gICAgICAgICAgICAgIGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgcmVzdWx0O1xyXG4gICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgcmVzdWx0ID0gc2VsZWN0b3IuY2FsbCh0aGlzQXJnLCB4LCBpbmRleCsrLCBpbm5lclNvdXJjZSk7XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0KTtcclxuICAgICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksXHJcbiAgICAgICAgICAgICAgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgZy5yZW1vdmUoaW5uZXJTdWJzY3JpcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgaGFzQ3VycmVudCA9IGZhbHNlO1xyXG5cclxuICAgICAgICAgICA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WVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIHZhciBBdXRvRGV0YWNoT2JzZXJ2ZXJQcm90b3R5cGUgPSBBdXRvRGV0YWNoT2JzZXJ2ZXIucHJvdG90eXBlO1xyXG5cclxuICAgICAgICBBdXRvRGV0YWNoT2JzZXJ2ZXJQcm90b3R5cGUubmV4dCA9IGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgICB2YXIgbm9FcnJvciA9IGZhbHNlO1xyXG4gICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5vYnNlcnZlci5vbk5leHQodmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgbm9FcnJvciA9IHRydWU7XHJcbiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgIHRocm93IGU7XHJcbiAgICAgICAgICAgIH0gZmluYWxseSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoIW5vRXJyb3IpIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIEF1dG9EZXRhY2hPYnNlcnZlclByb3RvdHlwZS5lcnJvciA9IGZ1bmN0aW9uIChleG4pIHtcclxuICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXIub25FcnJvcihleG4pO1xyXG4gICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICB0aHJvdyBlO1xyXG4gICAgICAgICAgICB9IGZpbmFsbHkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICBBdXRvRGV0YWNoT2JzZXJ2ZXJQcm90b3R5cGUuY29tcGxldGVk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vYmplY3QgdGhhdCBpcyBib3RoIGFuIG9ic2VydmFibGUgc2VxdWVuY2UgYXMgd2VsbCBhcyBhbiBvYnNlcnZlci5cclxuICAgICAqICBFYWNoIG5vdGlmaWNhdGlvbiBpcyBicm9hZGNhc3RlZCB0byBhbGwgc3Vic2NyaWJlZCBvYnNlcnZlcnMuXHJcbiAgICAgKi9cclxuICAgIHZhciBTdWJqZWN0ID0gUnguU3ViamVjdCA9IChmdW5jdGlvbiAoX3N1cGVyKSB7XHJcbiAgICAgICAgZnVuY3Rpb24gc3Vic2NyaWJlKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgaWYgKCF0aGlzLmlzU3RvcHBlZCkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5vYnNlcnZlcnMucHVzaChvYnNlcnZlcik7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gbmV3IElubmVyU3Vic2NyaXB0aW9uKHRoaXMsIG9ic2VydmVyKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICBpZiAodGhpcy5leGNlcHRpb24pIHtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IodGhpcy5leGNlcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuIGRpc3Bvc2FibGVFbXB0eTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICByZXR1cm4gZGlzcG9zYWJsZUVtcHR5O1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgaW5oZXJpdHMoU3ViamVjdCwgX3N1cGVyKTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQ3JlYXRlcyBhIHN1YmplY3QuXHJcbiAgICAgICAgICogQGNvbnN0cnVjdG9yXHJcbiAgICAgICAgICovXHJcbiAgICAgICAgZnVuY3Rpb24gU3ViamVjdCgpIHtcclxuICAgICAgICAgICAgX3N1cGVyLmNhbGwodGhpcywgc3Vic2NyaWJlKTtcclxuICAgICAgICAgICAgdGhpcy5pc0Rpc3Bvc2VkID0gZmFsc2UsXHJcbiAgICAgICAgICAgIHRoaXMuaXNTdG9wcGVkID0gZmFsc2UsXHJcbiAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzID0gW107XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBhZGRQcm9wZXJ0aWVzKFN1YmplY3QucHJvdG90eXBlLCBPYnNlcnZlciwge1xyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogSW5kaWNhdGVzIHdoZXRoZXIgdGhlIHN1YmplY3QgaGFzIG9ic2VydmVycyBzdWJzY3JpYmVkIHRvIGl0LlxyXG4gICAgICAgICAgICAgKiBAcmV0dXJucyB7Qm9vbGVhbn0gSW5kaWNhdGVzIHdoZXRoZXIgdGhlIHN1YmplY3QgaGFzIG9ic2VydmVycyBzdWJzY3JpYmVkIHRvIGl0LlxyXG4gICAgICAgICAgICAgKi9cclxuICAgICAgICAgICAgaGFzT2JzZXJ2ZXJzOiBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gdGhpcy5vYnNlcnZlcnMubGVuZ3RoID4gMDtcclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgLyoqXHJcbiAgICAgICAgICAgICAqIE5vdGlmaWVzIGFsbCBzdWJzY3JpYmVkIG9ic2VydmVycyBhYm91dCB0aGUgZW5kIG9mIHRoZSBzZXF1ZW5jZS5cclxuICAgICAgICAgICAgICovXHJcbiAgICAgICAgICAgIG9uQ29tcGxldGVkOiBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIG9zID0gdGhpcy5vYnNlcnZlcnMuc2xpY2UoMCk7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5pc1N0b3BwZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSBvcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvc1tpXS5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5vYnNlcnZlcnMgPSBbXTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgLyoqXHJcbiAgICAgICAgICAgICAqIE5vdGlmaWVzIGFsbCBzdWJzY3JpYmVkIG9ic2VydmVycyBhYm91dCB0aGUgZXhjZXB0aW9uLlxyXG4gICAgICAgICAgICAgKiBAcGFyYW0ge01peGVkfSBlcnJvciBUaGUgZXhjZXB0aW9uIHRvIHNlbmQgdG8gYWxsIG9ic2VydmVycy5cclxuICAgICAgICAgICAgICovXHJcbiAgICAgICAgICAgIG9uRXJyb3I6IGZ1bmN0aW9uIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgb3MgPSB0aGlzLm9ic2VydmVycy5zbGljZSgwKTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmlzU3RvcHBlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5leGNlcHRpb24gPSBleGNlcHRpb247XHJcbiAgICAgICAgICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IG9zLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9zW2ldLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzID0gW107XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBOb3RpZmllcyBhbGwgc3Vic2NyaWJlZCBvYnNlcnZlcnMgYWJvdXQgdGhlIGFycml2YWwgb2YgdGhlIHNwZWNpZmllZCBlbGVtZW50IGluIHRoZSBzZXF1ZW5jZS5cclxuICAgICAgICAgICAgICogQHBhcmFtIHtNaXhlZH0gdmFsdWUgVGhlIHZhbHVlIHRvIHNlbmQgdG8gYWxsIG9ic2VydmVycy5cclxuICAgICAgICAgICAgICovXHJcbiAgICAgICAgICAgIG9uTmV4dDogZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIG9zID0gdGhpcy5vYnNlcnZlcnMuc2xpY2UoMCk7XHJcbiAgICAgICAgICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IG9zLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9zW2ldLm9uTmV4dCh2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogVW5zdWJzY3JpYmUgYWxsIG9ic2VydmVycyBhbmQgcmVsZWFzZSByZXNvdXJjZXMuXHJcbiAgICAgICAgICAgICAqL1xyXG4g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xcclxuICAgICAgLyoqXHJcbiAgICAgICAqIE5vdGlmaWVzIGFsbCBzdWJzY3JpYmVkIG9ic2VydmVycyBhYm91dCB0aGUgZW5kIG9mIHRoZSBzZXF1ZW5jZSwgYWxzbyBjYXVzaW5nIHRoZSBsYXN0IHJlY2VpdmVkIHZhbHVlIHRvIGJlIHNlbnQgb3V0IChpZiBhbnkpLlxyXG4gICAgICAgKi9cclxuICAgICAgb25Db21wbGV0ZWQ6IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICB2YXIgbywgaSwgbGVuO1xyXG4gICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICBpZiAoIXRoaXMuaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICB0aGlzLmlzU3RvcHBlZCA9IHRydWU7XHJcbiAgICAgICAgICB2YXIgb3MgPSB0aGlzLm9ic2VydmVycy5zbGljZSgwKSxcclxuICAgICAgICAgICAgdiA9IHRoaXMudmFsdWUsXHJcbiAgICAgICAgICAgIGh2ID0gdGhpcy5oYXNWYWx1ZTtcclxuXHJcbiAgICAgICAgICBpZiAoaHYpIHtcclxuICAgICAgICAgICAgZm9yIChpID0gMCwgbGVuID0gb3MubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICBvID0gb3NbaV07XHJcbiAgICAgICAgICAgICAgby5vbk5leHQodik7XHJcbiAgICAgICAgICAgICAgby5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICBmb3IgKGkgPSAwLCBsZW4gPSBvcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgIG9zW2ldLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICB0aGlzLm9ic2VydmVycyA9IFtdO1xyXG4gICAgICAgIH1cclxuIC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0aGlzLmRpc3Bvc2VzLnB1c2godGhpcy5zY2hlZHVsZXIuY2xvY2spO1xyXG4gICAgfTtcclxuXHJcbiAgICAvKiogQHByaXZhdGUgKi9cclxuICAgIHZhciBNb2NrT2JzZXJ2ZXIgPSAoZnVuY3Rpb24gKF9zdXBlcikge1xyXG4gICAgICAgIGluaGVyaXRzKE1vY2tPYnNlcnZlciwgX3N1cGVyKTtcclxuXHJcbiAgICAgICAgLypcclxuICAgICAgICAgKiBAY29uc3RydWN0b3JcclxuICAgICAgICAgKiBAcHJ2aWF0ZVxyXG4gICAgICAgICAqL1xyXG4gICAgICAgIGZ1bmN0aW9uIE1vY2tPYnNlcnZlcihzY2hlZHVsZXIpIHtcclxuICAgICAgICAgICAgX3N1cGVyLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgIHRoaXMuc2NoZWR1bGVyID0gc2NoZWR1bGVyO1xyXG4gICAgICAgICAgICB0aGlzLm1lc3NhZ2VzID0gW107XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICB2YXIgTW9ja09ic2VydmVyUHJvdG90eXBlID0gTW9ja09ic2VydmVyLnByb3RvdHlwZTtcclxuXHJcbiAgICAgICAgLypcclxuICAgICAgICAgKiBAbWVtYmVyT2YgTW9ja09ic2VydmVyUHJvdG90eXBlI1xyXG4gICAgICAgICAqIEBwcnZpYXRlXHJcbiAgICAgICAgICovXHJcbiAgICAgICAgTW9ja09ic2VydmVyUHJvdG90eXBlLm9uTmV4dCA9IGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgICB0aGlzLm1lc3NhZ2VzLnB1c2gobmV3IFJlY29yZGVkKHRoaXMuc2NoZWR1bGVyLmNsb2NrLCBOb3RpZmljYXRpb24uY3JlYXRlT25OZXh0KHZhbHVlKSkpO1xyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIC8qXHJcbiAgICAgICAgICogQG1lbWJlck9mIE1vY2tPYnNlcnZlclByb3RvdHlwZSNcclxuICAgICAgICA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O1xyXG4gICAgICAgICAgICB0aGlzLm9ic2VydmVycyA9IFtdO1xyXG4gICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gdGhpcy5tZXNzYWdlcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgbWVzc2FnZSA9IHRoaXMubWVzc2FnZXNbaV07XHJcbiAgICAgICAgICAgICAgICBub3RpZmljYXRpb24gPSBtZXNzYWdlLnZhbHVlO1xyXG4gICAgICAgICAgICAgICAgKGZ1bmN0aW9uIChpbm5lck5vdGlmaWNhdGlvbikge1xyXG4gICAgICAgICAgICAgICAgICAgIHNjaGVkdWxlci5zY2hlZHVsZUFic29sdXRlV2l0aFN0YXRlKG51bGwsIG1lc3NhZ2UudGltZSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB2YXIgb2JzID0gb2JzZXJ2YWJsZS5vYnNlcnZlcnMuc2xpY2UoMCk7XHJcblxyXG4gICAgICAgICAgICAgICAgICAgICAgICBmb3IgKHZhciBqID0gMCwgakxlbiA9IG9icy5sZW5ndGg7IGogPCBqTGVuOyBqKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlubmVyTm90aWZpY2F0aW9uLmFjY2VwdChvYnNbal0pO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBkaXNwb3NhYmxlRW1wdHk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgICAgICAgICB9KShub3RpZmljYXRpb24pO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICByZXR1cm4gSG90T2JzZXJ2YWJsZTtcclxuICAgIH0pKE9ic2VydmFibGUpO1xyXG5cclxuICAgIC8qKiBAcHJpdmF0ZSAqL1xyXG4gICAgdmFyIENvbGRPYnNlcnZhYmxlID0gKGZ1bmN0aW9uIChfc3VwZXIpIHtcclxuXHJcbiAgICAgICAgZnVuY3Rpb24gc3Vic2NyaWJlKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBtZXNzYWdlLCBub3RpZmljYXRpb24sIG9ic2VydmFibGUgPSB0aGlzO1xyXG4gICAgICAgICAgICB0aGlzLnN1YnNjcmlwdGlvbnMucHVzaChuZXcgU3Vic2NyaXB0aW9uKHRoaXMuc2NoZWR1bGVyLmNsb2NrKSk7XHJcbiAgICAgICAgICAgIHZhciBpbmRleCA9IHRoaXMuc3Vic2NyaXB0aW9ucy5sZW5ndGggLSAxO1xyXG4gICAgICAgICAgICB2YXIgZCA9IG5ldyBDb21wb3NpdGVEaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSB0aGlzLm1lc3NhZ2VzLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICBtZXNzYWdlID0gdGhpcy5tZXNzYWdlc1tpXTtcclxuICAgICAgICAgICAgICAgIG5vdGlmaWNhdGlvbiA9IG1lc3NhZ2UudmFsdWU7XHJcbiAgICAgICAgICAgICAgICAoZnVuY3Rpb24gKGlubmVyTm90aWZpY2F0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgZC5hZGQob2JzZXJ2YWJsZS5zY2hlZHVsZXIuc2NoZWR1bGVSZWxhdGl2ZVdpdGhTdGF0ZShudWxsLCBtZXNzYWdlLnRpbWUsIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaW5uZXJOb3RpZmljYXRpb24uYWNjZXB0KG9ic2VydmVyKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGRpc3Bvc2FibGVFbXB0eTtcclxuICAgICAgICAgICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICAgICAgICB9KShub3RpZmljYXRpb24pO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIHJ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pbiBwcmV2aW91c1ZhbHVlKSB7XG4gICAgICAgICAgICAgICAgICAgIG5vZGUucmVtb3ZlQXR0cmlidXRlKGF0dHJOYW1lKVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSBpZiAocHJvcE5hbWUgPT09IFwic3R5bGVcIikge1xuICAgICAgICAgICAgICAgIGZvciAodmFyIGkgaW4gcHJldmlvdXNWYWx1ZSkge1xuICAgICAgICAgICAgICAgICAgICBub2RlLnN0eWxlW2ldID0gXCJcIlxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIHByZXZpb3VzVmFsdWUgPT09IFwic3RyaW5nXCIpIHtcbiAgICAgICAgICAgICAgICBub2RlW3Byb3BOYW1lXSA9IFwiXCJcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgbm9kZVtwcm9wTmFtZV0gPSBudWxsXG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG59XG5cbmZ1bmN0aW9uIHBhdGNoT2JqZWN0KG5vZGUsIHByb3BzLCBwcmV2aW91cywgcHJvcE5hbWUsIHByb3BWYWx1ZSkge1xuICAgIHZhciBwcmV2aW91c1ZhbHVlID0gcHJldmlvdXMgPyBwcmV2aW91c1twcm9wTmFtZV0gOiB1bmRlZmluZWRcblxuICAgIC8vIFNldCBhdHRyaWJ1dGVzXG4gICAgaWYgKHByb3BOYW1lID09PSBcImF0dHJpYnV0ZXNcIikge1xuICAgICAgICBmb3IgKHZhciBhdHRyTmFtZSBpbiBwcm9wVmFsdWUpIHtcbiAgICAgICAgICAgIHZhciBhdHRyVmFsdWUgPSBwcm9wVmFsdWVbYXR0ck5hbWVdXG5cbiAgICAgICAgICAgIGlmIChhdHRyVmFsdWUgPT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgICAgICAgIG5vZGUucmVtb3ZlQXR0cmlidXRlKGF0dHJOYW1lKVxuICAgICAgICAgICAgfSBlb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ICsgKHZDaGlsZC5jb3VudCB8fCAwKVxuXG4gICAgICAgICAgICAgICAgLy8gc2tpcCByZWN1cnNpb24gZG93biB0aGUgdHJlZSBpZiB0aGVyZSBhcmUgbm8gbm9kZXMgZG93biBoZXJlXG4gICAgICAgICAgICAgICAgaWYgKGluZGV4SW5SYW5nZShpbmRpY2VzLCByb290SW5kZXgsIG5leHRJbmRleCkpIHtcbiAgICAgICAgICAgICAgICAgICAgcmVjdXJzZShjaGlsZE5vZGVzW2ldLCB2Q2hpbGQsIGluZGljZXMsIG5vZGVzLCByb290SW5kZXgpXG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgcm9vdEluZGV4ID0gbmV4dEluZGV4XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICByZXR1cm4gbm9kZXNcbn1cblxuLy8gQmluYXJ5IHNlYXJjaCBmb3IgYW4gaW5kZXggaW4gdGhlIGludGVydmFsIFtsZWZ0LCByaWdodF1cbmZ1bmN0aW9uIGluZGV4SW5SYW5nZShpbmRpY2VzLCBsZWZ0LCByaWdodCkge1xuICAgIGlmIChpbmRpY2VzLmxlbmd0aCA9PT0gMCkge1xuICAgICAgICByZXR1cm4gZmFsc2VcbiAgICB9XG5cbiAgICB2YXIgbWluSW5kZXggPSAwXG4gICAgdmFyIG1heEluZGV4ID0gaW5kaWNlcy5sZW5ndGggLSAxXG4gICAgdmFyIGN1cnJlbnRJbmRleFxuICAgIHZhciBjdXJyZW50SXRlbVxuXG4gICAgd2hpbGUgKG1pbkluZGV4IDw9IG1heEluZGV4KSB7XG4gICAgICAgIGN1cnJlbnRJbmRleCA9ICgobWF4SW5kZXggKyBtaW5JbmRleCkgLyAyKSA+PiAwXG4gICAgICAgIGN1cnJlbnRJdGVtID0gaW5kaWNlc1tjdXJyZW50SW5kZXhdXG5cbiAgICAgICAgaWYgKG1pbkluZGV4ID09PSBtYXhJbmRleCkge1xuICAgICAgICAgICAgcmV0dXJuIGN1c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fVxuXG4gICAgZm9yICh2YXIgaSA9IDA7IGkgPCBpbmRpY2VzLmxlbmd0aDsgaSsrKSB7XG4gICAgICAgIHZhciBub2RlSW5kZXggPSBpbmRpY2VzW2ldXG4gICAgICAgIHJvb3ROb2RlID0gYXBwbHlQYXRjaChyb290Tm9kZSxcbiAgICAgICAgICAgIGluZGV4W25vZGVJbmRleF0sXG4gICAgICAgICAgICBwYXRjaGVzW25vZGVJbmRleF0sXG4gICAgICAgICAgICByZW5kZXJPcHRpb25zKVxuICAgIH1cblxuICAgIHJldHVybiByb290Tm9kZVxufVxuXG5mdW5jdGlvbiBhcHBseVBhdGNoKHJvb3ROb2RlLCBkb21Ob2RlLCBwYXRjaExpc3QsIHJlbmRlck9wdGlvbnMpIHtcbiAgICBpZiAoIWRvbU5vZGUpIHtcbiAgICAgICAgcmV0dXJuIHJvb3ROb2RlXG4gICAgfVxuXG4gICAgdmFyIG5ld05vZGVcblxuICAgIGlmIChpc0FycmF5KHBhdGNoTGlzdCkpIHtcbiAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCBwYXRjaExpc3QubGVuZ3RoOyBpKyspIHtcbiAgICAgICAgICAgIG5ld05vZGUgPSBwYXRjaE9wKHBhdGNoTGlzdFtpXSwgZG9tTm9kZSwgcmVuZGVyT3B0aW9ucylcblxuICAgICAgICAgICAgaWYgKGRvbU5vZGUgPT09IHJvb3ROb2RlKSB7XG4gICAgICAgICAgICAgICAgcm9vdE5vZGUgPSBuZXdOb2RlXG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9IGVsc2Uge1xuICAgICAgICBuZXdOb2RlID0gcGF0Y2hPcChwYXRjaExpc3QsIGRvbU5vZGUsIHJlbmRlck9wdGlvbnMpXG5cbiAgICAgICAgaWYgKGRvbU5vZGUgPT09IHJvb3ROb2RlKSB7XG4gICAgICAgICAgICByb290Tm9kZSA9IG5ld05vZGVcbiAgICAgICAgfVxuICAgIH1cblxuICAgIHJldHVybiByb290Tm9kZVxuf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gICAgICAgICAgICBhLmtleSA9PT0gYi5rZXkpIHtcbiAgICAgICAgICAgICAgICB2YXIgcHJvcHNQYXRjaCA9IGRpZmZQcm9wcyhhLnByb3BlcnRpZXMsIGIucHJvcGVydGllcywgYi5ob29rcylcbiAgICAgICAgICAgICAgICBpZiAocHJvcHNQYXRjaCkge1xuICAgICAgICAgICAgICAgICAgICBhcHBseSA9IGFwcGVuZFBhdGNoKGFwcGx5LFxuICAgICAgICAgICAgICAgICAgICAgICAgbmV3IFZQYXRjaChWUGF0Y2guUFJPUFMsIGEsIHByb3BzUGF0Y2gpKVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgYXBwbHkgPSBhcHBlbmRQYXRjaChhcHBseSwgbmV3IFZQYXRjaChWUGF0Y2guVk5PREUsIGEsIGIpKVxuICAgICAgICAgICAgICAgIGRlc3Ryb3lXaWRnZXRzKGEsIHBhdGNoLCBpbmRleClcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgYXBwbHkgPSBkaWZmQ2hpbGRyZW4oYSwgYiwgcGF0Y2gsIGFwcGx5LCBpbmRleClcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGFwcGx5ID0gYXBwZW5kUGF0Y2goYXBwbHksIG5ldyBWUGF0Y2goVlBhdGNoLlZOT0RFLCBhLCBiKSlcbiAgICAgICAgICAgIGRlc3Ryb3lXaWRnZXRzKGEsIHBhdGNoLCBpbmRleClcbiAgICAgICAgfVxuICAgIH0gZWxzZSBpZiAoaXNWVGV4dChiKSkge1xuICAgICAgICBpZiAoIWlzVlRleHQoYSkpIHtcbiAgICAgICAgICAgIGFwcGx5ID0gYXBwZW5kUGF0Y2goYXBwbHksIG5ldyBWUGF0Y2goVlBhdGNoLlZURVhULCBhLCBiKSlcbiAgICAgICAgICAgIGRlc3Ryb3lXaWRnZXRzKGEsIHBhdGNoLCBpbmRleClcbiAgICAgICAgfSBlbHNlIGlmIChhLnRleHQgIT09IGIudGV4dCkge1xuICAgICAgICAgICAgYXBwbHkgPSBhcHBlbmRQYXRjaChhcHBseSwgbmV3IFZQYXRjaChWUGF0Y2guVlRFWFQsIGEsIGIpKVxuICAgICAgICB9XG4gICAgfSBlbHNlIGlmIChpc1dpZGdldChiKSkge1xuICAgICAgICBhcHBseSA9IGFwcGVuZFBhdGNoKGFwcGx5LCBuZXcgVlBhdGNoKFZQYXRjaC5XSURHRVQsIGEsIGIpKVxuXG4gICAgICAgIGlmICghaXNXaWRnZXQoYSkpIHtcbiAgICAgICAgICAgIGRlc3Ryb3lXaWRnZXRzKGEsIHBhdGNoLCBpbmRleClcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGlmIChhcHBseSkge1xuICAgICAgICBwYXRjaFtpbmRleF0gPSBhcHBseVxuICAgIH1cbn1cblxuZnVuY3Rpb24gZGlmZlByb3BzKGEsIGIsIGhvb2tzKSB7XG4gICAgdmFyIGRpZmZcblxuICAgIGZvciAodmFyIGFLZXkgaW4gYSkge1xuICAgICAgICBpZiAoIShhS2V5IGluIGIpKSB7XG4gICAgICAgICAgICBkaWZmID0gZGlmZiB8fCB7fVxuICAgICAgICAgICAgZGlmZlthS2V5XSA9IHVuZGVmaW5lZFxuICAgICAgICB9XG5cbiAgICAgICAgdmFyIGFWYWx1ZSA9IGFbYUtleV1cbiAgICAgICAgdmFyIGJWYWx1ZSA9IGJbYUtleV1cblxuICAgICAgICBpZiAoaG9va3MgJiYgYUtleSBpbiBob29rcykge1xuICAgICAgICAgICAgZGlmZiA9IGRpZmYgfHwge31cbiAgICAgICAgICAgIGRpZmZbYUtleV0gPSBiVmFsdWVcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGlmIChpc09iamVjdChhVmFsdWUpICYmIGlzT2JqZWN0KGJWYWx1ZSkpIHtcbiAgICAgICAgICAgICAgICBpZiAoZ2V0UHJvdG90eXBlKGJWYWx1ZSkgIT09IGdldFByb3RvdHlwZShhVmFsdWUpKSB7XG4gICAgICAgICAgICAgICAgICAgIGRpZmYgPSBkaWZmIHx8IHt9XG4gICAgICAgICAgICAgICAgICAgIGRpZmZbYUtleV0gPSBiVmFsdWVcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICB2YXIgb2JqZWN0RGlmZiA9IGRpZmZQcm9wcyhhVmFsdWUsIGJWYWx1ZSlcbiAgICAgICAgICAgICAgICAgICAgaWYgKG9iamVjdERpZmYpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGRpZmYgPSBkaWZmIHx8IHt9XG4gICAgICAgICAgICAgICAgICAgICAgICBkaWZmW2FLZXldID0gb2JqZWN0RGlmZlxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIGlmIChhVmFsdWUgIT09IGJWYWx1ZSkge1xuICAgICAgICAgICAgICAgIGRpZmYgPSBkaWZmIHx8IHt9XG4gICAgICAgICAgICAgICAgZGlmZlthS2V5XSA9IGJWYWx1ZVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgZm9yICh2YXIgYktleSBpbiBiKSB7XG4gICAgICAgIGlmICghKGJLZXkgaW4gYSkpIHtcbiAgICAgICAgICAgIGRpZmYgPSBkaWZmIHx8IHt9XG4gICAgICAgICAgICBkaWZmW2JLZXldID0gYltiS2V5XVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgcmV0dXJuIGRpZmZcbn1cblxuZnVuY3Rpb24gZ2V0UHJvdG90eXBlKHZhbHVlKSB7XG4gICAgaWYgKE9iamVjdC5nZXRQcm90b3R5cGVPZikge1xuICAgICAgICByZXR1cm4gT2JqZWN0LmdldFByb3RvdHlwZU9mKHZhbHVlKVxuICAgIH0gZWxzZSBpZiAodmFsdWUuX19wcm90b19fKSB7XG4gICAgICAgIHJldHVybiB2YWx1ZS5fX3Byb3RvX19cbiAgICB9IGVsc2UgaWYgKHZhbHVlLmNvbn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bW92ZV0gPSBtb3ZlSW5kZXhcbiAgICAgICAgICAgICAgICByZXZlcnNlW21vdmVJbmRleF0gPSBtb3ZlXG4gICAgICAgICAgICAgICAgaGFzTW92ZXMgPSB0cnVlXG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBtb3ZlSW5kZXgrK1xuICAgICAgICB9IGVsc2UgaWYgKGkgaW4gYU1hdGNoKSB7XG4gICAgICAgICAgICBzaHVmZmxlW2ldID0gdW5kZWZpbmVkXG4gICAgICAgICAgICByZW1vdmVzW2ldID0gbW92ZUluZGV4KytcbiAgICAgICAgICAgIGhhc01vdmVzID0gdHJ1ZVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgd2hpbGUgKGJNYXRjaFtmcmVlSW5kZXhdICE9PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgICAgICBmcmVlSW5kZXgrK1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAoZnJlZUluZGV4IDwgbGVuKSB7XG4gICAgICAgICAgICAgICAgdmFyIGZyZWVDaGlsZCA9IGJDaGlsZHJlbltmcmVlSW5kZXhdXG4gICAgICAgICAgICAgICAgaWYgKGZyZWVDaGlsZCkge1xuICAgICAgICAgICAgICAgICAgICBzaHVmZmxlW2ldID0gZnJlZUNoaWxkXG4gICAgICAgICAgICAgICAgICAgIGlmIChmcmVlSW5kZXggIT09IG1vdmVJbmRleCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgaGFzTW92ZXMgPSB0cnVlXG4gICAgICAgICAgICAgICAgICAgICAgICBtb3Zlc1tmcmVlSW5kZXhdID0gbW92ZUluZGV4XG4gICAgICAgICAgICAgICAgICAgICAgICByZXZlcnNlW21vdmVJbmRleF0gPSBmcmVlSW5kZXhcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICBtb3ZlSW5kZXgrK1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBmcmVlSW5kZXgrK1xuICAgICAgICAg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aWVzXG4gICAgICAgIHByb3BzID0ge31cbiAgICB9XG5cbiAgICBwcm9wcyA9IHByb3BzIHx8IHByb3BlcnRpZXMgfHwge31cbiAgICB0YWcgPSBwYXJzZVRhZyh0YWdOYW1lLCBwcm9wcylcblxuICAgIC8vIHN1cHBvcnQga2V5c1xuICAgIGlmIChcImtleVwiIGluIHByb3BzKSB7XG4gICAgICAgIGtleSA9IHByb3BzLmtleVxuICAgICAgICBwcm9wcy5rZXkgPSB1bmRlZmluZWRcbiAgICB9XG5cbiAgICAvLyBzdXBwb3J0IG5hbWVzcGFjZVxuICAgIGlmIChcIm5hbWVzcGFjZVwiIGluIHByb3BzKSB7XG4gICAgICAgIG5hbWVzcGFjZSA9IHByb3BzLm5hbWVzcGFjZVxuICAgICAgICBwcm9wcy5uYW1lc3BhY2UgPSB1bmRlZmluZWRcbiAgICB9XG5cbiAgICAvLyBmaXggY3Vyc29yIGJ1Z1xuICAgIGlmICh0YWcgPT09IFwiaW5wdXRcIiAmJlxuICAgICAgICBcInZhbHVlXCIgaW4gcHJvcHMgJiZcbiAgICAgICAgcHJvcHMudmFsdWUgIT09IHVuZGVmaW5lZCAmJlxuICAgICAgICAhaXNIb29rKHByb3BzLnZhbHVlKVxuICAgICkge1xuICAgICAgICBwcm9wcy52YWx1ZSA9IHNvZnRTZXRIb29rKHByb3BzLnZhbHVlKVxuICAgIH1cblxuICAgIHZhciBrZXlzID0gT2JqZWN0LmtleXMocHJvcHMpXG4gICAgdmFyIHByb3BOYW1lLCB2YWx1ZVxuICAgIGZvciAodmFyIGogPSAwOyBqIDwga2V5cy5sZW5ndGg7IGorKykge1xuICAgICAgICBwcm9wTmFtZSA9IGtleXNbal1cbiAgICAgICAgdmFsdWUgPSBwcm9wc1twcm9wTmFtZV1cbiAgICAgICAgaWYgKGlzSG9vayh2YWx1ZSkpIHtcbiAgICAgICAgICAgIGNvbnRpbnVlXG4gICAgICAgIH1cblxuICAgICAgICAvLyBhZGQgZGF0YS1mb28gc3Vwc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hvb2tzID0ge31cbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICBob29rc1twcm9wTmFtZV0gPSBwcm9wZXJ0eVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgZm9yICh2YXIgaSA9IDA7IGkgPCBjb3VudDsgaSsrKSB7XG4gICAgICAgIHZhciBjaGlsZCA9IGNoaWxkcmVuW2ldXG4gICAgICAgIGlmIChpc1ZOb2RlKGNoaWxkKSkge1xuICAgICAgICAgICAgZGVzY2VuZGFudHMgKz0gY2hpbGQuY291bnQgfHwgMFxuXG4gICAgICAgICAgICBpZiAoIWhhc1dpZGdldHMgJiYgY2hpbGQuaGFzV2lkZ2V0cykge1xuICAgICAgICAgICAgICAgIGhhc1dpZGdldHMgPSB0cnVlXG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmICghZGVzY2VuZGFudEhvb2tzICYmIChjaGlsZC5ob29rcyB8fCBjaGlsZC5kZXNjZW5kYW50SG9va3MpKSB7XG4gICAgICAgICAgICAgICAgZGVzY2VuZGFudEhvb2tzID0gdHJ1ZVxuICAgICAgICAgICAgfVxuICAgICAgICB9IGVsc2UgaWYgKCFoYXNXaWRnZXRzICYmIGlzV2lkZ2V0KGNoaWxkKSkge1xuICAgICAgICAgICAgaWYgKHR5cGVvZiBjaGlsZC5kZXN0cm95ID09PSBcImZ1bmN0aW9uXCIpIHtcbiAgICAgICAgICAgICAgICBoYXNXaWRnZXRzID0gdHJ1ZVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgdGhpcy5jb3VudCA9IGNvdW50ICsgZGVzY2VuZGFudHNcbiAgICB0aGlzLmhhc1dpZGdldHMgPSBoYXNXaWRnZXRzXG4gICAgdGhpcy5ob29rcyA9IGhvb2tzXG4gICAgdGhpcy5kZXNjZW5kYW50SG9va3MgPSBkZXNjZW5kYW50SG9va3Ncbn1cblxuVmlydHVhbE5vZGUucHJvdG90eXBlLnZlcn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aXJlKFwiYnVmZmVyXCIpLkJ1ZmZlcixhcmd1bWVudHNbM10sYXJndW1lbnRzWzRdLGFyZ3VtZW50c1s1XSxhcmd1bWVudHNbNl0sXCIvZmFrZV8yYjc2M2Y5OC5qc1wiLFwiL1wiKSJdfQ== diff --git a/dist/js/utils.js b/dist/js/utils.js index ac4ddc5..c9de9ab 100644 --- a/dist/js/utils.js +++ b/dist/js/utils.js @@ -1418,6 +1418,6 @@ module.exports = { replicate: replicate }; -}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/fake_bdf7bcf4.js","/") +}).call(this,require("1YiZ5S"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/fake_b395c286.js","/") },{"1YiZ5S":4,"buffer":1}]},{},[5]) -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi9Vc2Vycy9hbWVkL0hvYmJ5L3J4bWFyYmxlcy9ub2RlX21vZHVsZXMvZ3VscC1icm93c2VyaWZ5L25vZGVfbW9kdWxlcy9icm93c2VyaWZ5L25vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCIvVXNlcnMvYW1lZC9Ib2JieS9yeG1hcmJsZXMvbm9kZV9tb2R1bGVzL2d1bHAtYnJvd3NlcmlmeS9ub2RlX21vZHVsZXMvYnJvd3NlcmlmeS9ub2RlX21vZHVsZXMvYnVmZmVyL2luZGV4LmpzIiwiL1VzZXJzL2FtZWQvSG9iYnkvcnhtYXJibGVzL25vZGVfbW9kdWxlcy9ndWxwLWJyb3dzZXJpZnkvbm9kZV9tb2R1bGVzL2Jyb3dzZXJpZnkvbm9kZV9tb2R1bGVzL2J1ZmZlci9ub2RlX21vZHVsZXMvYmFzZTY0LWpzL2xpYi9iNjQuanMiLCIvVXNlcnMvY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9kXG4gKi9cbmZ1bmN0aW9uIHJlcGxpY2F0ZShzb3VyY2UsIHN1YmplY3QpIHtcbiAgcmV0dXJuIHNvdXJjZS5zdWJzY3JpYmUoXG4gICAgZnVuY3Rpb24gcmVwbGljYXRpb25Pbk5leHQoeCkge1xuICAgICAgc3ViamVjdC5vbk5leHQoeCk7XG4gICAgfSxcbiAgICBmdW5jdGlvbiByZXBsaWNhdGlvbk9uRXJyb3IoZXJyKSB7XG4gICAgICBjb25zb2xlLmVycm9yKGVycik7XG4gICAgfVxuICApO1xufVxuXG5tb2R1bGUuZXhwb3J0cyA9IHtcbiAgcmVwbGljYXRlOiByZXBsaWNhdGVcbn07XG5cbn0pLmNhbGwodGhpcyxyZXF1aXJlKFwiMVlpWjVTXCIpLHR5cGVvZiBzZWxmICE9PSBcInVuZGVmaW5lZFwiID8gc2VsZiA6IHR5cGVvZiB3aW5kb3cgIT09IFwidW5kZWZpbmVkXCIgPyB3aW5kb3cgOiB7fSxyZXF1aXJlKFwiYnVmZmVyXCIpLkJ1ZmZlcixhcmd1bWVudHNbM10sYXJndW1lbnRzWzRdLGFyZ3VtZW50c1s1XSxhcmd1bWVudHNbNl0sXCIvZmFrZV9iMzk1YzI4Ni5qc1wiLFwiL1wiKSJdfQ== diff --git a/package.json b/package.json index bcbb64f..8d0f6a1 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,6 @@ "rx": "2.3.12", "virtual-dom": "0.0.19", "virtual-hyperscript": "4.4.0", - "hyperscript": "1.4.0", "dom-delegator": "^9.0.1" }, "devDependencies": { diff --git a/src/app.js b/src/app.js index 06355f1..a626c57 100644 --- a/src/app.js +++ b/src/app.js @@ -6,7 +6,7 @@ var OperatorsMenuModel = require('rxmarbles/models/operators-menu'); var OperatorsMenuView = require('rxmarbles/views/operators-menu'); var OperatorsMenuIntent = require('rxmarbles/intents/operators-menu'); var SandboxModel = require('rxmarbles/models/sandbox'); -var SandboxView = require('rxmarbles/views/new-sandbox'); +var SandboxView = require('rxmarbles/views/sandbox'); var SandboxIntent = require('rxmarbles/intents/sandbox'); var renderer = require('rxmarbles/renderer'); diff --git a/src/models/input-diagrams.js b/src/models/input-diagrams.js deleted file mode 100644 index 4ebaff2..0000000 --- a/src/models/input-diagrams.js +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Exports an array of diagram streams representing the input diagrams. - */ -// DEPRECATED DEPRECATED DEPRECATED DEPRECATED DEPRECATED -var Rx = require('rx'); -// TODO change below with SandboxModel.example -var OperatorsMenuModel = require('rxmarbles/models/operators-menu'); -var Utils = require('rxmarbles/models/utils'); -var Sandbox = require('rxmarbles/views/sandbox'); - -var arrayOfInitialInputDiagrams$ = new Rx.BehaviorSubject(null); - -function prepareNotification(input) { - if (typeof input.time !== "undefined") { - return input; - } - var output = { - time: input.t, - content: input.d - }; - output.id = Utils.calculateNotificationHash(output); - return output; -}; - -function getNotifications(diagram) { - var last = diagram[diagram.length - 1]; - if (typeof last === 'number') { - return diagram.slice(0, -1); - } else { - return diagram; - } -}; - -function prepareInputDiagram(diagram, indexInArray) { - if (indexInArray == null) { - indexInArray = 0; - } - var notifications = getNotifications(diagram); - var last = diagram[diagram.length - 1]; - var preparedDiagram = []; - for (var i = 0; i < notifications.length; i++) { - preparedDiagram.push(prepareNotification(notifications[i])); - } - preparedDiagram.end = (typeof last === 'number') ? last : 100; - preparedDiagram.id = indexInArray; - return preparedDiagram; -}; - -OperatorsMenuModel.selectedExample$ - .map(function(example) { - return example["inputs"].map(prepareInputDiagram); - }) - .subscribe(function(arrayOfDiagrams) { - arrayOfInitialInputDiagrams$.onNext(arrayOfDiagrams); - }); - -var continuous$ = Sandbox.getStreamOfArrayOfLiveInputDiagramStreams(); - -module.exports = { - initial$: arrayOfInitialInputDiagrams$, - continuous$: continuous$ -}; diff --git a/src/models/output-diagram.js b/src/models/output-diagram.js deleted file mode 100644 index 40ea9ab..0000000 --- a/src/models/output-diagram.js +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Exports the diagram stream representing the output diagram. - */ -// DEPRECATED DEPRECATED DEPRECATED DEPRECATED DEPRECATED DEPRECATED -var Rx = require('rx'); -var Utils = require('rxmarbles/models/utils'); -var InputDiagrams = require('rxmarbles/models/input-diagrams'); -// TODO Change below with SandboxModel.example -var OperatorsMenuModel = require('rxmarbles/models/operators-menu'); - -var MAXTIME = 100; // Time of completion - -var outputDiagramStream = InputDiagrams.continuous$ - .filter(function(x) { return (x !== null); }) - .flatMapLatest(function(arrayOfDiagramStreams) { - return Rx.Observable.combineLatest(arrayOfDiagramStreams, function() { - return (1 <= arguments.length) ? Array.prototype.slice.call(arguments) : []; - }); - }) - .combineLatest(OperatorsMenuModel.selectedExample$, function(diagrams, example) { - var vtscheduler = Utils.makeScheduler(); - var inputVTStreams = []; - for (var i = 0; i < diagrams.length; i++) { - inputVTStreams.push(Utils.toVTStream(diagrams[i], vtscheduler)); - } - var outputVTStream = example["apply"](inputVTStreams, vtscheduler); - // Necessary hack to include marbles at exactly 100.01 - var correctedMaxTime = MAXTIME + 0.02; - outputVTStream = outputVTStream.takeUntilWithTime(correctedMaxTime, vtscheduler); - var outputDiagram = Utils.getDiagramPromise(outputVTStream, vtscheduler, MAXTIME); - vtscheduler.start(); - return outputDiagram; - }) - .mergeAll(); - -module.exports = outputDiagramStream; diff --git a/src/models/utils.js b/src/models/utils.js index cd809e0..b0b8554 100644 --- a/src/models/utils.js +++ b/src/models/utils.js @@ -2,20 +2,6 @@ * Conversion from virtual time streams out to diagram data, and * vice-versa, and related functions. */ -var Rx = require('rx'); - -// DEPRECATED. Used only in old output-diagram.js -function makeScheduler() { - var scheduler = new Rx.VirtualTimeScheduler(0, function(x, y) { - if (x > y) { return 1; } - if (x < y) { return -1; } - return 0; - }); - scheduler.add = function(absolute, relative) { return absolute + relative; }; - scheduler.toDateTimeOffset = function(absolute) { return Math.floor(absolute); }; - scheduler.toRelative = function(timeSpan) { return timeSpan; }; - return scheduler; -}; function calculateNotificationContentHash(content) { var SOME_PRIME_NUMBER = 877; @@ -38,71 +24,7 @@ function calculateNotificationHash(marbleData) { return ((marbleData.time + contentHash + SMALL_PRIME) * LARGE_PRIME) % MAX; }; -// DEPRECATED. Used only in old output-diagram.js -function justIncomplete(item, scheduler) { - return new Rx.AnonymousObservable(function(observer) { - return scheduler.schedule(function() { - observer.onNext(item); - }); - }); -}; - -// DEPRECATED. Used only in old output-diagram.js -/** - * Creates an (virtual time) Rx.Observable from diagram - * data (array of data items). - */ -function toVTStream(diagramData, scheduler) { - var singleMarbleStreams = []; - for (var i = 0; i < diagramData.length; i++) { - var item = diagramData[i]; - singleMarbleStreams.push( - justIncomplete(item, scheduler).delay(item.t || item.time, scheduler) - ); - } - // Necessary correction to include marbles at time exactly diagramData.end: - var correctedEndTime = diagramData.end + 0.01; - return Rx.Observable.merge(singleMarbleStreams) - .takeUntilWithTime(correctedEndTime, scheduler) - .publish().refCount(); -}; - -// DEPRECATED. Used only in old output-diagram.js -function getDiagramPromise(stream, scheduler, maxTime) { - var diagram = []; - var subject = new Rx.BehaviorSubject([]); - stream - .observeOn(scheduler) - .timestamp(scheduler) - .map(function(x) { - if (typeof x.value !== "object") { - x.value = {content: x.value, id: calculateNotificationContentHash(x.value)}; - } - return { - time: (x.timestamp / maxTime) * 100, // converts timestamp to % of maxTime - content: x.value.content, - id: x.value.id - }; - }) - .reduce(function(acc, x) { - acc.push(x); - return acc; - },[]) - .subscribe(function onNext(x) { - diagram = x; - subject.onNext(diagram); - }, function onError() { - console.warn("Error in the diagram promise stream"); - }, function onComplete() { - diagram.end = scheduler.now(); - }); - return subject.asObservable(); -}; - module.exports = { - makeScheduler: makeScheduler, - toVTStream: toVTStream, calculateNotificationHash: calculateNotificationHash, - calculateNotificationContentHash: calculateNotificationContentHash, - getDiagramPromise: getDiagramPromise + calculateNotificationContentHash: calculateNotificationContentHash }; diff --git a/src/renderer.js b/src/renderer.js index b4a62e8..38a1ded 100644 --- a/src/renderer.js +++ b/src/renderer.js @@ -3,15 +3,39 @@ * Subscribes to vtree observables of all view components * and renders them as real DOM elements to the browser. */ -var Package = require('package.json'); -//var Sandbox = require('rxmarbles/views/sandbox'); -var OperatorsMenuView = require('rxmarbles/views/operators-menu'); -var SandboxView = require('rxmarbles/views/new-sandbox'); -var renderVTreeStream = require('rxmarbles/views/utils').renderVTreeStream; +var h = require('virtual-hyperscript'); +var VDOM = { + diff: require('virtual-dom/diff'), + patch: require('virtual-dom/patch') +}; var DOMDelegator = require('dom-delegator'); +var OperatorsMenuView = require('rxmarbles/views/operators-menu'); +var SandboxView = require('rxmarbles/views/sandbox'); +var Package = require('package.json'); var domDelegator; +function renderVTreeStream(vtree$, containerSelector) { + // Find and prepare the container + var container = document.querySelector(containerSelector); + if (container === null) { + console.error("Couldn't render into unknown '" + containerSelector + "'"); + return false; + } + container.innerHTML = ""; + // Make the DOM node bound to the VDOM node + var rootNode = document.createElement("div"); + container.appendChild(rootNode); + vtree$.startWith(h()) + .bufferWithCount(2, 1) + .subscribe(function(buffer) { + var oldVTree = buffer[0]; + var newVTree = buffer[1]; + rootNode = VDOM.patch(rootNode, VDOM.diff(oldVTree, newVTree)); + }); + return true; +}; + function renderAppVersionOnce() { var versionElement = document.querySelector("a.js-appVersion"); versionElement.textContent = "v" + Package.version; diff --git a/src/views/completion.js b/src/views/completion.js index 4a1573a..bcd30f8 100644 --- a/src/views/completion.js +++ b/src/views/completion.js @@ -1,25 +1,10 @@ /* * Renders a marker for the completion notification of a stream diagram. */ -var h = require('hyperscript'); -var vh = require('virtual-hyperscript'); -var Utils = require('rxmarbles/views/utils'); +var h = require('virtual-hyperscript'); var MARBLE_WIDTH = 5; // estimate of a marble width, in percentages -function render(completionTime) { - var element = h('div.diagramCompletion.is-draggable.js-completion', {}, [ - h('div.diagramCompletion-inner') - ]); - element.dataStream = Utils.getInteractiveLeftPosStream(element, completionTime); - element.dataStream - .subscribe(function(leftPos) { - element.style.left = leftPos + '%'; - return true; - }); - return element; -} - function vrender(completionData, isDraggable, diagramData, mouseDown$) { if (typeof isDraggable === 'undefined') { isDraggable = false; @@ -32,16 +17,15 @@ function vrender(completionData, isDraggable, diagramData, mouseDown$) { } }); var isTallClass = (isTall) ? '.is-tall' : ''; - return vh('div.diagramCompletion' + isDraggableClass + isTallClass, { + return h('div.diagramCompletion' + isDraggableClass + isTallClass, { style: {'left': completionData.time + '%'}, attributes: {'data-diagram-id': completionData.diagramId}, 'ev-mousedown': function(ev) { if (mouseDown$) { mouseDown$.onNext(ev); } } },[ - vh('div.diagramCompletion-inner') + h('div.diagramCompletion-inner') ]); } module.exports = { - render: render, vrender: vrender }; diff --git a/src/views/input-diagram.js b/src/views/input-diagram.js deleted file mode 100644 index 6fc3641..0000000 --- a/src/views/input-diagram.js +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Renders a stream diagram meant as an input to the sandbox. - */ -var Rx = require('rx'); -var h = require('hyperscript'); -var Marble = require('rxmarbles/views/marble'); -var Completion = require('rxmarbles/views/completion'); - -function makeDiagramBodyChildren(diagramData) { - var marbleViews = []; - for (var i = 0; i < diagramData.length; i++) { - var marbleData = diagramData[i]; - marbleViews.push(Marble.render(marbleData, true)); - } - var completionView = Completion.render(diagramData.end); - return [completionView].concat(marbleViews); -}; - -function makeDataStream(diagramElement) { - var marbleViews = diagramElement.querySelectorAll(".js-marble"); - var completionElement = diagramElement.querySelector(".js-completion"); - var marbleDataStreams = []; - for (var i = 0; i < marbleViews.length; i++) { - marbleDataStreams.push(marbleViews[i].dataStream); - } - var dataStream = Rx.Observable - .combineLatest(marbleDataStreams, function() { - return (1 <= arguments.length) ? Array.prototype.slice.call(arguments) : []; - }) - .combineLatest(completionElement.dataStream, function(marblesData, endTime) { - marblesData.end = endTime; - return marblesData; - }); - return dataStream; -}; - -//////// CoffeeScript -// makeMouseDownStream = (diagramElement) -> -// marbleViews = diagramElement.querySelectorAll(".js-marble") -// marbleIds = (marble.marbleId for marble in marbleViews) -// return Marble.mouseDownStream -// .filter((ev) -> ev.marbleId in marbleIds) - -module.exports = { - render: function(diagramData) { - var diagramElement = h("div.diagram", {}, [ - h("div.diagram-arrow"), - h("div.diagram-arrowHead"), - h("div.diagram-body", {}, makeDiagramBodyChildren(diagramData)) - ]); - diagramElement.dataStream = makeDataStream(diagramElement); - return diagramElement; - } -}; diff --git a/src/views/marble.js b/src/views/marble.js index f4a3188..26e4247 100644 --- a/src/views/marble.js +++ b/src/views/marble.js @@ -1,87 +1,19 @@ /* * Renders a circle or similar shape to represent an emitted item on a stream. */ -var Rx = require('rx'); -var Utils = require('rxmarbles/views/utils'); -var vh = require('virtual-hyperscript'); +var h = require('virtual-hyperscript'); var svg = require('virtual-hyperscript/svg'); -var XMLNS = 'http://www.w3.org/2000/svg'; var NUM_COLORS = 4; -var SVG_VIEWBOX = '0 0 1 1'; -var SVG_CX = 0.5; -var SVG_CY = 0.5; -var SVG_R = 0.47; -var SVG_BORDER_WIDTH = '0.06px'; - -function createRootElement(draggable) { - var container = document.createElement('div'); - container.className = 'marble js-marble'; - if (draggable) { - container.className += ' is-draggable'; - } - return container; -} - -function createMarbleSvg(item) { - var colornum = (item.id % NUM_COLORS) + 1; - var marble = document.createElementNS(XMLNS, 'svg'); - marble.setAttribute('class', 'marble-inner'); - marble.setAttribute('viewBox', SVG_VIEWBOX); - var circle = document.createElementNS(XMLNS, 'circle'); - circle.setAttribute('cx', SVG_CX); - circle.setAttribute('cy', SVG_CY); - circle.setAttribute('r', SVG_R); - circle.setAttribute('class', 'marble-shape marble-shape--color' + colornum); - circle.setAttribute('stroke-width', SVG_BORDER_WIDTH); - marble.appendChild(circle); - return marble; -} - -function createContentElement(item) { - var content = document.createElement('p'); - content.className = 'marble-content'; - content.textContent = (item != null) ? item.content : ''; - return content; -} - -function getLeftPosStream(item, draggable, element) { - if (draggable) { - return Utils.getInteractiveLeftPosStream(element, item.time); - } else { - return Rx.Observable.just(item.time); - } -} - -function render(item, draggable) { - if (draggable == null) { - draggable = false; - } - // Create DOM elements - var marble = createRootElement(draggable); - marble.appendChild(createMarbleSvg(item)); - marble.appendChild(createContentElement(item)); - // Define public and private streams - var leftPosStream = getLeftPosStream(item, draggable, marble); - marble.dataStream = leftPosStream - .map(function(leftPos) { - return {time: leftPos, content: item.content, id: item.id}; - }); - leftPosStream - .subscribe(function(leftPos) { - marble.style.left = leftPos + '%'; - }); - return marble; -} function vrender(marbleData, isDraggable, mouseDown$) { if (typeof isDraggable === 'undefined') { isDraggable = false; } - var colornum = (marbleData.id % 4) + 1; + var colornum = (marbleData.id % NUM_COLORS) + 1; var leftPos = '' + marbleData.time + '%'; var content = '' + marbleData.content; - return vh('div.marble.js-marble'+(isDraggable ? '.is-draggable' :''), { + return h('div.marble.js-marble'+(isDraggable ? '.is-draggable' :''), { style: {'left': leftPos}, attributes: { 'data-marble-id': marbleData.id, @@ -93,20 +25,19 @@ function vrender(marbleData, isDraggable, mouseDown$) { } } },[ - svg('svg', {attributes: {'class': 'marble-inner', viewBox: SVG_VIEWBOX}}, [ + svg('svg', {attributes: {'class': 'marble-inner', viewBox: '0 0 1 1'}}, [ svg('circle', { attributes: { 'class': 'marble-shape marble-shape--color' + colornum, - cx: SVG_CX, cy: SVG_CY, r: SVG_R, - 'stroke-width': SVG_BORDER_WIDTH + cx: 0.5, cy: 0.5, r: 0.47, + 'stroke-width': '0.06px' } }) ]), - vh('p.marble-content', {}, content) + h('p.marble-content', {}, content) ]); } module.exports = { - render: render, vrender: vrender }; diff --git a/src/views/new-sandbox.js b/src/views/new-sandbox.js deleted file mode 100644 index 4c32a40..0000000 --- a/src/views/new-sandbox.js +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Renders a scrollable list of operators to be demonstrated on the sandbox. - */ -var Rx = require('rx'); -var h = require('virtual-hyperscript'); -var SandboxInput = require('rxmarbles/views/sandbox-input'); -var SandboxOperator = require('rxmarbles/views/sandbox-operator'); -var SandboxOutput = require('rxmarbles/views/sandbox-output'); -var replicate = require('rxmarbles/utils').replicate; - -var modelExample$ = new Rx.BehaviorSubject(); -var modelInputDiagrams$ = new Rx.BehaviorSubject(); -var modelOutputDiagram$ = new Rx.BehaviorSubject(); -var marbleMouseDown$ = new Rx.Subject(); -var completionMouseDown$ = new Rx.Subject(); - -function observe(model) { - replicate(model.example$, modelExample$); - replicate(model.inputDiagrams$, modelInputDiagrams$); - replicate(model.outputDiagram$, modelOutputDiagram$); -} - -var vtree$ = Rx.Observable - .combineLatest(modelExample$, modelInputDiagrams$, modelOutputDiagram$, - function(example, inputDiagrams, outputDiagram) { - return h("div.sandbox", [ - SandboxInput.vrender(inputDiagrams, marbleMouseDown$, completionMouseDown$), - SandboxOperator.vrender(example), - SandboxOutput.vrender(outputDiagram) - ]); - } - ); - -//marbleMouseDown$.subscribe(function(ev) { console.log("LOOK!"); console.log(ev); }); - -module.exports = { - observe: observe, - vtree$: vtree$, - marbleMouseDown$: marbleMouseDown$, - completionMouseDown$: completionMouseDown$ -}; diff --git a/src/views/operator-box.js b/src/views/operator-box.js deleted file mode 100644 index 54d1a3d..0000000 --- a/src/views/operator-box.js +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Renders a box representing the Rx operator being applied on the input - * streams. - */ -var h = require('hyperscript'); - -function renderLabel(label) { - var attrs = (label.length > 20) ? {style: {"font-size": "1.5rem"}} : {}; - return h("span.operator-box-label", attrs, label); -}; - -module.exports = { - render: function(example) { - return h("div.operator-box", [renderLabel(example.label)]); - } -}; diff --git a/src/views/output-diagram.js b/src/views/output-diagram.js deleted file mode 100644 index fe492cf..0000000 --- a/src/views/output-diagram.js +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Renders a stream diagram meant as an output to the sandbox. - */ -var Rx = require('rx'); -var h = require('virtual-hyperscript'); -var Marble = require('rxmarbles/views/marble'); -var Completion = require('rxmarbles/views/completion'); -var VDOM = { - createElement: require('virtual-dom/create-element'), - diff: require('virtual-dom/diff'), - patch: require('virtual-dom/patch') -}; - -function makeDiagramBodyChildren(diagramData) { - var marbleViews = []; - for (i = 0; i < diagramData.length; i++) { - marbleViews.push(Marble.vrender(diagramData[i])); - } - var children = [Completion.vrender(diagramData.end)].concat(marbleViews); - return children; -}; - -function virtualRender(diagramData) { - if (diagramData === null) { - return h("div.diagram"); - } else { - return h("div.diagram", {}, [ - h("div.diagram-arrow"), - h("div.diagram-arrowHead"), - h("div.diagram-body", {}, makeDiagramBodyChildren(diagramData)) - ]); - } -}; - -module.exports = { - // options.data is a diagram data array - render: function(diagramDataStream) { - var tree = virtualRender(null); - var rootNode = VDOM.createElement(tree); - diagramDataStream.subscribe(function(diagram) { - var newTree = virtualRender(diagram); - rootNode = VDOM.patch(rootNode, VDOM.diff(tree, newTree)); - tree = newTree; - }); - return rootNode; - } -}; diff --git a/src/views/sandbox.js b/src/views/sandbox.js index c0eeef6..412a999 100644 --- a/src/views/sandbox.js +++ b/src/views/sandbox.js @@ -1,62 +1,39 @@ /* - * Responsible for rendering the sandbox element and connecting controller - * streams to the views. + * SandboxView */ var Rx = require('rx'); -var h = require('hyperscript'); -var InputDiagramView = require('rxmarbles/views/input-diagram'); -var OperatorBox = require('rxmarbles/views/operator-box'); -var OutputDiagramView = require('rxmarbles/views/output-diagram'); -var Utils = require('rxmarbles/views/utils'); +var h = require('virtual-hyperscript'); +var SandboxInput = require('rxmarbles/views/sandbox-input'); +var SandboxOperator = require('rxmarbles/views/sandbox-operator'); +var SandboxOutput = require('rxmarbles/views/sandbox-output'); +var replicate = require('rxmarbles/utils').replicate; -var streamOfArrayOfLiveInputDiagramStreams = new Rx.BehaviorSubject(null); +var modelExample$ = new Rx.BehaviorSubject(); +var modelInputDiagrams$ = new Rx.BehaviorSubject(); +var modelOutputDiagram$ = new Rx.BehaviorSubject(); +var marbleMouseDown$ = new Rx.Subject(); +var completionMouseDown$ = new Rx.Subject(); -function createInputDiagramElements() { - var InputDiagrams = require('rxmarbles/models/input-diagrams'); - var inputDiagramElements = Utils.renderObservableDOMElement( - InputDiagrams.initial$ - .map(function(diagrams) { - var diagramViews = []; - for (i = 0; i < diagrams.length; i++) { - diagramViews.push(InputDiagramView.render(diagrams[i])); - } - return diagramViews; - }) - .doAction(function(diagramViews) { - var dataStreams = []; - for (i = 0; i < diagramViews.length; i++) { - dataStreams.push(diagramViews[i].dataStream); - } - return streamOfArrayOfLiveInputDiagramStreams.onNext(dataStreams); - }) - ); - return inputDiagramElements; -}; +function observe(model) { + replicate(model.example$, modelExample$); + replicate(model.inputDiagrams$, modelInputDiagrams$); + replicate(model.outputDiagram$, modelOutputDiagram$); +} -function createOperatorBoxElement() { - // TODO change this with SandboxModel.operator$ - var OperatorsMenuModel = require('rxmarbles/models/operators-menu'); - return Utils.renderObservableDOMElement( - OperatorsMenuModel.selectedExample$ - .map(function(example) { return OperatorBox.render(example); }) +var vtree$ = Rx.Observable + .combineLatest(modelExample$, modelInputDiagrams$, modelOutputDiagram$, + function(example, inputDiagrams, outputDiagram) { + return h("div.sandbox", [ + SandboxInput.vrender(inputDiagrams, marbleMouseDown$, completionMouseDown$), + SandboxOperator.vrender(example), + SandboxOutput.vrender(outputDiagram) + ]); + } ); -}; - -function createOutputDiagramElement() { - var OutputDiagram = require('rxmarbles/models/output-diagram'); - return OutputDiagramView.render(OutputDiagram); -}; module.exports = { - getStreamOfArrayOfLiveInputDiagramStreams: function() { - return streamOfArrayOfLiveInputDiagramStreams; - }, - - render: function() { - return h("div.sandbox", [ - createInputDiagramElements(), - createOperatorBoxElement(), - createOutputDiagramElement() - ]); - } + observe: observe, + vtree$: vtree$, + marbleMouseDown$: marbleMouseDown$, + completionMouseDown$: completionMouseDown$ }; diff --git a/src/views/utils.js b/src/views/utils.js deleted file mode 100644 index ee46ee1..0000000 --- a/src/views/utils.js +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Util functions for rendering to the DOM. - */ -var Rx = require('rx'); -var h = require('virtual-hyperscript'); -var VDOM = { - createElement: require('virtual-dom/create-element'), - diff: require('virtual-dom/diff'), - patch: require('virtual-dom/patch') -}; - -function getDxDragStream(element) { - return Rx.Observable.fromEvent(element, "mousedown") - .map(function() { - var moveStream = Rx.Observable.fromEvent(document, "mousemove"); - var upStream = Rx.Observable.fromEvent(document, "mouseup"); - var dxStream = moveStream - .map(function(ev) { - ev.stopPropagation; - ev.preventDefault(); - return ev.pageX; - }) - .windowWithCount(2, 1) - .flatMap(function(result) { return result.toArray(); }) - .map(function(array) { return array[1] - array[0]; }); - return dxStream.takeUntil(upStream); - }) - .concatAll(); -} - -function getInteractiveLeftPosStream(element, initialPos) { - return getDxDragStream(element) - .scan(initialPos, function(acc, dx) { - var pxToPercentage = 1; - try { - pxToPercentage = 100.0 / element.parentElement.clientWidth; - } catch (err) { - console.warn(err); - } - return acc + (dx * pxToPercentage); - }) - .map(function(pos) { - if (pos < 0) { return 0; } - if (pos > 100) { return 100; } - return pos; - }) - .map(Math.round) - .startWith(initialPos) - .distinctUntilChanged(); -} - -function renderVTreeStream(vtree$, containerSelector) { - // Find and prepare the container - var container = document.querySelector(containerSelector); - if (container === null) { - console.error("Couldn't render into unknown '" + containerSelector + "'"); - return false; - } - container.innerHTML = ""; - // Make the DOM node bound to the VDOM node - var rootNode = document.createElement("div"); - container.appendChild(rootNode); - vtree$.startWith(h()) - .bufferWithCount(2, 1) - .subscribe(function(buffer) { - var oldVTree = buffer[0]; - var newVTree = buffer[1]; - rootNode = VDOM.patch(rootNode, VDOM.diff(oldVTree, newVTree)); - }); - return true; -}; - -function renderObservableDOMElement(elementStream) { - var wrapper = document.createElement("div"); - elementStream.subscribe(function(thing) { - wrapper.innerHTML = ""; - if (Array.isArray(thing)) { - for (i = 0; i < thing.length; i++) { - wrapper.appendChild(thing[i]); - } - } else if (thing instanceof Element) { - wrapper.appendChild(thing); - } - }); - return wrapper; -}; - -module.exports = { - renderVTreeStream: renderVTreeStream, - renderObservableDOMElement: renderObservableDOMElement, - getInteractiveLeftPosStream: getInteractiveLeftPosStream -};