diff --git a/.obsidian/core-plugins.json b/.obsidian/core-plugins.json index d34c8c2..845dca4 100644 --- a/.obsidian/core-plugins.json +++ b/.obsidian/core-plugins.json @@ -13,6 +13,5 @@ "starred", "markdown-importer", "word-count", - "open-with-default-app", "file-recovery" ] \ No newline at end of file diff --git a/.obsidian/plugins/dataview/main.js b/.obsidian/plugins/dataview/main.js index 79522a5..d4fe4b3 100644 --- a/.obsidian/plugins/dataview/main.js +++ b/.obsidian/plugins/dataview/main.js @@ -1,6 +1,8 @@ 'use strict'; var obsidian = require('obsidian'); +var view = require('@codemirror/view'); +var language = require('@codemirror/language'); function _mergeNamespaces(n, m) { m.forEach(function (e) { @@ -8575,7 +8577,9 @@ var Luxon = /*#__PURE__*/_mergeNamespaces({ const DEFAULT_QUERY_SETTINGS = { renderNullAs: "\\-", taskCompletionTracking: false, + taskCompletionUseEmojiShorthand: false, taskCompletionText: "completion", + taskCompletionDateFormat: "yyyy-MM-dd", warnOnEmptyResult: true, refreshEnabled: true, refreshInterval: 2500, @@ -8585,12 +8589,17 @@ const DEFAULT_QUERY_SETTINGS = { tableIdColumnName: "File", tableGroupColumnName: "Group", }; +const DEFAULT_EXPORT_SETTINGS = { + allowHtml: true, +}; /** Default settings for dataview on install. */ const DEFAULT_SETTINGS = { ...DEFAULT_QUERY_SETTINGS, + ...DEFAULT_EXPORT_SETTINGS, ...{ inlineQueryPrefix: "=", inlineJsQueryPrefix: "$=", + inlineQueriesInCodeblocks: true, enableDataviewJs: false, enableInlineDataviewJs: false, prettyRenderInlineFields: true, @@ -8840,12 +8849,14 @@ var Values; return setting.renderNullAs; switch (wrapped.type) { case "null": - return "" + setting.renderNullAs; + return setting.renderNullAs; case "string": return wrapped.value; case "number": case "boolean": return "" + wrapped.value; + case "html": + return wrapped.value.outerHTML; case "widget": return wrapped.value.markdown(); case "link": @@ -8898,6 +8909,8 @@ var Values; return { type: "link", value: val }; else if (isFunction(val)) return { type: "function", value: val }; + else if (isHtml(val)) + return { type: "html", value: val }; else if (isObject(val)) return { type: "object", value: val }; else @@ -9026,7 +9039,7 @@ var Values; } return 0; case "widget": - return 0; + case "html": case "function": return 0; } @@ -9062,8 +9075,8 @@ var Values; return wrapped.value.length > 0; case "null": return false; + case "html": case "widget": - return true; case "function": return true; } @@ -9123,8 +9136,19 @@ var Values; return val instanceof Widget; } Values.isWidget = isWidget; + function isHtml(val) { + if (typeof HTMLElement !== "undefined") { + return val instanceof HTMLElement; + } + else { + return false; + } + } + Values.isHtml = isHtml; + /** Checks if the given value is an object (and not any other dataview-recognized object-like type). */ function isObject(val) { return (typeof val == "object" && + !isHtml(val) && !isWidget(val) && !isArray(val) && !isDuration(val) && @@ -9240,6 +9264,7 @@ class Link { return { path: this.path, type: this.type, subpath: this.subpath, display: this.display, embed: this.embed }; } /** Update this link with a new path. */ + //@ts-ignore; error appeared after updating Obsidian to 0.15.4; it also updated other packages but didn't say which withPath(path) { return new Link(Object.assign({}, this, { path })); } @@ -9739,6 +9764,9 @@ async function renderValue(field, container, originFile, component, settings, ex else if (Values.isLink(field)) { await renderCompactMarkdown(field.markdown(), container, originFile, component); } + else if (Values.isHtml(field)) { + container.appendChild(field); + } else if (Values.isWidget(field)) { if (Widgets.isListPair(field)) { await renderValue(field.key, container, originFile, component, settings, expandList, context, depth); @@ -10270,6 +10298,7 @@ function findClosing(line, start, open, close) { escaped = !escaped; continue; } + // If escaped, ignore the next character for computing nesting, regardless of what it is. if (escaped) { escaped = false; continue; @@ -10353,7 +10382,13 @@ function extractInlineFields(line, includeTaskFields = false) { if (includeTaskFields) fields = fields.concat(extractSpecialTaskFields(line)); fields.sort((a, b) => a.start - b.start); - return fields; + let filteredFields = []; + for (let i = 0; i < fields.length; i++) { + if (i == 0 || filteredFields[filteredFields.length - 1].end < fields[i].start) { + filteredFields.push(fields[i]); + } + } + return filteredFields; } /** Validates that a raw field name has a valid form. */ const FULL_LINE_KEY_PART = parsimmon_umd_min.exports.alt(parsimmon_umd_min.exports.regexp(new RegExp(emojiRegex(), "u")), parsimmon_umd_min.exports.regexp(/[0-9\p{Letter}\w\s_/-]+/u)) @@ -10363,41 +10398,31 @@ parsimmon_umd_min.exports.regexp(/[^0-9\w\p{Letter}]*/u) .then(FULL_LINE_KEY_PART) .skip(parsimmon_umd_min.exports.regexp(/[_\*~`]*/u)); const CREATED_DATE_REGEX = /\u{2795}\s*(\d{4}-\d{2}-\d{2})/u; -const DUE_DATE_REGEX = /[\u{1F4C5}\u{1F4C6}\u{1F5D3}\u{FE0F}]{1,}\s*(\d{4}-\d{2}-\d{2})/u; +const DUE_DATE_REGEX = /(?:\u{1F4C5}|\u{1F4C6}|\u{1F5D3}\u{FE0F})\s*(\d{4}-\d{2}-\d{2})/u; const DONE_DATE_REGEX = /\u{2705}\s*(\d{4}-\d{2}-\d{2})/u; +const SCHEDULED_DATE_REGEX = /[\u{23F3}\u{231B}]\s*(\d{4}-\d{2}-\d{2})/u; +const START_DATE_REGEX = /\u{1F6EB}\s*(\d{4}-\d{2}-\d{2})/u; /** Parse special completed/due/done task fields which are marked via emoji. */ function extractSpecialTaskFields(line) { let results = []; - let createdMatch = CREATED_DATE_REGEX.exec(line); - if (createdMatch) - results.push({ - key: "created", - value: createdMatch[1], - start: createdMatch.index, - startValue: createdMatch.index + 1, - end: createdMatch.index + createdMatch[0].length, - wrapping: "emoji-shorthand", - }); - let dueMatch = DUE_DATE_REGEX.exec(line); - if (dueMatch) - results.push({ - key: "due", - value: dueMatch[1], - start: dueMatch.index, - startValue: dueMatch.index + 1, - end: dueMatch.index + dueMatch[0].length, - wrapping: "emoji-shorthand", - }); - let completedMatch = DONE_DATE_REGEX.exec(line); - if (completedMatch) - results.push({ - key: "completion", - value: completedMatch[1], - start: completedMatch.index, - startValue: completedMatch.index + 1, - end: completedMatch.index + completedMatch[0].length, - wrapping: "emoji-shorthand", - }); + [ + { shorthandDateRegex: CREATED_DATE_REGEX, shorthandDateKey: "created" }, + { shorthandDateRegex: START_DATE_REGEX, shorthandDateKey: "start" }, + { shorthandDateRegex: SCHEDULED_DATE_REGEX, shorthandDateKey: "scheduled" }, + { shorthandDateRegex: DUE_DATE_REGEX, shorthandDateKey: "due" }, + { shorthandDateRegex: DONE_DATE_REGEX, shorthandDateKey: "completion" }, + ].forEach(shorthandRegexAndKey => { + const shorthandDateMatch = shorthandRegexAndKey.shorthandDateRegex.exec(line); + if (shorthandDateMatch) + results.push({ + key: shorthandRegexAndKey.shorthandDateKey, + value: shorthandDateMatch[1], + start: shorthandDateMatch.index, + startValue: shorthandDateMatch.index + 1, + end: shorthandDateMatch.index + shorthandDateMatch[0].length, + wrapping: "emoji-shorthand", + }); + }); return results; } /** Sets or replaces the value of an inline field; if the value is 'undefined', deletes the key. */ @@ -10422,6 +10447,24 @@ function setInlineField(source, key, value) { } return source; } +function setEmojiShorthandCompletionField(source, value) { + const existing = extractInlineFields(source, true); + const existingKeys = existing.filter(f => f.key === "completion" && f.wrapping === "emoji-shorthand"); + // Don't do anything if there are duplicate keys OR the key already doesn't exist. + if (existingKeys.length > 2 || (existingKeys.length == 0 && !value)) + return source; + /* No wrapper, add own spacing at start */ + const annotation = value ? ` ✅ ${value}` : ""; + let existingKey = existingKeys[0]; + if (existingKey) { + const prefix = source.substring(0, existingKey.start); + const suffix = source.substring(existingKey.end); + return `${prefix.trimEnd()}${annotation}${suffix}`; + } + else { + return `${source.trimEnd()}${annotation}`; + } +} /** All extracted markdown file metadata obtained from a file. */ class PageMetadata { @@ -10559,6 +10602,14 @@ class ListItem$1 { var _a, _b, _c, _d; return (_d = ((_c = (_b = (_a = this.fields.get("completed")) !== null && _a !== void 0 ? _a : this.fields.get("completion")) !== null && _b !== void 0 ? _b : this.fields.get("comptime")) !== null && _c !== void 0 ? _c : this.fields.get("compday"))) === null || _d === void 0 ? void 0 : _d[0]; } + start() { + var _a; + return (_a = this.fields.get("start")) === null || _a === void 0 ? void 0 : _a[0]; + } + scheduled() { + var _a; + return (_a = this.fields.get("scheduled")) === null || _a === void 0 ? void 0 : _a[0]; + } /** Create an API-friendly copy of this list item. De-duplication is done via the provided cache. */ serialize(cache) { // Map children to their serialized/de-duplicated equivalents right away. @@ -10592,13 +10643,17 @@ class ListItem$1 { result.checked = this.task.checked; result.completed = this.task.completed; result.fullyCompleted = this.task.fullyCompleted; - let created = this.created(), due = this.due(), completed = this.completed(); + let created = this.created(), due = this.due(), completed = this.completed(), start = this.start(), scheduled = this.scheduled(); if (created) result.created = Values.deepCopy(created); if (due) result.due = Values.deepCopy(due); if (completed) result.completion = Values.deepCopy(completed); + if (start) + result.start = Values.deepCopy(start); + if (scheduled) + result.scheduled = Values.deepCopy(scheduled); } return result; } @@ -13713,7 +13768,7 @@ function createBase64WorkerFactory(base64, sourcemapArg, enableUnicodeArg) { }; } -var WorkerFactory = createBase64WorkerFactory('Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24gKCkgewoJJ3VzZSBzdHJpY3QnOwoKCXZhciBjb21tb25qc0dsb2JhbCA9IHR5cGVvZiBnbG9iYWxUaGlzICE9PSAndW5kZWZpbmVkJyA/IGdsb2JhbFRoaXMgOiB0eXBlb2Ygd2luZG93ICE9PSAndW5kZWZpbmVkJyA/IHdpbmRvdyA6IHR5cGVvZiBnbG9iYWwgIT09ICd1bmRlZmluZWQnID8gZ2xvYmFsIDogdHlwZW9mIHNlbGYgIT09ICd1bmRlZmluZWQnID8gc2VsZiA6IHt9OwoKCXZhciBsdXhvbiA9IHt9OwoKCU9iamVjdC5kZWZpbmVQcm9wZXJ0eShsdXhvbiwgJ19fZXNNb2R1bGUnLCB7IHZhbHVlOiB0cnVlIH0pOwoKCWZ1bmN0aW9uIF9kZWZpbmVQcm9wZXJ0aWVzKHRhcmdldCwgcHJvcHMpIHsKCSAgZm9yICh2YXIgaSA9IDA7IGkgPCBwcm9wcy5sZW5ndGg7IGkrKykgewoJICAgIHZhciBkZXNjcmlwdG9yID0gcHJvcHNbaV07CgkgICAgZGVzY3JpcHRvci5lbnVtZXJh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oaXMubnVtKGR0Lm1pbGxpc2Vjb25kLCAzKTsKCSAgICAgICAgLy8gc2Vjb25kcwoKCSAgICAgICAgY2FzZSAicyI6CgkgICAgICAgICAgcmV0dXJuIF90aGlzLm51bShkdC5zZWNvbmQpOwoKCSAgICAgICAgY2FzZSAic3MiOgoJICAgICAgICAgIHJldHVybiBfdGhpcy5udW0oZHQuc2Vjb25kLCAyKTsKCSAgICAgICAgLy8gZnJhY3Rpb25hbCBzZWNvbmRzCgoJICAgICAgICBjYXNlICJ1dSI6CgkgICAgICAgICAgcmV0dXJuIF90aGlzLm51bShNYXRoLmZsb29yKGR0Lm1pbGxpc2Vjb25kIC8gMTApLCAyKTsKCgkgICAgICAgIGNhc2UgInV1dSI6CgkgICAgICAgICAgcmV0dXJuIF90aGlzLm51bShNYXRoLmZsb29yKGR0Lm1pbGxpc2Vjb25kIC8gMTAwKSk7CgkgICAgICAgIC8vIG1pbnV0ZXMKCgkgICAgICAgIGNhc2UgIm0iOgoJICAgICAgICAgIHJldHVybiBfdGhpcy5udW0oZHQubWludXRlKTsKCgkgICAgICAgIGNhc2UgIm1tIjoKCSAgICAgICAgICByZXR1cm4gX3RoaXMubnVtKGR0Lm1pbnV0ZSwgMik7CgkgICAgICAgIC8vIGhvdXJzCgoJICAgICAgICBjYXNlICJoIjoKCSAgICAgICAgICByZXR1cm4gX3RoaXMubnVtKGR0LmhvdXIgJSAxMiA9PT0gMCA/IDEyIDogZHQuaG91ciAlIDEyKTsKCgkgICAgICAgIGNhc2UgImhoIjoKCSAgICAgICAgICByZXR1cm4gX3RoaXMubnVtKGR0LmhvdXIgJSAxMiA9PT0gMCA/IDEyIDogZHQuaG91ciAlIDEyLCAyKTsKCgkgICAgICAgIGNhc2UgIkgiOgoJICAgICAgICAgIHJldHVybiBfdGhpcy5udW0oZHQuaG91cik7CgoJICAgICAgICBjYXNlICJISCI6CgkgICAgICAgICAgcmV0dXJuIF90aGlzLm51bShkdC5ob3VyLCAyKTsKCSAgICAgICAgLy8gb2Zmc2V0CgoJICAgICAgICBjYXNlICJaIjoKCSAgICAgICAgICAvLyBsaWtlICs2CgkgICAgICAgICAgcmV0dXJuIGZvcm1hdE9mZnNldCh7CgkgICAgICAgICAgICBmb3JtYXQ6ICJuYXJyb3ciLAoJICAgICAgICAgICAgYWxsb3daOiBfdGhpcy5vcHRzLmFsbG93WgoJICAgICAgICAgIH0pOwoKCSAgICAgICAgY2FzZSAiWloiOgoJICAgICAgICAgIC8vIGxpa2UgKzA2OjAwCgkgICAgICAgICAgcmV0dXJuIGZvcm1hdE9mZnNldCh7CgkgICAgICAgICAgICBmb3JtYXQ6ICJzaG9ydCIsCgkgICAgICAgICAgICBhbGxvd1o6IF90aGlzLm9wdHMuYWxsb3daCgkgICAgICAgICAgfSk7CgoJICAgICAgICBjYXNlICJaWloiOgoJICAgICAgICAgIC8vIGxpa2UgKzA2MDAKCSAgICAgICAgICByZXR1cm4gZm9ybWF0T2Zmc2V0KHsKCSAgICAgICAgICAgIGZvcm1hdDogInRlY2hpZSIsCgkgICAgICAgICAgICBhbGxvd1o6IF90aGlzLm9wdHMuYWxsb3daCgkgICAgICAgICAgfSk7CgoJICAgICAgICBjYXNlICJaWlpaIjoKCSAgICAgICAgICAvLyBsaWtlIEVTVAoJICAgICAgICAgIHJldHVybiBkdC56b25lLm9mZnNldE5hbWUoZHQudHMsIHsKCSAgICAgICAgICAgIGZvcm1hdDogInNob3J0IiwKCSAgICAgICAgICAgIGxvY2FsZTogX3RoaXMubG9jLmxvY2FsZQoJICAgICAgICAgIH0pOwoKCSAgICAgICAgY2FzZSAiWlpaWloiOgoJICAgICAgICAgIC8vIGxpa2UgRWFzdGVybiBTdGFuZGFyZCBUaW1lCgkgICAgICAgICAgcmV0dXJuIGR0LnpvbmUub2Zmc2V0TmFtZShkdC50cywgewoJICAgICAgICAgICAgZm9ybWF0OiAibG9uZyIsCgkgICAgICAgICAgICBsb2NhbGU6IF90aGlzLmxvYy5sb2NhbGUKCSAgICAgICAgICB9KTsKCSAgICAgICAgLy8gem9uZQoKCSAgICAgICAgY2FzZSAieiI6CgkgICAgICAgICAgLy8gbGlrZSBBbWVyaWNhL05ld19Zb3JrCgkgICAgICAgICAgcmV0dXJuIGR0LnpvbmVOYW1lOwoJICAgICAgICAvLyBtZXJpZGllbXMKCgkgICAgICAgIGNhc2UgImEiOgoJICAgICAgICAgIHJldHVybiBtZXJpZGllbSgpOwoJICAgICAgICAvLyBkYXRlcwoKCSAgICAgICAgY2FzZSAiZCI6CgkgICAgICAgICAgcmV0dXJuIHVzZURhdGVUaW1lRm9ybWF0dGVyID8gc3RyaW5nKHsKCSAgICAgICAgICAgIGRheTogIm51bWVyaWMiCgkgICAgICAgICAgfSwgImRheSIpIDogX3RoaXMubnVtKGR0LmRheSk7CgoJICAgICAgICBjYXNlICJkZCI6CgkgICAgICAgICAgcmV0dXJuIHVzZURhdGVUaW1lRm9ybWF0dGVyID8gc3RyaW5nKHsKCSAgICAgICAgICAgIGRheTogIjItZGlnaXQiCgkgICAgICAgICAgfSwgImRheSIpIDogX3RoaXMubnVtKGR0LmRheSwgMik7CgkgICAgICAgIC8vIHdlZWtkYXlzIC0gc3RhbmRhbG9uZQoKCSAgICAgICAgY2FzZSAiYyI6CgkgICAgICAgICAgLy8gbGlrZSAxCgkgICAgICAgICAgcmV0dXJuIF90aGlzLm51bShkdC53ZWVrZGF5KTsKCgkgICAgICAgIGNhc2UgImNjYyI6CgkgICAgICAgICAgLy8gbGlrZSAnVHVlcycKCSAgICAgICAgICByZXR1cm4gd2Vla2RheSgic2hvcnQiLCB0cnVlKTsKCgkgICAgICAgIGNhc2UgImNjY2MiOgoJICAgICAgICAgIC8vIGxpa2UgJ1R1ZXNkYXknCgkgICAgICAgICAgcmV0dXJuIHdlZWtkYXkoImxvbmciLCB0cnVlKTsKCgkgICAgICAgIGNhc2UgImNjY2NjIjoKCSAgICAgICAgICAvLyBsaWtlICdUJwoJICAgICAgICAgIHJldHVybiB3ZWVrZGF5KCJuYXJyb3ciLCB0cnVlKTsKCSAgICAgICAgLy8gd2Vla2RheXMgLSBmb3JtYXQKCgkgICAgICAgIGNhc2UgIkUiOgoJICAgICAgICAgIC8vIGxpa2UgMQoJICAgICAgICAgIHJldHVybiBfdGhpcy5udW0oZHQud2Vla2RheSk7CgoJICAgICAgICBjYXNlICJFRUUiOgoJICAgICAgICAgIC8vIGxpa2UgJ1R1ZXMnCgkgICAgICAgICAgcmV0dXJuIHdlZWtkYXkoInNob3J0IiwgZmFsc2UpOwoKCSAgICAgICAgY2FzZSAiRUVFRSI6CgkgICAgICAgICAgLy8gbGlrZSAnVHVlc2RheScKCSAgICAgICAgICByZXR1cm4gd2Vla2RheSgibG9uZyIsIGZhbHNlKTsKCgkgICAgICAgIGNhc2UgIkVFRUVFIjoKCSAgICAgICAgICAvLyBsaWtlICdUJwoJICAgICAgICAgIHJldHVybiB3ZWVrZGF5KCJuYXJyb3ciLCBmYWxzZSk7CgkgICAgICAgIC8vIG1vbnRocyAtIHN0YW5kYWxvbmUKCgkgICAgICAgIGNhc2UgIkwiOgoJICAgICAgICAgIC8vIGxpa2UgMQoJICAgICAgICAgIHJldHVybiB1c2VEYXRlVGltZUZvcm1hdHRlciA/IHN0cmluZyh7CgkgICAgICAgICAgICBtb250aDogIm51bWVyaWMiLAoJICAgICAgICAgICAgZGF5OiAibnVtZXJpYyIKCSAgICAgICAgICB9LCAibW9udGgiKSA6IF90aGlzLm51bShkdC5tb250aCk7CgoJICAgICAgICBjYXNlICJMTCI6CgkgICAgICAgICAgLy8gbGlrZSAwMSwgZG9lc24ndCBzZWVtIHRvIHdvcmsKCSAgICAgICAgICByZXR1cm4gdXNlRGF0ZVRpbWVGb3JtYXR0ZXIgPyBzdHJpbmcoewoJICAgICAgICAgICAgbW9udGg6ICIyLWRpZ2l0IiwKCSAgICAgICAgICAgIGRheTogIm51bWVyaWMiCgkgICAgICAgICAgfSwgIm1vbnRoIikgOiBfdGhpcy5udW0oZHQubW9udGgsIDIpOwoKCSAgICAgICAgY2FzZSAiTExMIjoKCSAgICAgICAgICAvLyBsaWtlIEphbgoJICAgICAgICAgIHJldHVybiBtb250aCgic2hvcnQiLCB0cnVlKTsKCgkgICAgICAgIGNhc2UgIkxMTEwiOgoJICAgICAgICAgIC8vIGxpa2UgSmFudWFyeQoJICAgICAgICAgIHJldHVybiBtb250aCgibG9uZyIsIHRydWUpOwoKCSAgICAgICAgY2FzZSAiTExMTEwiOgoJICAgICAgICAgIC8vIGxpa2UgSgoJICAgICAgICAgIHJldHVybiBtb250aCgibmFycm93IiwgdHJ1ZSk7CgkgICAgICAgIC8vIG1vbnRocyAtIGZvcm1hdAoKCSAgICAgICAgY2FzZSAiTSI6CgkgICAgICAgICAgLy8gbGlrZSAxCgkgICAgICAgICAgcmV0dXJuIHVzZURhdGVUaW1lRm9ybWF0dGVyID8gc3RyaW5nKHsKCSAgICAgICAgICAgIG1vbnRoOiAibnVtZXJpYyIKCSAgICAgICAgICB9LCAibW9udGgiKSA6IF90aGlzLm51bShkdC5tb250aCk7CgoJICAgICAgICBjYXNlICJNTSI6CgkgICAgICAgICAgLy8gbGlrZSAwMQoJICAgICAgICAgIHJldHVybiB1c2VEYXRlVGltZUZvcm1hdHRlciA/IHN0cmluZyh7CgkgICAgICAgICAgICBtb250aDogIjItZGlnaXQiCgkgICAgICAgICAgfSwgIm1vbnRoIikgOiBfdGhpcy5udW0oZHQubW9udGgsIDIpOwoKCSAgICAgICAgY2FzZSAiTU1NIjoKCSAgICAgICAgICAvLyBsaWtlIEphbgoJICAgICAgICAgIHJldHVybiBtb250aCgic2hvcnQiLCBmYWxzZSk7CgoJICAgICAgICBjYXNlICJNTU1NIjoKCSAgICAgICAgICAvLyBsaWtlIEphbnVhcnkKCSAgICAgICAgICByZXR1cm4gbW9udGgoImxvbmciLCBmYWxzZSk7CgoJICAgICAgICBjYXNlICJNTU1NTSI6CgkgICAgICAgICAgLy8gbGlrZSBKCgkgICAgICAgICAgcmV0dXJuIG1vbnRoKCJuYXJyb3ciLCBmYWxzZSk7CgkgICAgICAgIC8vIHllYXJzCgoJICAgICAgICBjYXNlICJ5IjoKCSAgICAgICAgICAvLyBsaWtlIDIwMTQKCSAgICAgICAgICByZXR1cm4gdXNlRGF0ZVRpbWVGb3JtYXR0ZXIgPyBzdHJpbmcoewoJICAgICAgICAgICAgeWVhcjogIm51bWVyaWMiCgkgICAgICAgICAgfSwgInllYXIiKSA6IF90aGlzLm51bShkdC55ZWFyKTsKCgkgICAgICAgIGNhc2UgInl5IjoKCSAgICAgICAgICAvLyBsaWtlIDE0CgkgICAgICAgICAgcmV0dXJuIHVzZURhdGVUaW1lRm9ybWF0dGVyID8gc3RyaW5nKHsKCSAgICAgICAgICAgIHllYXI6ICIyLWRpZ2l0IgoJICAgICAgICAgIH0sICJ5ZWFyIikgOiBfdGhpcy5udW0oZHQueWVhci50b1N0cmluZygpLnNsaWNlKC0yKSwgMik7CgoJICAgICAgICBjYXNlICJ5eXl5IjoKCSAgICAgICAgICAvLyBsaWtlIDAwMTIKCSAgICAgICAgICByZXR1cm4gdXNlRGF0ZVRpbWVGb3JtYXR0ZXIgPyBzdHJpbmcoewoJICAgICAgICAgICAgeWVhcjogIm51bWVyaWMiCgkgICAgICAgICAgfSwgInllYXIiKSA6IF90aGlzLm51bShkdC55ZWFyLCA0KTsKCgkgICAgICAgIGNhc2UgInl5eXl5eSI6CgkgICAgICAgICAgLy8gbGlrZSAwMDAwMTIKCSAgICAgICAgICByZXR1cm4gdXNlRGF0ZVRpbWVGb3JtYXR0ZXIgPyBzdHJpbmcoewoJICAgICAgICAgICAgeWVhcjogIm51bWVyaWMiCgkgICAgICAgICAgfSwgInllYXIiKSA6IF90aGlzLm51bShkdC55ZWFyLCA2KTsKCSAgICAgICAgLy8gZXJhcwoKCSAgICAgICAgY2FzZSAiRyI6CgkgICAgICAgICAgLy8gbGlrZSBBRAoJICAgICAgICAgIHJldHVybiBlcmEoInNob3J0Iik7CgoJICAgICAgICBjYXNlICJHRyI6CgkgICAgICAgICAgLy8gbGlrZSBBbm5vIERvbWluaQoJICAgICAgICAgIHJldHVybiBlcmEoImxvbmciKTsKCgkgICAgICAgIGNhc2UgIkdHR0dHIjoKCSAgICAgICAgICByZXR1cm4gZXJhKCJuYXJyb3ciKTsKCgkgICAgICAgIGNhc2UgImtrIjoKCSAgICAgICAgICByZXR1cm4gX3RoaXMubnVtKGR0LndlZWtZZWFyLnRvU3RyaW5nKCkuc2xpY2UoLTIpLCAyKTsKCgkgICAgICAgIGNhc2UgImtra2siOgoJICAgICAgICAgIHJldHVybiBfdGhpcy5udW0oZHQud2Vla1llYXIsIDQpOwoKCSAgICAgICAgY2FzZSAiVyI6CgkgICAgICAgICAgcmV0dXJuIF90aGlzLm51bShkdC53ZWVrTnVtYmVyKTsKCgkgICAgICAgIGNhc2UgIldXIjoKCSAgICAgICAgICByZXR1cm4gX3RoaXMubnVtKGR0LndlZWtOdW1iZXIsIDIpOwoKCSAgICAgICAgY2FzZSAibyI6CgkgICAgICAgICAgcmV0dXJuIF90aGlzLm51bShkdC5vcmRpbmFsKTsKCgkgICAgICAgIGNhc2UgIm9vbyI6CgkgICAgICAgICAgcmV0dXJuIF90aGlzLm51bShkdC5vcmRpbmFsLCAzKTsKCgkgICAgICAgIGNhc2UgInEiOgoJICAgICAgICAgIC8vIGxpa2UgMQoJICAgICAgICAgIHJldHVybiBfdGhpcy5udW0oZHQucXVhcnRlcik7CgoJICAgICAgICBjYXNlICJxcSI6CgkgICAgICAgICAgLy8gbGlrZSAwMQoJICAgICAgICAgIHJldHVybiBfdGhpcy5udW0oZHQucXVhcnRlciwgMik7CgoJICAgICAgICBjYXNlICJYIjoKCSAgICAgICAgICByZXR1cm4gX3RoaXMubnVtKE1hdGguZmxvb3IoZHQudHMgLyAxMDAwKSk7CgoJICAgICAgICBjYXNlICJ4IjoKCSAgICAgICAgICByZXR1cm4gX3RoaXMubnVtKGR0LnRzKTsKCgkgICAgICAgIGRlZmF1bHQ6CgkgICAgICAgICAgcmV0dXJuIG1heWJlTWFjcm8odG9rZW4pOwoJICAgICAgfQoJICAgIH07CgoJICAgIHJldHVybiBzdHJpbmdpZnlUb2tlbnMoRm9ybWF0dGVyLnBhcnNlRm9ybWF0KGZtdCksIHRva2VuVG9TdHJpbmcpOwoJICB9OwoKCSAgX3Byb3RvLmZvcm1hdER1cmF0aW9uRnJvbVN0cmluZyA9IGZ1bmN0aW9uIGZvcm1hdER1cmF0aW9uRnJvbVN0cmluZyhkdXIsIGZtdCkgewoJICAgIHZhciBfdGhpczIgPSB0aGlzOwoKCSAgICB2YXIgdG9rZW5Ub0ZpZWxkID0gZnVuY3Rpb24gdG9rZW5Ub0ZpZWxkKHRva2VuKSB7CgkgICAgICBzd2l0Y2ggKHRva2VuWzBdKSB7CgkgICAgICAgIGNhc2UgIlMiOgoJICAgICAgICAgIHJldHVybiAibWlsbGlzZWNvbmQiOwoKCSAgICAgICAgY2FzZSAicyI6CgkgICAgICAgICAgcmV0dXJuICJzZWNvbmQiOwoKCSAgICAgICAgY2FzZSAibSI6CgkgICAgICAgICAgcmV0dXJuICJtaW51dGUiOwoKCSAgICAgICAgY2FzZSAiaCI6CgkgICAgICAgICAgcmV0dXJuICJob3VyIjsKCgkgICAgICAgIGNhc2UgImQiOgoJICAgICAgICAgIHJldHVybiAiZGF5IjsKCgkgICAgICAgIGNhc2UgInciOgoJICAgICAgICAgIHJldHVybiAid2VlayI7CgoJICAgICAgICBjYXNlICJNIjoKCSAgICAgICAgICByZXR1cm4gIm1vbnRoIjsKCgkgICAgICAgIGNhc2UgInkiOgoJICAgICAgICAgIHJldHVybiAieWVhciI7CgoJICAgICAgICBkZWZhdWx0OgoJICAgICAgICAgIHJldHVybiBudWxsOwoJICAgICAgfQoJICAgIH0sCgkgICAgICAgIHRva2VuVG9TdHJpbmcgPSBmdW5jdGlvbiB0b2tlblRvU3RyaW5nKGxpbGR1cikgewoJICAgICAgcmV0dXJuIGZ1bmN0aW9uICh0b2tlbikgewoJICAgICAgICB2YXIgb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ICAgY2FzZSAiTU0iOgoJICAgICAgICByZXR1cm4gaW50VW5pdCh0d28pOwoKCSAgICAgIGNhc2UgIk1NTSI6CgkgICAgICAgIHJldHVybiBvbmVPZihsb2MubW9udGhzKCJzaG9ydCIsIHRydWUsIGZhbHNlKSwgMSk7CgoJICAgICAgY2FzZSAiTU1NTSI6CgkgICAgICAgIHJldHVybiBvbmVPZihsb2MubW9udGhzKCJsb25nIiwgdHJ1ZSwgZmFsc2UpLCAxKTsKCgkgICAgICBjYXNlICJMIjoKCSAgICAgICAgcmV0dXJuIGludFVuaXQob25lT3JUd28pOwoKCSAgICAgIGNhc2UgIkxMIjoKCSAgICAgICAgcmV0dXJuIGludFVuaXQodHdvKTsKCgkgICAgICBjYXNlICJMTEwiOgoJICAgICAgICByZXR1cm4gb25lT2YobG9jLm1vbnRocygic2hvcnQiLCBmYWxzZSwgZmFsc2UpLCAxKTsKCgkgICAgICBjYXNlICJMTExMIjoKCSAgICAgICAgcmV0dXJuIG9uZU9mKGxvYy5tb250aHMoImxvbmciLCBmYWxzZSwgZmFsc2UpLCAxKTsKCSAgICAgIC8vIGRhdGVzCgoJICAgICAgY2FzZSAiZCI6CgkgICAgICAgIHJldHVybiBpbnRVbml0KG9uZU9yVHdvKTsKCgkgICAgICBjYXNlICJkZCI6CgkgICAgICAgIHJldHVybiBpbnRVbml0KHR3byk7CgkgICAgICAvLyBvcmRpbmFscwoKCSAgICAgIGNhc2UgIm8iOgoJICAgICAgICByZXR1cm4gaW50VW5pdChvbmVUb1RocmVlKTsKCgkgICAgICBjYXNlICJvb28iOgoJICAgICAgICByZXR1cm4gaW50VW5pdCh0aHJlZSk7CgkgICAgICAvLyB0aW1lCgoJICAgICAgY2FzZSAiSEgiOgoJICAgICAgICByZXR1cm4gaW50VW5pdCh0d28pOwoKCSAgICAgIGNhc2UgIkgiOgoJICAgICAgICByZXR1cm4gaW50VW5pdChvbmVPclR3byk7CgoJICAgICAgY2FzZSAiaGgiOgoJICAgICAgICByZXR1cm4gaW50VW5pdCh0d28pOwoKCSAgICAgIGNhc2UgImgiOgoJICAgICAgICByZXR1cm4gaW50VW5pdChvbmVPclR3byk7CgoJICAgICAgY2FzZSAibW0iOgoJICAgICAgICByZXR1cm4gaW50VW5pdCh0d28pOwoKCSAgICAgIGNhc2UgIm0iOgoJICAgICAgICByZXR1cm4gaW50VW5pdChvbmVPclR3byk7CgoJICAgICAgY2FzZSAicSI6CgkgICAgICAgIHJldHVybiBpbnRVbml0KG9uZU9yVHdvKTsKCgkgICAgICBjYXNlICJxcSI6CgkgICAgICAgIHJldHVybiBpbnRVbml0KHR3byk7CgoJICAgICAgY2FzZSAicyI6CgkgICAgICAgIHJldHVybiBpbnRVbml0KG9uZU9yVHdvKTsKCgkgICAgICBjYXNlICJzcyI6CgkgICAgICAgIHJldHVybiBpbnRVbml0KHR3byk7CgoJICAgICAgY2FzZSAiUyI6CgkgICAgICAgIHJldHVybiBpbnRVbml0KG9uZVRvVGhyZWUpOwoKCSAgICAgIGNhc2UgIlNTUyI6CgkgICAgICAgIHJldHVybiBpbnRVbml0KHRocmVlKTsKCgkgICAgICBjYXNlICJ1IjoKCSAgICAgICAgcmV0dXJuIHNpbXBsZShvbmVUb05pbmUpOwoKCSAgICAgIGNhc2UgInV1IjoKCSAgICAgICAgcmV0dXJuIHNpbXBsZShvbmVPclR3byk7CgoJICAgICAgY2FzZSAidXV1IjoKCSAgICAgICAgcmV0dXJuIGludFVuaXQob25lKTsKCSAgICAgIC8vIG1lcmlkaWVtCgoJICAgICAgY2FzZSAiYSI6CgkgICAgICAgIHJldHVybiBvbmVPZihsb2MubWVyaWRpZW1zKCksIDApOwoJICAgICAgLy8gd2Vla1llYXIgKGspCgoJICAgICAgY2FzZSAia2trayI6CgkgICAgICAgIHJldHVybiBpbnRVbml0KGZvdXIpOwoKCSAgICAgIGNhc2UgImtrIjoKCSAgICAgICAgcmV0dXJuIGludFVuaXQodHdvVG9Gb3VyLCB1bnRydW5jYXRlWWVhcik7CgkgICAgICAvLyB3ZWVrTnVtYmVyIChXKQoKCSAgICAgIGNhc2UgIlciOgoJICAgICAgICByZXR1cm4gaW50VW5pdChvbmVPclR3byk7CgoJICAgICAgY2FzZSAiV1ciOgoJICAgICAgICByZXR1cm4gaW50VW5pdCh0d28pOwoJICAgICAgLy8gd2Vla2RheXMKCgkgICAgICBjYXNlICJFIjoKCSAgICAgIGNhc2UgImMiOgoJICAgICAgICByZXR1cm4gaW50VW5pdChvbmUpOwoKCSAgICAgIGNhc2UgIkVFRSI6CgkgICAgICAgIHJldHVybiBvbmVPZihsb2Mud2Vla2RheXMoInNob3J0IiwgZmFsc2UsIGZhbHNlKSwgMSk7CgoJICAgICAgY2FzZSAiRUVFRSI6CgkgICAgICAgIHJldHVybiBvbmVPZihsb2Mud2Vla2RheXMoImxvbmciLCBmYWxzZSwgZmFsc2UpLCAxKTsKCgkgICAgICBjYXNlICJjY2MiOgoJICAgICAgICByZXR1cm4gb25lT2YobG9jLndlZWtkYXlzKCJzaG9ydCIsIHRydWUsIGZhbHNlKSwgMSk7CgoJICAgICAgY2FzZSAiY2NjYyI6CgkgICAgICAgIHJldHVybiBvbmVPZihsb2Mud2Vla2RheXMoImxvbmciLCB0cnVlLCBmYWxzZSksIDEpOwoJICAgICAgLy8gb2Zmc2V0L3pvbmUKCgkgICAgICBjYXNlICJaIjoKCSAgICAgIGNhc2UgIlpaIjoKCSAgICAgICAgcmV0dXJuIG9mZnNldChuZXcgUmVnRXhwKCIoWystXSIgKyBvbmVPclR3by5zb3VyY2UgKyAiKSg/OjooIiArIHR3by5zb3VyY2UgKyAiKSk/IiksIDIpOwoKCSAgICAgIGNhc2UgIlpaWiI6CgkgICAgICAgIHJldHVybiBvZmZzZXQobmV3IFJlZ0V4cCgiKFsrLV0iICsgb25lT3JUd28uc291cmNlICsgIikoIiArIHR3by5zb3VyY2UgKyAiKT8iKSwgMik7CgkgICAgICAvLyB3ZSBkb24ndCBzdXBwb3J0IFpaWlogKFBTVCkgb3IgWlp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2YXIgem9uZSA9IGNvbmZpZy56b25lIHx8IFNldHRpbmdzLmRlZmF1bHRab25lOwoJICAgIHZhciBpbnZhbGlkID0gY29uZmlnLmludmFsaWQgfHwgKE51bWJlci5pc05hTihjb25maWcudHMpID8gbmV3IEludmFsaWQoImludmFsaWQgaW5wdXQiKSA6IG51bGwpIHx8ICghem9uZS5pc1ZhbGlkID8gdW5zdXBwb3J0ZWRab25lKHpvbmUpIDogbnVsbCk7CgkgICAgLyoqCgkgICAgICogQGFjY2VzcyBwcml2YXRlCgkgICAgICovCgoJICAgIHRoaXMudHMgPSBpc1VuZGVmaW5lZChjb25maWcudHMpID8gU2V0dGluZ3Mubm93KCkgOiBjb25maWcudHM7CgkgICAgdmFyIGMgPSBudWxsLAoJICAgICAgICBvID0gbnVsbDsKCgkgICAgaWYgKCFpbnZhbGlkKSB7CgkgICAgICB2YXIgdW5jaGFuZ2VkID0gY29uZmlnLm9sZCAmJiBjb25maWcub2xkLnRzID09PSB0aGlzLnRzICYmIGNvbmZpZy5vbGQuem9uZS5lcXVhbHMoem9uZSk7CgoJICAgICAgaWYgKHVuY2hhbmdlZCkgewoJICAgICAgICB2YXIgX3JlZiA9IFtjb25maWcub2xkLmMsIGNvbmZpZy5vbGQub107CgkgICAgICAgIGMgPSBfcmVmWzBdOwoJICAgICAgICBvID0gX3JlZlsxXTsKCSAgICAgIH0gZWxzZSB7CgkgICAgICAgIHZhciBvdCA9IHpvbmUub2Zmc2V0KHRoaXMudHMpOwoJICAgICAgICBjID0gdHNUb09iaih0aGlzLnRzLCBvdCk7CgkgICAgICAgIGludmFsaWQgPSBOdW1iZXIuaXNOYU4oYy55ZWFyKSA/IG5ldyBJbnZhbGlkKCJpbnZhbGlkIGlucHV0IikgOiBudWxsOwoJICAgICAgICBjID0gaW52YWxpZCA/IG51bGwgOiBjOwoJICAgICAgICBvID0gaW52YWxpZCA/IG51bGwgOiBvdDsKCSAgICAgIH0KCSAgICB9CgkgICAgLyoqCgkgICAgICogQGFj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AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLy9+PiAyMDE3LTAxLTAxVDAwOjAwOjAwWgoJICAgKiBAZXhhbXBsZSBEYXRlVGltZS51dGMoMjAxNywgMykgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvL34+IDIwMTctMDMtMDFUMDA6MDA6MDBaCgkgICAqIEBleGFtcGxlIERhdGVUaW1lLnV0YygyMDE3LCAzLCAxMikgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vfj4gMjAxNy0wMy0xMlQwMDowMDowMFoKCSAgICogQGV4YW1wbGUgRGF0ZVRpbWUudXRjKDIwMTcsIDMsIDEyLCA1KSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLy9+PiAyMDE3LTAzLTEyVDA1OjAwOjAwWgoJICAgKiBAZXhhbXBsZSBEYXRlVGltZS51dGMoMjAxNywgMywgMTIsIDUsIDQ1KSAgICAgICAgICAgICAgICAgICAgICAgICAgICAvL34+IDIwMTctMDMtMTJUMDU6NDU6MDBaCgkgICAqIEBleGFtcGxlIERhdGVUaW1lLnV0YygyMDE3LCAzLCAxMiwgNSwgNDUsIHsgbG9jYWxlOiAiZnIiIH0pICAgICAgICAgIC8vfj4gMjAxNy0wMy0xMlQwNTo0NTowMFogd2l0aCBhIEZyZW5jaCBsb2NhbGUKCSAgICogQGV4YW1wbGUgRGF0ZVRpbWUudXRjKDIwMTcsIDMsIDEyLCA1LCA0NSwgMTApICAgICAgICAgICAgICAgICAgICAgICAgLy9+PiAyMDE3LTAzLTEyVDA1OjQ1OjEwWgoJICAgKiBAZXhhbXBsZSBEYXRlVGltZS51dGMoMjAxNywgMywgMTIsIDUsIDQ1LCAxMCwgNzY1LCB7IGxvY2FsZTogImZyIiB9KSAvL34+IDIwMTctMDMtMTJUMDU6NDU6MTAuNzY1WiB3aXRoIGEgRnJlbmNoIGxvY2FsZQoJICAgKiBAcmV0dXJuIHtEYXRlVGltZX0KCSAgIC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+IFsKCSAgICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vPT4gICB7IHR5cGU6ICdkYXknLCB2YWx1ZTogJzI1JyB9LAoJICAgKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLy89PiAgIHsgdHlwZTogJ2xpdGVyYWwnLCB2YWx1ZTogJy8nIH0sCgkgICAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLz0+ICAgeyB0eXBlOiAnbW9udGgnLCB2YWx1ZTogJzA1JyB9LAoJICAgKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLy89PiAgIHsgdHlwZTogJ2xpdGVyYWwnLCB2YWx1ZTogJy8nIH0sCgkgICAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLz0+ICAgeyB0eXBlOiAneWVhcicsIHZhbHVlOiAnMTk4MicgfQoJICAgKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLy89PiBdCgkgICAqLwoJICA7CgoJICBfcHJvdG8udG9Mb2NhbGVQYXJ0cyA9IGZ1bmN0aW9uIHRvTG9jYWxlUGFydHMob3B0cykgewoJICAgIGlmIChvcHRzID09PSB2b2lkIDApIHsKCSAgICAgIG9wdHMgPSB7fTsKCSAgICB9CgoJICAgIHJldHVybiB0aGlzLmlzVmFsaWQgPyBGb3JtYXR0ZXIuY3JlYXRlKHRoaXMubG9jLmNsb25lKG9wdHMpLCBvcHRzKS5mb3JtYXREYXRlVGltZVBhcnRzKHRoaXMpIDogW107CgkgIH0KCSAgLyoqCgkgICAqIFJldHVybnMgYW4gSVNPIDg2MDEtY29tcGxpYW50IHN0cmluZyByZXByZXNlbnRhdGlvbiBvZiB0aGlzIERhdGVUaW1lCgkgICAqIEBwYXJhbSB7T2JqZWN0fSBvcHRzIC0gb3B0aW9ucwoJICAgKiBAcGFyYW0ge2Jvb2xlYW59IFtvcHRzLnN1cHByZXNzTWlsbGlzZWNvbmRzPWZhbHNlXSAt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LVx1REUzQVx1REU1MFx1REU1MVx1REYwMC1cdURGMjBcdURGMkQtXHVERjM1XHVERjM3LVx1REY3Q1x1REY3RS1cdURGODRcdURGODYtXHVERjkzXHVERkEwLVx1REZDMVx1REZDNVx1REZDNlx1REZDOFx1REZDOVx1REZDRi1cdURGRDNcdURGRTAtXHVERkYwXHVERkY4LVx1REZGRl18XHVEREU2XHVEODNDW1x1RERFOC1cdURERUNcdURERUVcdURERjFcdURERjJcdURERjRcdURERjYtXHVEREZBXHVEREZDXHVEREZEXHVEREZGXXxcdURERTdcdUQ4M0NbXHVEREU2XHVEREU3XHVEREU5LVx1RERFRlx1RERGMS1cdURERjRcdURERjYtXHVEREY5XHVEREZCXHVEREZDXHVEREZFXHVEREZGXXxcdURERThcdUQ4M0NbXHVEREU2XHVEREU4XHVEREU5XHVEREVCLVx1RERFRVx1RERGMC1cdURERjVcdURERjdcdURERkEtXHVEREZGXXxcdURERTlcdUQ4M0NbXHVEREVBXHVEREVDXHVEREVGXHVEREYwXHVEREYyXHVEREY0XHVEREZGXXxcdURERUFcdUQ4M0NbXHVEREU2XHVEREU4XHVEREVBXHVEREVDXHVEREVEXHVEREY3LVx1RERGQV18XHVEREVCXHVEODNDW1x1RERFRS1cdURERjBcdURERjJcdURERjRcdURERjddfFx1RERFQ1x1RDgzQ1tcdURERTZcdURERTdcdURERTktXHVEREVFXHVEREYxLVx1RERGM1x1RERGNS1cdURERkFcdURERkNcdURERkVdfFx1RERFRFx1RDgzQ1tcdURERjBcdURERjJcdURERjNcdURERjdcdURERjlcdURERkFdfFx1RERFRVx1RDgzQ1tcdURERTgtXHVEREVBXHVEREYxLVx1RERGNFx1RERGNi1cdURERjldfFx1RERFRlx1RDgzQ1tcdURERUFcdURERjJcdURERjRcdURERjVdfFx1RERGMFx1RDgzQ1tcdURERUFcdURERUMtXHVEREVFXHVEREYyXHVEREYzXHVEREY1XHVEREY3XHVEREZDXHVEREZFXHVEREZGXXxcdURERjFcdUQ4M0NbXHVEREU2LVx1RERFOFx1RERFRVx1RERGMFx1RERGNy1cdURERkJcdURERkVdfFx1RERGMlx1RDgzQ1tcdURERTZcdURERTgtXHVEREVEXHVEREYwLVx1RERGRl18XHVEREYzXHVEODNDW1x1RERFNlx1RERFOFx1RERFQS1cdURERUNcdURERUVcdURERjFcdURERjRcdURERjVcdURERjdcdURERkFcdURERkZdfFx1RERGNFx1RDgzQ1x1RERGMnxcdURERjVcdUQ4M0NbXHVEREU2XHVEREVBLVx1RERFRFx1RERGMC1cdURERjNcdURERjctXHVEREY5XHVEREZDXHVEREZFXXxcdURERjZcdUQ4M0NcdURERTZ8XHVEREY3XHVEODNDW1x1RERFQVx1RERGNFx1RERGOFx1RERGQVx1RERGQ118XHVEREY4XHVEODNDW1x1RERFNi1cdURERUFcdURERUMtXHVEREY0XHVEREY3LVx1RERGOVx1RERGQlx1RERGRC1cdURERkZdfFx1RERGOVx1RDgzQ1tcdURERTZcdURERThcdURERTlcdURERUItXHVEREVEXHVEREVGLVx1RERGNFx1RERGN1x1RERGOVx1RERGQlx1RERGQ1x1RERGRl18XHVEREZBXHVEODNDW1x1RERFNlx1RERFQ1x1RERGMlx1RERGM1x1RERGOFx1RERGRVx1RERGRl18XHVEREZCXHVEODNDW1x1RERFNlx1RERFOFx1RERFQVx1RERFQ1x1RERFRVx1RERGM1x1RERGQV18XHVEREZDXHVEODNDW1x1RERFQlx1RERGOF18XHVEREZEXHVEODNDXHVEREYwfFx1RERGRVx1RDgzQ1tcdURERUFcdURERjldfFx1RERGRlx1RDgzQ1tcdURERTZcdURERjJcdURERkNdfFx1REZGM1x1RkUwRj8oPzpcdTIwMEQoPzpcdTI2QTdcdUZFMEY/fFx1RDgzQ1x1REYwOCkpP3xcdURGRjQoPzpcdTIwMERcdTI2MjBcdUZFMEY/fFx1REI0MFx1REM2N1x1REI0MFx1REM2Mlx1REI0MCg/Olx1REM2NVx1REI0MFx1REM2RVx1REI0MFx1REM2N3xcdURDNzNcdURCNDBcdURDNjNcdURCNDBcdURDNzR8XHVEQzc3XHVEQjQwXHVEQzZDXHVEQjQwXHVEQzczKVx1REI0MFx1REM3Rik/KXxcdUQ4M0QoPzpbXHVEQzNGXHVEQ0ZEXHVERDQ5XHVERDRBXHVERDZGXHVERDcwXHVERDczXHVERDc2LVx1REQ3OVx1REQ4N1x1REQ4QS1cdUREOERcdUREQTVcdUREQThcdUREQjFcdUREQjJcdUREQkNcdUREQzItXHVEREM0XHVEREQxLVx1REREM1x1REREQy1cdUREREVcdURERTFcdURERTNcdURERThcdURERUZcdURERjNcdURERkFcdURFQ0JcdURFQ0QtXHVERUNGXHVERUUwLVx1REVFNVx1REVFOVx1REVGMFx1REVGM11cdUZFMEY/fFtcdURDNDJcdURDNDNcdURDNDYtXHVEQzUwXHVEQzY2XHVEQzY3XHVEQzZCLVx1REM2RFx1REM3Mlx1REM3NC1cdURDNzZcdURDNzhcdURDN0NcdURDODNcdURDODVcdURDOEZcdURDOTFcdURDQUFcdUREN0FcdUREOTVcdUREOTZcdURFNENcdURFNEZcdURFQzBcdURFQ0NdKD86XHVEODNDW1x1REZGQi1cdURGRkZdKT98W1x1REM2RVx1REM3MFx1REM3MVx1REM3M1x1REM3N1x1REM4MVx1REM4Mlx1REM4Nlx1REM4N1x1REU0NS1cdURFNDdcdURFNEJcdURFNERcdURFNEVcdURFQTNcdURFQjQtXHVERUI2XSg/Olx1RDgzQ1tcdURGRkItXHVERkZGXSk/KD86XHUyMDBEW1x1MjY0MFx1MjY0Ml1cdUZFMEY/KT98W1x1REQ3NFx1REQ5MF0oPzpcdUZFMEZ8XHVEODNDW1x1REZGQi1cdURGRkZdKT98W1x1REMwMC1cdURDMDdcdURDMDktXHVEQzE0XHVEQzE2LVx1REMzQVx1REMzQy1cdURDM0VcdURDNDBcdURDNDRcdURDNDVcdURDNTEtXHVEQzY1XHVEQzZBXHVEQzc5LVx1REM3Qlx1REM3RC1cdURDODBcdURDODRcdURDODgtXHVEQzhFXHVEQzkwXHVEQzkyLVx1RENBOVx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VlOw0KCSAgICAgICAgICAgIGNhc2UgIm51bWJlciI6DQoJICAgICAgICAgICAgY2FzZSAiYm9vbGVhbiI6DQoJICAgICAgICAgICAgICAgIHJldHVybiAiIiArIHdyYXBwZWQudmFsdWU7DQoJICAgICAgICAgICAgY2FzZSAid2lkZ2V0IjoNCgkgICAgICAgICAgICAgICAgcmV0dXJuIHdyYXBwZWQudmFsdWUubWFya2Rvd24oKTsNCgkgICAgICAgICAgICBjYXNlICJsaW5rIjoNCgkgICAgICAgICAgICAgICAgcmV0dXJuIHdyYXBwZWQudmFsdWUubWFya2Rvd24oKTsNCgkgICAgICAgICAgICBjYXNlICJmdW5jdGlvbiI6DQoJICAgICAgICAgICAgICAgIHJldHVybiAiPGZ1bmN0aW9uPiI7DQoJICAgICAgICAgICAgY2FzZSAiYXJyYXkiOg0KCSAgICAgICAgICAgICAgICBsZXQgcmVzdWx0ID0gIiI7DQoJICAgICAgICAgICAgICAgIGlmIChyZWN1cnNpdmUpDQoJICAgICAgICAgICAgICAgICAgICByZXN1bHQgKz0gIlsiOw0KCSAgICAgICAgICAgICAgICByZXN1bHQgKz0gd3JhcHBlZC52YWx1ZS5tYXAoZiA9PiB0b1N0cmluZyhmLCBzZXR0aW5nLCB0cnVlKSkuam9pbigiLCAiKTsNCgkgICAgICAgICAgICAgICAgaWYgKHJlY3Vyc2l2ZSkNCgkgICAgICAgICAgICAgICAgICAgIHJlc3VsdCArPSAiXSI7DQoJICAgICAgICAgICAgICAgIHJldHVybiByZXN1bHQ7DQoJICAgICAgICAgICAgY2FzZSAib2JqZWN0IjoNCgkgICAgICAgICAgICAgICAgcmV0dXJuICgieyAiICsNCgkgICAgICAgICAgICAgICAgICAgIE9iamVjdC5lbnRyaWVzKHdyYXBwZWQudmFsdWUpDQoJICAgICAgICAgICAgICAgICAgICAgICAgLm1hcChlID0+IGVbMF0gKyAiOiAiICsgdG9TdHJpbmcoZVsxXSwgc2V0dGluZywgdHJ1ZSkpDQoJICAgICAgICAgICAgICAgICAgICAgICAgLmpvaW4oIiwgIikgKw0KCSAgICAgICAgICAgICAgICAgICAgIiB9Iik7DQoJICAgICAgICAgICAgY2FzZSAiZGF0ZSI6DQoJICAgICAgICAgICAgICAgIGlmICh3cmFwcGVkLnZhbHVlLnNlY29uZCA9PSAwICYmIHdyYXBwZWQudmFsdWUuaG91ciA9PSAwICYmIHdyYXBwZWQudmFsdWUubWludXRlID09IDApIHsNCgkgICAgICAgICAgICAgICAgICAgIHJldHVybiB3cmFwcGVkLnZhbHVlLnRvRm9ybWF0KHNldHRpbmcuZGVmYXVsdERhdGVGb3JtYXQpOw0KCSAgICAgICAgICAgICAgICB9DQoJICAgICAgICAgICAgICAgIHJldHVybiB3cmFwcGVkLnZhbHVlLnRvRm9ybWF0KHNldHRpbmcuZGVmYXVsdERhdGVUaW1lRm9ybWF0KTsNCgkgICAgICAgICAgICBjYXNlICJkdXJhdGlvbiI6DQoJICAgICAgICAgICAgICAgIHJldHVybiByZW5kZXJNaW5pbWFsRHVyYXRpb24od3JhcHBlZC52YWx1ZSk7DQoJICAgICAgICB9DQoJICAgIH0NCgkgICAgVmFsdWVzLnRvU3RyaW5nID0gdG9TdHJpbmc7DQoJICAgIC8qKiBXcmFwIGEgbGl0ZXJhbCB2YWx1ZSBzbyB5b3UgY2FuIHN3aXRjaCBvbiBpdCBlYXNpbHkuICovDQoJICAgIGZ1bmN0aW9uIHdyYXBWYWx1ZSh2YWwpIHsNCgkgICAgICAgIGlmIChpc051bGwodmFsKSkNCgkgICAgICAgICAgICByZXR1cm4geyB0eXBlOiAibnVsbCIsIHZhbHVlOiB2YWwgfTsNCgkgICAgICAgIGVsc2UgaWYgKGlzTnVtYmVyKHZhbCkpDQoJICAgICAgICAgICAgcmV0dXJuIHsgdHlwZTogIm51bWJlciIsIHZhbHVlOiB2YWwgfTsNCgkgICAgICAgIGVsc2UgaWYgKGlzU3RyaW5nKHZhbCkpDQoJICAgICAgICAgICAgcmV0dXJuIHsgdHlwZTogInN0cmluZ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cGUpOw0KCSAgICAgICAgaWYgKHdyYXAxLnZhbHVlID09PSB3cmFwMi52YWx1ZSkNCgkgICAgICAgICAgICByZXR1cm4gMDsNCgkgICAgICAgIHN3aXRjaCAod3JhcDEudHlwZSkgew0KCSAgICAgICAgICAgIGNhc2UgInN0cmluZyI6DQoJICAgICAgICAgICAgICAgIHJldHVybiB3cmFwMS52YWx1ZS5sb2NhbGVDb21wYXJlKHdyYXAyLnZhbHVlKTsNCgkgICAgICAgICAgICBjYXNlICJudW1iZXIiOg0KCSAgICAgICAgICAgICAgICBpZiAod3JhcDEudmFsdWUgPCB3cmFwMi52YWx1ZSkNCgkgICAgICAgICAgICAgICAgICAgIHJldHVybiAtMTsNCgkgICAgICAgICAgICAgICAgZWxzZSBpZiAod3JhcDEudmFsdWUgPT0gd3JhcDIudmFsdWUpDQoJICAgICAgICAgICAgICAgICAgICByZXR1cm4gMDsNCgkgICAgICAgICAgICAgICAgcmV0dXJuIDE7DQoJICAgICAgICAgICAgY2FzZSAibnVsbCI6DQoJICAgICAgICAgICAgICAgIHJldHVybiAwOw0KCSAgICAgICAgICAgIGNhc2UgImJvb2xlYW4iOg0KCSAgICAgICAgICAgICAgICBpZiAod3JhcDEudmFsdWUgPT0gd3JhcDIudmFsdWUpDQoJICAgICAgICAgICAgICAgICAgICByZXR1cm4gMDsNCgkgICAgICAgICAgICAgICAgZWxzZQ0KCSAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHdyYXAxLnZhbHVlID8gMSA6IC0xOw0KCSAgICAgICAgICAgIGNhc2UgImxpbmsiOg0KCSAgICAgICAgICAgICAgICBsZXQgbGluazEgPSB3cmFwMS52YWx1ZTsNCgkgICAgICAgICAgICAgICAgbGV0IGxpbmsyID0gd3JhcDIudmFsdWU7DQoJICAgICAgICAgICAgICAgIGxldCBub3JtYWxpemUgPSBsaW5rTm9ybWFsaXplciAhPT0gbnVsbCAmJiBsaW5rTm9ybWFsaXplciAhPT0gdm9pZCAwID8gbGlua05vcm1hbGl6ZXIgOiAoKHgpID0+IHgpOw0KCSAgICAgICAgICAgICAgICAvLyBXZSBjYW4ndCBjb21wYXJlIGJ5IGZpbGUgbmFtZSBvciBkaXNwbGF5LCBzaW5jZSB0aGF0IHdvdWxkIGJyZWFrIGxpbmsgZXF1YWxpdHkuIENvbXBhcmUgYnkgcGF0aC4NCgkgICAgICAgICAgICAgICAgbGV0IHBhdGhDb21wYXJlID0gbm9ybWFsaXplKGxpbmsxLnBhdGgpLmxvY2FsZUNvbXBhcmUobm9ybWFsaXplKGxpbmsyLnBhdGgpKTsNCgkgICAgICAgICAgICAgICAgaWYgKHBhdGhDb21wYXJlICE9IDApDQoJICAgICAgICAgICAgICAgICAgICByZXR1cm4gcGF0aENvbXBhcmU7DQoJICAgICAgICAgICAgICAgIC8vIFRoZW4gY29tcGFyZSBieSB0eXBlLg0KCSAgICAgICAgICAgICAgICBsZXQgdHlwZUNvbXBhcmUgPSBsaW5rMS50eXBlLmxvY2FsZUNvbXBhcmUobGluazIudHlwZSk7DQoJICAgICAgICAgICAgICAgIGlmICh0eXBlQ29tcGFyZSAhPSAwKQ0KCSAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHR5cGVDb21wYXJlOw0KCSAgICAgICAgICAgICAgICAvLyBUaGVuIGNvbXBhcmUgYnkgc3VicGF0aCBleGlzdGVuY2UuDQoJICAgICAgICAgICAgICAgIGlmIChsaW5rMS5zdWJwYXRoICYmICFsaW5rMi5zdWJwYXRoKQ0KCSAgICAgICAgICAgICAgICAgICAgcmV0dXJuIDE7DQoJICAgICAgICAgICAgICAgIGlmICghbGluazEuc3VicGF0aCAmJiBsaW5rMi5zdWJwYXRoKQ0KCSAgICAgICAgICAgICAgICAgICAgcmV0dXJuIC0xOw0KCSAgICAgICAgICAgICAgICBpZiAoIWxpbmsxLnN1YnBhdGggJiYgIWxpbmsyLnN1YnBhdGgpDQoJICAgICAgICAgICAgICAgICAgICByZXR1cm4gMDsNCgkgICAgICAgICAgICAgICAgLy8gU2luY2UgYm90aCBoYXZlIGEgc3VicGF0aCwgY29tcGFyZSBieSBzdWJwYXRoLg0KCSAgICAgICAgICAgICAgICByZXR1cm4gKChfYSA9IGxpbmsxLnN1YnBhdGgpICE9PSBudWxsICYmIF9hICE9PSB2b2lkIDAgPyBfYSA6ICIiKS5sb2NhbGVDb21wYXJlKChfYiA9IGxpbmsyLnN1YnBhdGgpICE9PSBudWxsICYmIF9iICE9PSB2b2lkIDAgPyBfYiA6ICIiKTsNCgkgICAgICAgICAgICBjYXNlICJkYXRlIjoNCgkgICAgICAgICAgICAgICAgcmV0dXJuIHdyYXAxLnZhbHVlIDwgd3JhcDIudmFsdWUNCgkgICAgICAgICAgICAgICAgICAgID8gLTENCgkgICAgICAgICAgICAgICAgICAgIDogd3JhcDEudmFsdWUuZXF1YWxzKHdyYXAyLnZhbHVlKQ0KCSAgICAgICAgICAgICAgICAgICAgICAgID8gMA0KCSAgICAgICAgICAgICAgICAgICAgICAgIDogMTsNCgkgICAgICAgICAgICBjYXNlICJkdXJhdGlvbiI6DQoJICAgICAgICAgICAgICAgIHJldHVybiB3cmFwMS52YWx1ZSA8IHdyYXAyLnZhbHVlDQoJICAgICAgICAgICAgICAgICAgICA/IC0xDQoJICAgICAgICAgICAgICAgICAgICA6IHdyYXAxLnZhbHVlLmVxdWFscyh3cmFwMi52YWx1ZSkNCgkgICAgICAgICAgICAgICAgICAgICAgICA/IDANCgkgICAgICAgICAgICAgICAgICAgICAgICA6IDE7DQoJICAgICAgICAgICAgY2FzZSAiYXJyYXkiOg0KCSAgICAgICAgICAgICAgICBsZXQgZjEgPSB3cmFwMS52YWx1ZTsNCgkgICAgICAgICAgICAgICAgbGV0IGYyID0gd3JhcDIudmFsdWU7DQoJICAgICAgICAgICAgICAgIGZvciAobGV0IGluZGV4ID0gMDsgaW5kZXggPCBNYXRoLm1pbihmMS5sZW5ndGgsIGYyLmxlbmd0aCk7IGluZGV4KyspIHsNCgkgICAgICAgICAgICAgICAgICAgIGxldCBjb21wID0gY29tcGFyZVZhbHVlKGYxW2luZGV4XSwgZjJbaW5kZXhdKTsNCgkgICAgICAgICAgICAgICAgICAgIGlmIChjb21wICE9IDApDQoJICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGNvbXA7DQoJICAgICAgICAgICAgICAgIH0NCgkgICAgICAgICAgICAgICAgcmV0dXJuIGYxLmxlbmd0aCAtIGYyLmxlbmd0aDsNCgkgICAgICAgICAgICBjYXNlICJvYmplY3QiOg0KCSAgICAgICAgICAgICAgICBsZXQgbzEgPSB3cmFwMS52YWx1ZTsNCgkgICAgICAgICAgICAgICAgbGV0IG8yID0gd3JhcDIudmFsdWU7DQoJICAgICAgICAgICAgICAgIGxldCBrMSA9IEFycmF5LmZyb20oT2JqZWN0LmtleXMobzEpKTsNCgkgICAgICAgICAgICAgICAgbGV0IGsyID0gQXJyYXkuZnJvbShPYmplY3Qua2V5cyhvMikpOw0KCSAgICAgICAgICAgICAgICBrMS5zb3J0KCk7DQoJICAgICAgICAgICAgICAgIGsyLnNvcnQoKTsNCgkgICAgICAgICAgICAgICAgbGV0IGtleUNvbXBhcmUgPSBjb21wYXJlVmFsdWUoazEsIGsyKTsNCgkgICAgICAgICAgICAgICAgaWYgKGtleUNvbXBhcmUgIT0gMCkNCgkgICAgICAgICAgICAgICAgICAgIHJldHVybiBrZXlDb21wYXJlOw0KCSAgICAgICAgICAgICAgICBmb3IgKGxldCBrZXkgb2YgazEpIHsNCgkgICAgICAgICAgICAgICAgICAgIGxldCBjb21wID0gY29tcGFyZVZhbHVlKG8xW2tleV0sIG8yW2tleV0pOw0KCSAgICAgICAgICAgICAgICAgICAgaWYgKGNvbXAgIT0gMCkNCgkgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gY29tcDsNCgkgICAgICAgICAgICAgICAgfQ0KCSAgICAgICAgICAgICAgICByZXR1cm4gMDsNCgkgICAgICAgICAgICBjYXNlICJ3aWRnZXQiOg0KCSAgICAgICAgICAgICAgICByZXR1cm4gMD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BwZWQudmFsdWU7DQoJICAgICAgICAgICAgY2FzZSAibGluayI6DQoJICAgICAgICAgICAgICAgIHJldHVybiAhIXdyYXBwZWQudmFsdWUucGF0aDsNCgkgICAgICAgICAgICBjYXNlICJkYXRlIjoNCgkgICAgICAgICAgICAgICAgcmV0dXJuIHdyYXBwZWQudmFsdWUudG9NaWxsaXMoKSAhPSAwOw0KCSAgICAgICAgICAgIGNhc2UgImR1cmF0aW9uIjoNCgkgICAgICAgICAgICAgICAgcmV0dXJuIHdyYXBwZWQudmFsdWUuYXMoInNlY29uZHMiKSAhPSAwOw0KCSAgICAgICAgICAgIGNhc2UgIm9iamVjdCI6DQoJICAgICAgICAgICAgICAgIHJldHVybiBPYmplY3Qua2V5cyh3cmFwcGVkLnZhbHVlKS5sZW5ndGggPiAwOw0KCSAgICAgICAgICAgIGNhc2UgImFycmF5IjoNCgkgICAgICAgICAgICAgICAgcmV0dXJuIHdyYXBwZWQudmFsdWUubGVuZ3RoID4gMDsNCgkgICAgICAgICAgICBjYXNlICJudWxsIjoNCgkgICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlOw0KCSAgICAgICAgICAgIGNhc2UgIndpZGdldCI6DQoJICAgICAgICAgICAgICAgIHJldHVybiB0cnVlOw0KCSAgICAgICAgICAgIGNhc2UgImZ1bmN0aW9uIjoNCgkgICAgICAgICAgICAgICAgcmV0dXJuIHRydWU7DQoJICAgICAgICB9DQoJICAgIH0NCgkgICAgVmFsdWVzLmlzVHJ1dGh5ID0gaXNUcnV0aHk7DQoJICAgIC8qKiBEZWVwIGNvcHkgYSBmaWVsZC4gKi8NCgkgICAgZnVuY3Rpb24gZGVlcENvcHkoZmllbGQpIHsNCgkgICAgICAgIGlmIChmaWVsZCA9PT0gbnVsbCB8fCBmaWVsZCA9PT0gdW5kZWZpbmVkKQ0KCSAgICAgICAgICAgIHJldHVybiBmaWVsZDsNCgkgICAgICAgIGlmIChWYWx1ZXMuaXNBcnJheShmaWVsZCkpIHsNCgkgICAg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gICAgICAvLyBIZWFkZXJzIG5lZWQgdG8gYmUgbm9ybWFsaXplZCB0byBhbHBoYS1udW1lcmljICYgd2l0aCBleHRyYSBzcGFjaW5nIHJlbW92ZWQuDQoJICAgICAgICByZXR1cm4gbmV3IExpbmsoew0KCSAgICAgICAgICAgIHBhdGgsDQoJICAgICAgICAgICAgZW1iZWQsDQoJICAgICAgICAgICAgZGlzcGxheSwNCgkgICAgICAgICAgICBzdWJwYXRoOiBub3JtYWxpemVIZWFkZXJGb3JMaW5rKGhlYWRlciksDQoJICAgICAgICAgICAgdHlwZTogImhlYWRlciIsDQoJICAgICAgICB9KTsNCgkgICAgfQ0KCSAgICAvKiogQ3JlYXRlIGEgbGluayB0byBhIHNwZWNpZmljIGZpbGUgYW5kIGJsb2NrIGluIHRoYXQgZmlsZS4gKi8NCgkgICAgc3RhdGljIGJsb2NrKHBhdGgsIGJsb2NrSWQsIGVtYmVkLCBkaXNwbGF5KSB7DQoJICAgICAgICByZXR1cm4gbmV3IExpbmsoew0KCSAgICAgICAgICAgIHBhdGgsDQoJICAgICAgICAgICAgZW1iZWQsDQoJICAgICAgICAgICAgZGlzcGxheSwNCgkgICAgICAgICAgICBzdWJwYXRoOiBibG9ja0lkLA0KCSAgICAgICAgICAgIHR5cGU6ICJibG9jayIsDQoJICAgICAgICB9KTsNCgkgICAgfQ0KCSAgICBzdGF0aWMgZnJvbU9iamVjdChvYmplY3QpIHsNCgkgICAgICAgIHJldHVybiBuZXcgTGluayhvYmplY3QpOw0KCSAgICB9DQoJICAgIC8qKiBDaGVja3MgZm9yIGxpbmsgZXF1YWxpdHkgKGkuZS4sIHRoYXQgdGhlIGxpbmtzIGFyZSBwb2ludGluZyB0byB0aGUgc2FtZSBleGFjdCBsb2NhdGlvbikuICovDQoJICAgIGVxdWFscyhvdGhlcikgew0KCSAgICAgICAgaWYgKG90aGVyID09IHVuZGVmaW5lZCB8fCBvdGhlciA9PSBudWxsKQ0KCSAgICAgICAgICAgIHJldHVybiBmYW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0IGEgZmlsZSBsaW5rIGludG8gYSBsaW5rIHRvIGEgc3BlY2lmaWMgaGVhZGVyLiAqLw0KCSAgICB3aXRoSGVhZGVyKGhlYWRlcikgew0KCSAgICAgICAgcmV0dXJuIExpbmsuaGVhZGVyKHRoaXMucGF0aCwgaGVhZGVyLCB0aGlzLmVtYmVkLCB0aGlzLmRpc3BsYXkpOw0KCSAgICB9DQoJICAgIC8qKiBDb252ZXJ0IGFueSBsaW5rIGludG8gYSBsaW5rIHRvIGl0cyBmaWxlLiAqLw0KCSAgICB0b0ZpbGUoKSB7DQoJICAgICAgICByZXR1cm4gTGluay5maWxlKHRoaXMucGF0aCwgdGhpcy5lbWJlZCwgdGhpcy5kaXNwbGF5KTsNCgkgICAgfQ0KCSAgICAvKiogQ29udmVydCB0aGlzIGxpbmsgaW50byBhbiBlbWJlZGRlZCBsaW5rLiAqLw0KCSAgICB0b0VtYmVkKCkgew0KCSAgICAgICAgaWYgKHRoaXMuZW1iZWQpIHsNCgkgICAgICAgICAgICByZXR1cm4gdGhpczsNCgkgICAgICAgIH0NCgkgICAgICAgIGVsc2Ugew0KCSAgICAgICAgICAgIGxldCBsaW5rID0gbmV3IExpbmsodGhpcyk7DQoJICAgICAgICAgICAgbGluay5lbWJlZCA9IHRydWU7DQoJICAgICAgICAgICAgcmV0dXJuIGxpbms7DQoJICAgICAgICB9DQoJICAgIH0NCgkgICAgLyoqIENvbnZlcnQgdGhpcyBsaW5rIGludG8gYSBub24tZW1iZWRkZWQgbGluay4gKi8NCgkgICAgZnJvbUVtYmVkKCkgew0KCSAgICAgICAgaWYgKCF0aGlzLmVtYmVkKSB7DQoJICAgICAgICAgICAgcmV0dXJuIHRoaXM7DQoJICAgICAgICB9DQoJICAgICAgICBlbHNlIHsNCgkgICAgICAgICAgICBsZXQgbGluayA9IG5ldyBMaW5rKHRoaXMpOw0KCSAgICAgICAgICAgIGxpbmsuZW1iZWQgPSBmYWxzZTsNCgkgICAgICAgICAgICByZXR1cm4gbGluaz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b2t1cHMuICAqLw0KCSAgICBzZXJpYWxpemUoaW5kZXgsIGNhY2hlKSB7DQoJICAgICAgICAvLyBDb252ZXJ0IGxpc3QgaXRlbXMgdmlhIHRoZSBjYW5vbmljYWxpemF0aW9uIGNhY2hlLg0KCSAgICAgICAgbGV0IHJlYWxDYWNoZSA9IGNhY2hlICE9PSBudWxsICYmIGNhY2hlICE9PSB2b2lkIDAgPyBjYWNoZSA6IG5ldyBMaXN0U2VyaWFsaXphdGlvbkNhY2hlKHRoaXMubGlzdHMpOw0KCSAgICAgICAgbGV0IHJlc3VsdCA9IHsNCgkgICAgICAgICAgICBmaWxlOiB7DQoJICAgICAgICAgICAgICAgIHBhdGg6IHRoaXMucGF0aCwNCgkgICAgICAgICAgICAgICAgZm9sZGVyOiB0aGlzLmZvbGRlcigpLA0KCSAgICAgICAgICAgICAgICBuYW1lOiB0aGlzLm5hbWUoKSwNCgkgICAgICAgICAgICAgICAgbGluazogTGluay5maWxlKHRoaXMucGF0aCksDQoJICAgICAgICAgICAgICAgIG91dGxpbmtzOiB0aGlzLmZpbGVMaW5rcygpLA0KCSAgICAgICAgICAgICAgICBpbmxpbmtzOiBBcnJheS5mcm9tKGluZGV4LmxpbmtzLmdldEludmVyc2UodGhpcy5wYXRoKSkubWFwKGwgPT4gTGluay5maWxlKGwpKSwNCgkgICAgICAgICAgICAgICAgZXRhZ3M6IEFycmF5LmZyb20odGhpcy50YWdzKSwNCgkgICAgICAgICAgICAgICAgdGFnczogQXJyYXkuZnJvbSh0aGlzLmZ1bGxUYWdzKCkpLA0KCSAgICAgICAgICAgICAgICBhbGlhc2VzOiBBcnJheS5mcm9tKHRoaXMuYWxpYXNlcyksDQoJICAgICAgICAgICAgICAgIGxpc3RzOiB0aGlzLmxpc3RzLm1hcChsID0+IHJlYWxDYWNoZS5nZXQobC5saW5lKSksDQoJICAgICAgICAgICAgICAgIHRhc2tzOiB0aGlzLmxpc3RzLmZpbHRlcihsID0+ICEhbC50YXNrKS5tYXAobCA9PiByZWFsQ2FjaGUuZ2V0KGwubGluZSkpLA0KCSAgICAgICAgICAgICAgICBjdGltZTogdGhpcy5jdGltZSwNCgkgICAgICAgICAgICAgICAgY2RheTogc3RyaXBUaW1lKHRoaXMuY3RpbWUpLA0KCSAgICAgICAgICAgICAgICBtdGltZTogdGhpcy5tdGltZSwNCgkgICAgICAgICAgICAgICAgbWRheTogc3RyaXBUaW1lKHRoaXMubXRpbWUpLA0KCSAgICAgICAgICAgICAgICBzaXplOiB0aGlzLnNpemUsDQoJICAgICAgICAgICAgICAgIHN0YXJyZWQ6IGluZGV4LnN0YXJyZWQuc3RhcnJlZCh0aGlzLnBhdGgpLA0KCSAgICAgICAgICAgICAgICBmcm9udG1hdHRlcjogVmFsdWVzLmRlZXBDb3B5KHRoaXMuZnJvbnRtYXR0ZXIpLA0KCSAgICAgICAgICAgICAgICBleHQ6IHRoaXMuZXh0ZW5zaW9uKCksDQoJICAgICAgICAgICAgfSwNCgkgICAgICAgIH07DQoJICAgICAgICAvLyBBZGQgdGhlIGN1cnJlbnQgZGF5IGlmIHByZXNlbnQuDQoJICAgICAgICBpZiAodGhpcy5kYXkpDQoJICAgICAgICAgICAgcmVzdWx0LmZpbGUuZGF5ID0gdGhpcy5kYXk7DQoJICAgICAgICAvLyBUaGVuIGFwcGVuZCB0aGUgY29tcHV0ZWQgZmllbGRzLg0KCSAgICAgICAgZm9yIChsZXQgW2tleSwgdmFsdWVdIG9mIHRoaXMuZmllbGRzLmVudHJpZXMoKSkgew0KCSAgICAgICAgICAgIGlmIChrZXkgaW4gcmVzdWx0KQ0KCSAgICAgICAgICAgICAgICBjb250aW51ZTsgLy8gRG9uJ3QgYWxsb3cgZmllbGRzIHRvIG92ZXJyaWRlIGV4aXN0aW5nIGtleXMuDQoJICAgICAgICAgICAgcmVzdWx0W2tleV0gPSB2YWx1ZTsNCgkgICAgICAgIH0NCgkgICAgICAgIHJldHVybiByZXN1bHQ7DQoJICAgIH0NCgl9DQoJLyoqIEEgb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cm92aWRlZCBjYWNoZS4gKi8NCgkgICAgc2VyaWFsaXplKGNhY2hlKSB7DQoJICAgICAgICAvLyBNYXAgY2hpbGRyZW4gdG8gdGhlaXIgc2VyaWFsaXplZC9kZS1kdXBsaWNhdGVkIGVxdWl2YWxlbnRzIHJpZ2h0IGF3YXkuDQoJICAgICAgICBsZXQgY2hpbGRyZW4gPSB0aGlzLmNoaWxkcmVuLm1hcChsID0+IGNhY2hlLmdldChsKSkuZmlsdGVyKChsKSA9PiBsICE9PSB1bmRlZmluZWQpOw0KCSAgICAgICAgbGV0IHJlc3VsdCA9IHsNCgkgICAgICAgICAgICBzeW1ib2w6IHRoaXMuc3ltYm9sLA0KCSAgICAgICAgICAgIGxpbms6IHRoaXMubGluaywNCgkgICAgICAgICAgICBzZWN0aW9uOiB0aGlzLnNlY3Rpb24sDQoJICAgICAgICAgICAgdGV4dDogdGhpcy50ZXh0LA0KCSAgICAgICAgICAgIHRhZ3M6IEFycmF5LmZyb20odGhpcy50YWdzKSwNCgkgICAgICAgICAgICBsaW5lOiB0aGlzLmxpbmUsDQoJICAgICAgICAgICAgbGluZUNvdW50OiB0aGlzLmxpbmVDb3VudCwNCgkgICAgICAgICAgICBsaXN0OiB0aGlzLmxpc3QsDQoJICAgICAgICAgICAgb3V0bGlua3M6IEFycmF5LmZyb20odGhpcy5saW5rcyksDQoJICAgICAgICAgICAgcGF0aDogdGhpcy5saW5rLnBhdGgsDQoJICAgICAgICAgICAgY2hpbGRyZW46IGNoaWxkcmVuLA0KCSAgICAgICAgICAgIHRhc2s6ICEhdGhpcy50YXNrLA0KCSAgICAgICAgICAgIGFubm90YXRlZDogdGhpcy5maWVsZHMuc2l6ZSA+IDAsDQoJICAgICAgICAgICAgcG9zaXRpb246IFZhbHVlcy5kZWVwQ29weSh0aGlzLnBvc2l0aW9uKSwNCgkgICAgICAgICAgICBzdWJ0YXNrczogY2hpbGRyZW4sDQoJICAgICAgICAgICAgcmVhbDogISF0aGlzLnRhc2ssDQoJ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Wcuc3RhcnRzV2l0aCgiIyIpKQ0KCSAgICAgICAgICAgICAgICB0YWcgPSAiIyIgKyB0YWc7DQoJICAgICAgICAgICAgdGFncy5hZGQodGFnKTsNCgkgICAgICAgIH0NCgkgICAgICAgIGZvciAobGV0IGFsaWFzIG9mIGV4dHJhY3RBbGlhc2VzKG1ldGFkYXRhLmZyb250bWF0dGVyKSB8fCBbXSkNCgkgICAgICAgICAgICBhbGlhc2VzLmFkZChhbGlhcyk7DQoJICAgICAgICBsZXQgZnJvbnRGaWVsZHMgPSBwYXJzZUZyb250bWF0dGVyKG1ldGFkYXRhLmZyb250bWF0dGVyKTsNCgkgICAgICAgIGZvciAobGV0IFtrZXksIHZhbHVlXSBvZiBPYmplY3QuZW50cmllcyhmcm9udEZpZWxkcykpIHsNCgkgICAgICAgICAgICBpZiAoa2V5ID09ICJwb3NpdGlvbiIpDQoJICAgICAgICAgICAgICAgIGNvbnRpbnVlOw0KCSAgICAgICAgICAgIGFkZElubGluZUZpZWxkKGtleSwgdmFsdWUsIGZpZWxkcyk7DQoJICAgICAgICB9DQoJICAgIH0NCgkgICAgLy8gTGlua3MgaW4gbWV0YWRhdGEuDQoJICAgIGNvbnN0IGxpbmtzQnlMaW5lID0ge307DQoJICAgIGZvciAobGV0IHJhd0xpbmsgb2YgbWV0YWRhdGEubGlua3MgfHwgW10pIHsNCgkgICAgICAgIGNvbnN0IGxpbmsgPSBMaW5rLmluZmVyKHJhd0xpbmsubGluaywgZmFsc2UsIHJhd0xpbmsuZGlzcGxheVRleHQpOw0KCSAgICAgICAgY29uc3QgbGluZSA9IHJhd0xpbmsucG9zaXRpb24uc3RhcnQubGluZTsNCgkgICAgICAgIGxpbmtzLnB1c2gobGluayk7DQoJICAgICAgICBpZiAoIShsaW5lIGluIGxpbmtzQnlMaW5lKSkNCgkgICAgICAgICAgICBsaW5rc0J5TGluZVtsaW5lXSA9IFtsaW5rXTsNCgkgICAgICAgIGVsc2UNCgkgICAgICAgICAgICBsaW5rc0J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GluZSA9PSBudWxsKQ0KCSAgICAgICAgICAgICAgICBjb250aW51ZTsNCgkgICAgICAgICAgICBpZiAobGlzdExpbmVzVG9Ta2lwLmhhcyhsaW5lbm8pKQ0KCSAgICAgICAgICAgICAgICBjb250aW51ZTsNCgkgICAgICAgICAgICAvLyBGYXN0IGJhaWwtb3V0IGZvciBsaW5lcyB0aGF0IGFyZSB0b28gbG9uZyBvciBkbyBub3QgY29udGFpbiAnOjonLg0KCSAgICAgICAgICAgIGlmIChsaW5lLmxlbmd0aCA+IDIwNDggfHwgIWxpbmUuaW5jbHVkZXMoIjo6IikpDQoJICAgICAgICAgICAgICAgIGNvbnRpbnVlOw0KCSAgICAgICAgICAgIGxpbmUgPSBsaW5lLnRyaW0oKTsNCgkgICAgICAgICAgICBsZXQgaW5saW5lRmllbGRzID0gZXh0cmFjdElubGluZUZpZWxkcyhsaW5lKTsNCgkgICAgICAgICAgICBpZiAoaW5saW5lRmllbGRzLmxlbmd0aCA+IDApIHsNCgkgICAgICAgICAgICAgICAgZm9yIChsZXQgaWZpZWxkIG9mIGlubGluZUZpZWxkcykNCgkgICAgICAgICAgICAgICAgICAgIGFkZFJhd0lubGluZUZpZWxkKGlmaWVsZCwgZmllbGRzKTsNCgkgICAgICAgICAgICB9DQoJICAgICAgICAgICAgZWxzZSB7DQoJICAgICAgICAgICAgICAgIGxldCBmdWxsTGluZSA9IGV4dHJhY3RGdWxsTGluZUZpZWxkKGxpbmUpOw0KCSAgICAgICAgICAgICAgICBpZiAoZnVsbExpbmUpDQoJICAgICAgICAgICAgICAgICAgICBhZGRSYXdJbmxpbmVGaWVsZChmdWxsTGluZSwgZmllbGRzKTsNCgkgICAgICAgICAgICB9DQoJICAgICAgICB9DQoJICAgIH0NCgkgICAgcmV0dXJuIHsgZmllbGRzLCBsaXN0cyB9Ow0KCX0NCgkvLyBUT0RPOiBDb25zaWRlciB1c2luZyBhbiBhY3R1YWwgcGFyc2VyIGluIGxlaXUgb2YgYSBtb3JlIGV4c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AgICAgICAgICAgIGNhc2UgIm51bWJlciI6DQoJICAgICAgICAgICAgY2FzZSAic3RyaW5nIjoNCgkgICAgICAgICAgICBjYXNlICJib29sZWFuIjoNCgkgICAgICAgICAgICAgICAgcmV0dXJuIHdyYXBwZWQudmFsdWU7DQoJICAgICAgICAgICAgY2FzZSAiZGF0ZSI6DQoJICAgICAgICAgICAgICAgIHJldHVybiB7DQoJICAgICAgICAgICAgICAgICAgICAiX19fdHJhbnNmZXItdHlwZSI6ICJkYXRlIiwNCgkgICAgICAgICAgICAgICAgICAgIHZhbHVlOiB0cmFuc2ZlcmFibGUod3JhcHBlZC52YWx1ZS50b09iamVjdCgpKSwNCgkgICAgICAgICAgICAgICAgICAgIG9wdGlvbnM6IHsgem9uZTogd3JhcHBlZC52YWx1ZS56b25lTmFtZSB9LA0KCSAgICAgICAgICAgICAgICB9Ow0KCSAgICAgICAgICAgIGNhc2UgImR1cmF0aW9uIjoNCgkgICAgICAgICAgICAgICAgcmV0dXJuIHsgIl9fX3RyYW5zZmVyLXR5cGUiOiAiZHVyYXRpb24iLCB2YWx1ZTogdHJhbnNmZXJhYmxlKHdyYXBwZWQudmFsdWUudG9PYmplY3QoKSkgfTsNCgkgICAgICAgICAgICBjYXNlICJhcnJheSI6DQoJICAgICAgICAgICAgICAgIHJldHVybiB3cmFwcGVkLnZhbHVlLm1hcCh2ID0+IHRyYW5zZmVyYWJsZSh2KSk7DQoJICAgICAgICAgICAgY2FzZSAibGluayI6DQoJICAgICAgICAgICAgICAgIHJldHVybiB7ICJfX190cmFuc2Zlci10eXBlIjogImxpbmsiLCB2YWx1ZTogdHJhbnNmZXJhYmxlKHdyYXBwZWQudmFsdWUudG9PYmplY3QoKSkgfTsNCgkgICAgICAgICAgICBjYXNlICJvYmplY3QiOg0KCSAgICAgICAgICAgICAgICBsZXQgcmVzdWx0ID0ge307DQoJICAgICAgICAgICAgICAgIGZvciAobGV0IFtrZXksIHZhbHVlXSBvZiBPYmplY3QuZW50cmllcyh3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lKQ0KCSAgICAgICAgICAgICAgICByZWFsLmFkZCh2YWx1ZSh2YWwpKTsNCgkgICAgICAgICAgICByZXR1cm4gcmVhbDsNCgkgICAgICAgIH0NCgkgICAgICAgIGVsc2UgaWYgKEFycmF5LmlzQXJyYXkodHJhbnNmZXJhYmxlKSkgew0KCSAgICAgICAgICAgIHJldHVybiB0cmFuc2ZlcmFibGUubWFwKHYgPT4gdmFsdWUodikpOw0KCSAgICAgICAgfQ0KCSAgICAgICAgZWxzZSBpZiAodHlwZW9mIHRyYW5zZmVyYWJsZSA9PT0gIm9iamVjdCIpIHsNCgkgICAgICAgICAgICBpZiAoIl9fX3RyYW5zZmVyLXR5cGUiIGluIHRyYW5zZmVyYWJsZSkgew0KCSAgICAgICAgICAgICAgICBzd2l0Y2ggKHRyYW5zZmVyYWJsZVsiX19fdHJhbnNmZXItdHlwZSJdKSB7DQoJICAgICAgICAgICAgICAgICAgICBjYXNlICJkYXRlIjoNCgkgICAgICAgICAgICAgICAgICAgICAgICBsZXQgcmF3RGF0ZSA9IERhdGVUaW1lXzEuZnJvbU9iamVjdCh2YWx1ZSh0cmFuc2ZlcmFibGUudmFsdWUpKTsNCgkgICAgICAgICAgICAgICAgICAgICAgICBsZXQgZGF0ZU9wdHMgPSB2YWx1ZSh0cmFuc2ZlcmFibGUub3B0aW9ucyk7DQoJICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGRhdGVPcHRzLnpvbmUpDQoJICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJhd0RhdGUuc2V0Wm9uZShkYXRlT3B0cy56b25lKTsNCgkgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gcmF3RGF0ZTsNCgkgICAgICAgICAgICAgICAgICAgIGNhc2UgImR1cmF0aW9uIjoNCgkgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gRHVyYXRpb25fMS5mcm9tT2JqZWN0KHZhbHVlKHRyYW5zZmVyYWJsZS52YWx1ZSkpOw0KCSAgICAgICAgICAgICAg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BudWxsKSB7DQoJICAgICAgICB0aHJvdyBFcnJvcihgQ2Fubm90IGluZGV4IGZpbGUsIHNpbmNlIGl0IGhhcyBubyBPYnNpZGlhbiBmaWxlIG1ldGFkYXRhLmApOw0KCSAgICB9DQoJICAgIHJldHVybiBydW5JbXBvcnQocGF0aCwgY29udGVudHMsIHN0YXQsIG1ldGFkYXRhKTsNCgl9DQoJb25tZXNzYWdlID0gYXN5bmMgKGV2dCkgPT4gew0KCSAgICB0cnkgew0KCSAgICAgICAgbGV0IHsgcGF0aCwgY29udGVudHMsIHN0YXQsIG1ldGFkYXRhIH0gPSBldnQuZGF0YTsNCgkgICAgICAgIGxldCByZXN1bHQgPSBmYWlsYWJsZUltcG9ydChwYXRoLCBjb250ZW50cywgc3RhdCwgbWV0YWRhdGEpOw0KCSAgICAgICAgcG9zdE1lc3NhZ2UoeyBwYXRoOiBldnQuZGF0YS5wYXRoLCByZXN1bHQ6IFRyYW5zZmVyYWJsZS50cmFuc2ZlcmFibGUocmVzdWx0KSB9KTsNCgkgICAgfQ0KCSAgICBjYXRjaCAoZXJyb3IpIHsNCgkgICAgICAgIGNvbnNvbGUubG9nKGVycm9yKTsNCgkgICAgICAgIHBvc3RNZXNzYWdlKHsNCgkgICAgICAgICAgICBwYXRoOiBldnQuZGF0YS5wYXRoLA0KCSAgICAgICAgICAgIHJlc3VsdDogew0KCSAgICAgICAgICAgICAgICAkZXJyb3I6IGBGYWlsZWQgdG8gaW5kZXggZmlsZTogJHtldnQuZGF0YS5wYXRofTogJHtlcnJvcn1gLA0KCSAgICAgICAgICAgIH0sDQoJICAgICAgICB9KTsNCgkgICAgfQ0KCX07Cgp9KSgpOwoK', null, false); +var WorkerFactory = createBase64WorkerFactory('Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24gKCkgewoJJ3VzZSBzdHJpY3QnOwoKCXZhciBjb21tb25qc0dsb2JhbCA9IHR5cGVvZiBnbG9iYWxUaGlz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dheXMiOwoJICB9CgoJICBpZiAobmFycm93ID09PSB2b2lkIDApIHsKCSAgICBuYXJyb3cgPSBmYWxzZTsKCSAgfQoKCSAgdmFyIHVuaXRzID0gewoJICAgIHllYXJzOiBbInllYXIiLCAieXIuIl0sCgkgICAgcXVhcnRlcnM6IFsicXVhcnRlciIsICJxdHIuIl0sCgkgICAgbW9udGhzOiBbIm1vbnRoIiwgIm1vLiJdLAoJICAgIHdlZWtzOiBbIndlZWsiLCAid2suIl0sCgkgICAgZGF5czogWyJkYXkiLCAiZGF5IiwgImRheXMiXSwKCSAgICBob3VyczogWyJob3VyIiwgImhyLiJdLAoJICAgIG1pbnV0ZXM6IFsibWludXRlIiwgIm1pbi4iXSwKCSAgICBzZWNvbmRzOiBbInNlY29uZCIsICJzZWMuIl0KCSAgfTsKCSAgdmFyIGxhc3RhYmxlID0gWyJob3VycyIsICJtaW51dGVzIiwgInNlY29uZHMiXS5pbmRleE9mKHVuaXQpID09PSAtMTsKCgkgIGlmIChudW1lcmljID09PSAiYXV0byIgJiYgbGFzdGFibGUpIHsKCSAgICB2YXIgaXNEYXkgPSB1bml0ID09PSAiZGF5cyI7CgoJICAgIHN3aXRjaCAoY291bnQpIHsKCSAgICAgIGNhc2UgMToKCSAgICAgICAgcmV0dXJuIGlzRGF5ID8gInRvbW9ycm93IiA6ICJuZXh0ICIgKyB1bml0c1t1bml0XVswXTsKCgkgICAgICBjYXNlIC0xOgoJICAgICAgICByZXR1cm4gaXNEYXkgPyAieWVzdGVyZGF5IiA6ICJsYXN0ICIgKyB1bml0c1t1bml0XVswXTsKCgkgICAgICBjYXNlIDA6CgkgICAgICAgIHJldHVybiBpc0RheSA/ICJ0b2RheSIgOiAidGhpcyAiICsgdW5pdHNbdW5pdF1bMF07CgoJICAgIH0KCSAgfQoKCSAgdmFyIGlzSW5QYXN0ID0gT2JqZWN0LmlzKGNvdW50LCAtMCkgfHwgY291bnQgPCAwLAoJICAgICAgZm10VmFsdWUgPSBNYXRoLmFicy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yQXQoaSk7CgoJICAgICAgaWYgKGMgPT09ICInIikgewoJICAgICAgICBpZiAoY3VycmVudEZ1bGwubGVuZ3RoID4gMCkgewoJICAgICAgICAgIHNwbGl0cy5wdXNoKHsKCSAgICAgICAgICAgIGxpdGVyYWw6IGJyYWNrZXRlZCwKCSAgICAgICAgICAgIHZhbDogY3VycmVudEZ1bGwKCSAgICAgICAgICB9KTsKCSAgICAgICAgfQoKCSAgICAgICAgY3VycmVudCA9IG51bGw7CgkgICAgICAgIGN1cnJlbnRGdWxsID0gIiI7CgkgICAgICAgIGJyYWNrZXRlZCA9ICFicmFja2V0ZWQ7CgkgICAgICB9IGVsc2UgaWYgKGJyYWNrZXRlZCkgewoJICAgICAgICBjdXJyZW50RnVsbCArPSBjOwoJICAgICAgfSBlbHNlIGlmIChjID09PSBjdXJyZW50KSB7CgkgICAgICAgIGN1cnJlbnRGdWxsICs9IGM7CgkgICAgICB9IGVsc2UgewoJICAgICAgICBpZiAoY3VycmVudEZ1bGwubGVuZ3RoID4gMCkgewoJICAgICAgICAgIHNwbGl0cy5wdXNoKHsKCSAgICAgICAgICAgIGxpdGVyYWw6IGZhbHNlLAoJICAgICAgICAgICAgdmFsOiBjdXJyZW50RnVsbAoJICAgICAgICAgIH0pOwoJICAgICAgICB9CgoJICAgICAgICBjdXJyZW50RnVsbCA9IGM7CgkgICAgICAgIGN1cnJlbnQgPSBjOwoJICAgICAgfQoJICAgIH0KCgkgICAgaWYgKGN1cnJlbnRGdWxsLmxlbmd0aCA+IDApIHsKCSAgICAgIHNwbGl0cy5wdXNoKHsKCSAgICAgICAgbGl0ZXJhbDogYnJhY2tldGVkLAoJICAgICAgICB2YWw6IGN1cnJlbnRGdWxsCgkgICAgICB9KTsKCSAgICB9CgoJICAgIHJldHVybiBzcGxpdHM7CgkgIH07CgoJICBGb3JtYXR0ZXIubWFjcm9Ub2tlblRvRm9ybWF0T3B0cyA9IGZ1bmN0aW9uIG1hY3JvVG9rZW5Ub0Zvcm1hdE9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W0oZHQubWludXRlKTsKCgkgICAgICAgIGNhc2UgIm1tIjoKCSAgICAgICAgICByZXR1cm4gX3RoaXMubnVtKGR0Lm1pbnV0ZSwgMik7CgkgICAgICAgIC8vIGhvdXJzCgoJICAgICAgICBjYXNlICJoIjoKCSAgICAgICAgICByZXR1cm4gX3RoaXMubnVtKGR0LmhvdXIgJSAxMiA9PT0gMCA/IDEyIDogZHQuaG91ciAlIDEyKTsKCgkgICAgICAgIGNhc2UgImhoIjoKCSAgICAgICAgICByZXR1cm4gX3RoaXMubnVtKGR0LmhvdXIgJSAxMiA9PT0gMCA/IDEyIDogZHQuaG91ciAlIDEyLCAyKTsKCgkgICAgICAgIGNhc2UgIkgiOgoJICAgICAgICAgIHJldHVybiBfdGhpcy5udW0oZHQuaG91cik7CgoJICAgICAgICBjYXNlICJISCI6CgkgICAgICAgICAgcmV0dXJuIF90aGlzLm51bShkdC5ob3VyLCAyKTsKCSAgICAgICAgLy8gb2Zmc2V0CgoJICAgICAgICBjYXNlICJaIjoKCSAgICAgICAgICAvLyBsaWtlICs2CgkgICAgICAgICAgcmV0dXJuIGZvcm1hdE9mZnNldCh7CgkgICAgICAgICAgICBmb3JtYXQ6ICJuYXJyb3ciLAoJICAgICAgICAgICAgYWxsb3daOiBfdGhpcy5vcHRzLmFsbG93WgoJICAgICAgICAgIH0pOwoKCSAgICAgICAgY2FzZSAiWloiOgoJICAgICAgICAgIC8vIGxpa2UgKzA2OjAwCgkgICAgICAgICAgcmV0dXJuIGZvcm1hdE9mZnNldCh7CgkgICAgICAgICAgICBmb3JtYXQ6ICJzaG9ydCIsCgkgICAgICAgICAgICBhbGxvd1o6IF90aGlzLm9wdHMuYWxsb3daCgkgICAgICAgICAgfSk7CgoJICAgICAgICBjYXNlICJaWloiOgoJICAgICAgICAgIC8vIGxpa2UgKzA2MDAKCSAgICAgICAgICByZXR1cm4gZm9ybWF0T2Zmc2V0KHsKCSAgICAgICAgICAgIGZvcm1hdDogInRlY2hpZSIsCgkgICAgICAgICAgICBhbGxvd1o6IF90aGlzLm9wdHMuYWxsb3daCgkgICAgICAgICAgfSk7CgoJICAgICAgICBjYXNlICJaWlpaIjoKCSAgICAgICAgICAvLyBsaWtlIEVTVAoJICAgICAgICAgIHJldHVybiBkdC56b25lLm9mZnNldE5hbWUoZHQudHMsIHsKCSAgICAgICAgICAgIGZvcm1hdDogInNob3J0IiwKCSAgICAgICAgICAgIGxvY2FsZTogX3RoaXMubG9jLmxvY2FsZQoJICAgICAgICAgIH0pOwoKCSAgICAgICAgY2FzZSAiWlpaWloiOgoJICAgICAgICAgIC8vIGxpa2UgRWFzdGVybiBTdGFuZGFyZCBUaW1lCgkgICAgICAgICAgcmV0dXJuIGR0LnpvbmUub2Zmc2V0TmFtZShkdC50cywgewoJICAgICAgICAgICAgZm9ybWF0OiAibG9uZyIsCgkgICAgICAgICAgICBsb2NhbGU6IF90aGlzLmxvYy5sb2NhbGUKCSAgICAgICAgICB9KTsKCSAgICAgICAgLy8gem9uZQoKCSAgICAgICAgY2FzZSAieiI6CgkgICAgICAgICAgLy8gbGlrZSBBbWVyaWNhL05ld19Zb3JrCgkgICAgICAgICAgcmV0dXJuIGR0LnpvbmVOYW1lOwoJICAgICAgICAvLyBtZXJpZGllbXMKCgkgICAgICAgIGNhc2UgImEiOgoJICAgICAgICAgIHJldHVybiBtZXJpZGllbSgpOwoJICAgICAgICAvLyBkYXRlcwoKCSAgICAgICAgY2FzZSAiZCI6CgkgICAgICAgICAgcmV0dXJuIHVzZURhdGVUaW1lRm9ybWF0dGVyID8gc3RyaW5nKHsKCSAgICAgICAgICAgIGRheTogIm51bWVyaWMiCgkgICAgICAgICAgfSwgImRheSIpIDogX3RoaXMubnVtKGR0LmRheSk7CgoJICAgICAgICBjYXNlICJkZCI6CgkgICAgICAgICAgcmV0dXJuIHVzZURhdGVUaW1lRm9ybWF0dGVyID8gc3RyaW5nKHsKCSAgICAgICAgICAgIGRheTogIjItZGlnaXQiCgkgICAgICAgICAgfSwgImRheSIpIDogX3RoaXMubnVtKGR0LmRheSwgMik7CgkgICAgICAgIC8vIHdlZWtkYXlzIC0gc3RhbmRhbG9uZQoKCSAgICAgICAgY2FzZSAiYyI6CgkgICAgICAgICAgLy8gbGlrZSAxCgkgICAgICAgICAgcmV0dXJuIF90aGlzLm51bShkdC53ZWVrZGF5KTsKCgkgICAgICAgIGNhc2UgImNjYyI6CgkgICAgICAgICAgLy8gbGlrZSAnVHVlcycKCSAgICAgICAgICByZXR1cm4gd2Vla2RheSgic2hvcnQiLCB0cnVlKTsKCgkgICAgICAgIGNhc2UgImNjY2MiOgoJICAgICAgICAgIC8vIGxpa2UgJ1R1ZXNkYXknCgkgICAgICAgICAgcmV0dXJuIHdlZWtkYXkoImxvbmciLCB0cnVlKTsKCgkgICAgICAgIGNhc2UgImNjY2NjIjoKCSAgICAgICAgICAvLyBsaWtlICdUJwoJICAgICAgICAgIHJldHVybiB3ZWVrZGF5KCJuYXJyb3ciLCB0cnVlKTsKCSAgICAgICAgLy8gd2Vla2RheXMgLSBmb3JtYXQKCgkgICAgICAgIGNhc2UgIkUiOgoJICAgICAgICAgIC8vIGxpa2UgMQoJICAgICAgICAgIHJldHVybiBfdGhpcy5udW0oZHQud2Vla2RheSk7CgoJICAgICAgICBjYXNlICJFRUUiOgoJICAgICAgICAgIC8vIGxpa2UgJ1R1ZXMnCgkgICAgICAgICAgcmV0dXJuIHdlZWtkYXkoInNob3J0IiwgZmFsc2UpOwoKCSAgICAgICAgY2FzZSAiRUVFRSI6CgkgICAgICAgICAgLy8gbGlrZSAnVHVlc2RheScKCSAgICAgICAgICByZXR1cm4gd2Vla2RheSgibG9uZyIsIGZhbHNlKTsKCgkgICAgICAgIGNhc2UgIkVFRUVFIjoKCSAgICAgICAgICAvLyBsaWtlICdUJwoJICAgICAgICAgIHJldHVybiB3ZWVrZGF5KCJuYXJyb3ciLCBmYWxzZSk7CgkgICAgICAgIC8vIG1vbnRocyAtIHN0YW5kYWxvbmUKCgkgICAgICAgIGNhc2UgIkwiOgoJICAgICAgICAgIC8vIGxpa2UgMQoJICAgICAgICAgIHJldHVybiB1c2VEYXRlVGltZUZvcm1hdHRlciA/IHN0cmluZyh7CgkgICAgICAgICAgICBtb250aDogIm51bWVyaWMiLAoJICAgICAgICAgICAgZGF5OiAibnVtZXJpYyIKCSAgICAgICAgICB9LCAibW9udGgiKSA6IF90aGlzLm51bShkdC5tb250aCk7CgoJICAgICAgICBjYXNlICJMTCI6CgkgICAgICAgICAgLy8gbGlrZSAwMSwgZG9lc24ndCBzZWVtIHRvIHdvcmsKCSAgICAgICAgICByZXR1cm4gdXNlRGF0ZVRpbWVGb3JtYXR0ZXIgPyBzdHJpbmcoewoJICAgICAgICAgICAgbW9udGg6ICIyLWRpZ2l0IiwKCSAgICAgICAgICAgIGRheTogIm51bWVyaWMiCgkgICAgICAgICAgfSwgIm1vbnRoIikgOiBfdGhpcy5udW0oZHQubW9udGgsIDIpOwoKCSAgICAgICAgY2FzZSAiTExMIjoKCSAgICAgICAgICAvLyBsaWtlIEphbgoJICAgICAgICAgIHJldHVybiBtb250aCgic2hvcnQiLCB0cnVlKTsKCgkgICAgICAgIGNhc2UgIkxMTEwiOgoJICAgICAgICAgIC8vIGxpa2UgSmFudWFyeQoJICAgICAgICAgIHJldHVybiBtb250aCgibG9uZyIsIHRydWUpOwoKCSAgICAgICAgY2FzZSAiTExMTEwiOgoJICAgICAgICAgIC8vIGxpa2UgSgoJICAgICAgICAgIHJldHVybiBtb250aCgibmFycm93IiwgdHJ1ZSk7CgkgICAgICAgIC8vIG1vbnRocyAtIGZvcm1hdAoKCSAgICAgICAgY2FzZSAiTSI6CgkgICAgICAgICAgLy8gbGlrZSAxCgkgICAgICAgICAgcmV0dXJuIHVzZURhdGVUaW1lRm9ybWF0dGVyID8gc3RyaW5nKHsKCSAgICAgICAgICAgIG1vbnRoOiAibnVtZXJpYyIKCSAgICAgICAgICB9LCAibW9udGgiKSA6IF90aGlzLm51bShkdC5tb250aCk7CgoJICAgICAgICBjYXNlICJNTSI6CgkgICAgICAgICAgLy8gbGlrZSAwMQoJICAgICAgICAgIHJldHVybiB1c2VEYXRlVGltZUZvcm1hdHRlciA/IHN0cmluZyh7CgkgICAgICAgICAgICBtb250aDogIjItZGlnaXQiCgkgICAgICAgICAgfSwgIm1vbnRoIikgOiBfdGhpcy5udW0oZHQubW9udGgsIDIpOwoKCSAgICAgICAgY2FzZSAiTU1NIjoKCSAgICAgICAgICAvLyBsaWtlIEphbgoJICAgICAgICAgIHJldHVybiBtb250aCgic2hvcnQiLCBmYWxzZSk7CgoJICAgICAgICBjYXNlICJNTU1NIjoKCSAgICAgICAgICAvLyBsaWtlIEphbnVhcnkKCSAgICAgICAgICByZXR1cm4gbW9udGgoImxvbmciLCBmYWxzZSk7CgoJICAgICAgICBjYXNlICJNTU1NTSI6CgkgICAgICAgICAgLy8gbGlrZSBKCgkgICAgICAgICAgcmV0dXJuIG1vbnRoKCJuYXJyb3ciLCBmYWxzZSk7CgkgICAgICAgIC8vIHllYXJzCgoJICAgICAgICBjYXNlICJ5IjoKCSAgICAgICAgICAvLyBsaWtlIDIwMTQKCSAgICAgICAgICByZXR1cm4gdXNlRGF0ZVRpbWVGb3JtYXR0ZXIgPyBzdHJpbmcoewoJICAgICAgICAgICAgeWVhcjogIm51bWVyaWMiCgkgICAgICAgICAgfSwgInllYXIiKSA6IF90aGlzLm51bShkdC55ZWFyKTsKCgkgICAgICAgIGNhc2UgInl5IjoKCSAgICAgICAgICAvLyBsaWtlIDE0CgkgICAgICAgICAgcmV0dXJuIHVzZURhdGVUaW1lRm9ybWF0dGVyID8gc3RyaW5nKHsKCSAgICAgICAgICAgIHllYXI6ICIyLWRpZ2l0IgoJICAgICAgICAgIH0sICJ5ZWFyIikgOiBfdGhpcy5udW0oZHQueWVhci50b1N0cmluZygpLnNsaWNlKC0yKSwgMik7CgoJICAgICAgICBjYXNlICJ5eXl5IjoKCSAgICAgICAgICAvLyBsaWtlIDAwMTIKCSAgICAgICAgICByZXR1cm4gdXNlRGF0ZVRpbWVGb3JtYXR0ZXIgPyBzdHJpbmcoewoJICAgICAgICAgICAgeWVhcjogIm51bWVyaWMiCgkgICAgICAgICAgfSwgInllYXIiKSA6IF90aGlzLm51bShkdC55ZWFyLCA0KTsKCgkgICAgICAgIGNhc2UgInl5eXl5eSI6CgkgICAgICAgICAgLy8gbGlrZSAwMDAwMTIKCSAgICAgICAgICByZXR1cm4gdXNlRGF0ZVRpbWVGb3JtYXR0ZXIgPyBzdHJpbmcoewoJICAgICAgICAgICAgeWVhcjogIm51bWVyaWMiCgkgICAgICAgICAgfSwgInllYXIiKSA6IF90aGlzLm51bShkdC55ZWFyLCA2KTsKCSAgICAgICAgLy8gZXJhcwoKCSAgICAgICAgY2FzZSAiRyI6CgkgICAgICAgICAgLy8gbGlrZSBBRAoJICAgICAgICAgIHJldHVybiBlcmEoInNob3J0Iik7CgoJICAgICAgICBjYXNlICJHRyI6CgkgICAgICAgICAgLy8gbGlrZSBBbm5vIERvbWluaQoJICAgICAgICAgIHJldHVybiBlcmEoImxvbmciKTsKCgkgICAgICAgIGNhc2UgIkdHR0dHIjoKCSAgICAgICAgICByZXR1cm4gZXJhKCJuYXJyb3ciKTsKCgkgICAgICAgIGNhc2UgImtrIjoKCSAgICAgICAgICByZXR1cm4gX3RoaXMubnVtKGR0LndlZWtZZWFyLnRvU3RyaW5nKCkuc2xpY2UoLTIpLCAyKTsKCgkgICAgICAgIGNhc2UgImtra2siOgoJICAgICAgICAgIHJldHVybiBfdGhpcy5udW0oZHQud2Vla1llYXIsIDQpOwoKCSAgICAgICAgY2FzZSAiVyI6CgkgICAgICAgICAgcmV0dXJuIF90aGlzLm51bShkdC53ZWVrTnVtYmVyKTsKCgkgICAgICAgIGNhc2UgIldXIjoKCSAgICAgICAgICByZXR1cm4gX3RoaXMubnVtKGR0LndlZWtOdW1iZXIsIDIpOwoKCSAgICAgICAgY2FzZSAibyI6CgkgICAgICAgICAgcmV0dXJuIF90aGlzLm51bShk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gICAgICAgICAgcmV0dXJuICJtaW51dGUiOwoKCSAgICAgICAgY2FzZSAiaCI6CgkgICAgICAgICAgcmV0dXJuICJob3VyIjsKCgkgICAgICAgIGNhc2UgImQiOgoJICAgICAgICAgIHJldHVybiAiZGF5IjsKCgkgICAgICAgIGNhc2UgInciOgoJICAgICAgICAgIHJldHVybiAid2VlayI7CgoJICAgICAgICBjYXNlICJNIjoKCSAgICAgICAgICByZXR1cm4gIm1vbnRoIjsKCgkgICAgICAgIGNhc2UgInkiOgoJICAgICAgICAgIHJldHVybiAieWVhciI7CgoJICAgICAgICBkZWZhdWx0OgoJICAgICAgICAgIHJldHVybiBudWxsOwoJICAgICAgfQoJICAgIH0sCgkgICAgICAgIHRva2VuVG9TdHJpbmcgPSBmdW5jdGlvbiB0b2tlblRvU3RyaW5nKGxpbGR1cikgewoJICAgICAgcmV0dXJuIGZ1bmN0aW9uICh0b2tlbikgewoJICAgICAgICB2YXIgbWFwcGVkID0gdG9rZW5Ub0ZpZWxkKHRva2VuKTsKCgkgICAgICAgIGlmIChtYXBwZWQpIHsKCSAgICAgICAgICByZXR1cm4gX3RoaXMyLm51bShsaWxkdXIuZ2V0KG1hcHBlZCksIHRva2VuLmxlbmd0aCk7CgkgICAgICAgIH0gZWxzZSB7CgkgICAgICAgICAgcmV0dXJuIHRva2VuOwoJICAgICAgICB9CgkgICAgICB9OwoJICAgIH0sCgkgICAgICAgIHRva2VucyA9IEZvcm1hdHRlci5wYXJzZUZvcm1hdChmbXQpLAoJICAgICAgICByZWFsVG9rZW5zID0gdG9rZW5zLnJlZHVjZShmdW5jdGlvbiAoZm91bmQsIF9yZWYpIHsKCSAgICAgIHZhciBsaXRlcmFsID0gX3JlZi5saXRlcmFsLAoJICAgICAgICAgIHZhbCA9IF9yZWYudmFsOwoJICAgICAgcmV0dXJuIGxpdGVyYWwgPyBmb3VuZCA6IGZvdW5kLmNvbmNhdCh2YWwpOwoJICAgIH0sIFtdKSwKCSAgICAgICAgY29sbGFwc2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KF9zdGVwMiA9IF9pdGVyYXRvcjIoKSkuZG9uZTspIHsKCSAgICAgIHZhciBrID0gX3N0ZXAyLnZhbHVlOwoKCSAgICAgIGlmICh1bml0cy5pbmRleE9mKGspID49IDApIHsKCSAgICAgICAgbGFzdFVuaXQgPSBrOwoJICAgICAgICB2YXIgb3duID0gMDsgLy8gYW55dGhpbmcgd2UgaGF2ZW4ndCBib2lsZWQgZG93biB5ZXQgc2hvdWxkIGdldCBib2lsZWQgdG8gdGhpcyB1bml0CgoJICAgICAgICBmb3IgKHZhciBhayBpbiBhY2N1bXVsYXRlZCkgewoJICAgICAgICAgIG93biArPSB0aGlzLm1hdHJpeFtha11ba10gKiBhY2N1bXVsYXRlZFtha107CgkgICAgICAgICAgYWNjdW11bGF0ZWRbYWtdID0gMDsKCSAgICAgICAgfSAvLyBwbHVzIGFueXRoaW5nIHRoYXQncyBhbHJlYWR5IGluIHRoaXMgdW5pdAoKCgkgICAgICAgIGlmIChpc051bWJlcih2YWxzW2tdKSkgewoJICAgICAgICAgIG93biArPSB2YWxzW2tdOwoJICAgICAgICB9CgoJICAgICAgICB2YXIgaSA9IE1hdGgudHJ1bmMob3duKTsKCSAgICAgICAgYnVpbHRba10gPSBpOwoJICAgICAgICBhY2N1bXVsYXRlZFtrXSA9IChvd24gKiAxMDAwIC0gaSAqIDEwMDApIC8gMTAwMDsgLy8gcGx1cyBhbnl0aGluZyBmdXJ0aGVyIGRvd24gdGhlIGNoYWluIHRoYXQgc2hvdWxkIGJlIHJvbGxlZCB1cCBpbiB0byB0aGlzCgoJICAgICAgICBmb3IgKHZhciBkb3duIGluIHZhbHMpIHsKCSAgICAgICAgICBpZiAob3JkZXJlZFVuaXRzJDEuaW5kZXhPZihkb3duKSA+IG9yZGVyZWRVbml0cyQxLmluZGV4T2YoaykpIHsKCSAgICAgICAgICAgIGNvbnZlcnQodGhpcy5tYXRyaXgsIHZhbHMsIGRvd24sIGJ1aWx0LCBrKTsKCSAgICAgICAgICB9CgkgICA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xvYy5lcmFzKCJsb25nIiwgZmFsc2UpLCAwKTsKCSAgICAgIC8vIHllYXJzCgoJICAgICAgY2FzZSAieSI6CgkgICAgICAgIHJldHVybiBpbnRVbml0KG9uZVRvU2l4KTsKCgkgICAgICBjYXNlICJ5eSI6CgkgICAgICAgIHJldHVybiBpbnRVbml0KHR3b1RvRm91ciwgdW50cnVuY2F0ZVllYXIpOwoKCSAgICAgIGNhc2UgInl5eXkiOgoJICAgICAgICByZXR1cm4gaW50VW5pdChmb3VyKTsKCgkgICAgICBjYXNlICJ5eXl5eSI6CgkgICAgICAgIHJldHVybiBpbnRVbml0KGZvdXJUb1NpeCk7CgoJICAgICAgY2FzZSAieXl5eXl5IjoKCSAgICAgICAgcmV0dXJuIGludFVuaXQoc2l4KTsKCSAgICAgIC8vIG1vbnRocwoKCSAgICAgIGNhc2UgIk0iOgoJICAgICAgICByZXR1cm4gaW50VW5pdChvbmVPclR3byk7CgoJICAgICAgY2FzZSAiTU0iOgoJICAgICAgICByZXR1cm4gaW50VW5pdCh0d28pOwoKCSAgICAgIGNhc2UgIk1NTSI6CgkgICAgICAgIHJldHVybiBvbmVPZihsb2MubW9udGhzKCJzaG9ydCIsIHRydWUsIGZhbHNlKSwgMSk7CgoJICAgICAgY2FzZSAiTU1NTSI6CgkgICAgICAgIHJldHVybiBvbmVPZihsb2MubW9udGhzKCJsb25nIiwgdHJ1ZSwgZmFsc2UpLCAxKTsKCgkgICAgICBjYXNlICJMIjoKCSAgICAgICAgcmV0dXJuIGludFVuaXQob25lT3JUd28pOwoKCSAgICAgIGNhc2UgIkxMIjoKCSAgICAgICAgcmV0dXJuIGludFVuaXQodHdvKTsKCgkgICAgICBjYXNlICJMTEwiOgoJICAgICAgICByZXR1cm4gb25lT2YobG9jLm1vbnRocygic2hvcnQiLCBmYWxzZSwgZmFsc2UpLCAxKTsKCgkgICAgICBjYXNlICJMTExMIjoKCSAgICAgICAgcmV0dXJuIG9uZU9mKGxvYy5tb250aHMoImxvbmciLCBmYWxzZSwgZmFsc2UpLCAxKTsKCSAgICAgIC8vIGRhdGVzCgoJICAgICAgY2FzZSAiZCI6CgkgICAgICAgIHJldHVybiBpbnRVbml0KG9uZU9yVHdvKTsKCgkgICAgICBjYXNlICJkZCI6CgkgICAgICAgIHJldHVybiBpbnRVbml0KHR3byk7CgkgICAgICAvLyBvcmRpbmFscwoKCSAgICAgIGNhc2UgIm8iOgoJICAgICAgICByZXR1cm4gaW50VW5pdChvbmVUb1RocmVlKTsKCgkgICAgICBjYXNlICJvb28iOgoJICAgICAgICByZXR1cm4gaW50VW5pdCh0aHJlZSk7CgkgICAgICAvLyB0aW1lCgoJICAgICAgY2FzZSAiSEgiOgoJICAgICAgICByZXR1cm4gaW50VW5pdCh0d28pOwoKCSAgICAgIGNhc2UgIkgiOgoJICAgICAgICByZXR1cm4gaW50VW5pdChvbmVPclR3byk7CgoJICAgICAgY2FzZSAiaGgiOgoJICAgICAgICByZXR1cm4gaW50VW5pdCh0d28pOwoKCSAgICAgIGNhc2UgImgiOgoJICAgICAgICByZXR1cm4gaW50VW5pdChvbmVPclR3byk7CgoJICAgICAgY2FzZSAibW0iOgoJICAgICAgICByZXR1cm4gaW50VW5pdCh0d28pOwoKCSAgICAgIGNhc2UgIm0iOgoJICAgICAgICByZXR1cm4gaW50VW5pdChvbmVPclR3byk7CgoJICAgICAgY2FzZSAicSI6CgkgICAgICAgIHJldHVybiBpbnRVbml0KG9uZU9yVHdvKTsKCgkgICAgICBjYXNlICJxcSI6CgkgICAgICAgIHJldHVybiBpbnRVbml0KHR3byk7CgoJICAgICAgY2FzZSAicyI6CgkgICAgICAgIHJldHVybiBpbnRVbml0KG9uZU9yVHdvKTsKCgkgICAgICBjYXNlICJzcyI6CgkgICAgICAgIHJldHVybiBpbnRVbml0KHR3byk7CgoJICAgICAgY2FzZSAiUyI6CgkgICAgICAgIHJldHVybiBpbnRVbml0KG9uZVRvVGhyZWUpOwoKCSAgICAgIGNhc2UgIlNTUyI6CgkgICAgICAgIHJldHVybiBpbnRVbml0KHRocmVlKTsKCgkgICAgICBjYXNlICJ1IjoKCSAgICAgICAgcmV0dXJuIHNpbXBsZShvbmVUb05pbmUpOwoKCSAgICAgIGNhc2UgInV1IjoKCSAgICAgICAgcmV0dXJuIHNpbXBsZShvbmVPclR3byk7CgoJICAgICAgY2FzZSAidXV1IjoKCSAgICAgICAgcmV0dXJuIGludFVuaXQob25lKTsKCSAgICAgIC8vIG1lcmlkaWVtCgoJICAgICAgY2FzZSAiYSI6CgkgICAgICAgIHJldHVybiBvbmVPZihsb2MubWVyaWRpZW1zKCksIDApOwoJICAgICAgLy8gd2Vla1llYXIgKGspCgoJICAgICAgY2FzZSAia2trayI6CgkgICAgICAgIHJldHVybiBpbnRVbml0KGZvdXIpOwoKCSAgICAgIGNhc2UgImtrIjoKCSAgICAgICAgcmV0dXJuIGludFVuaXQodHdvVG9Gb3VyLCB1bnRydW5jYXRlWWVhcik7CgkgICAgICAvLyB3ZWVrTnVtYmVyIChXKQoKCSAgICAgIGNhc2UgIlciOgoJICAgICAgICByZXR1cm4gaW50VW5pdChvbmVPclR3byk7CgoJICAgICAgY2FzZSAiV1ciOgoJICAgICAgICByZXR1cm4gaW50VW5pdCh0d28pOwoJICAgICAgLy8gd2Vla2RheXMKCgkgICAgICBjYXNlICJFIjoKCSAgICAgIGNhc2UgImMiOgoJICAgICAgICByZXR1cm4gaW50VW5pdChvbmUpOwoKCSAgICAgIGNhc2UgIkVFRSI6CgkgICAgICAgIHJldHVybiBvbmVPZihsb2Mud2Vla2RheXMoInNob3J0IiwgZmFsc2UsIGZhbHNlKSwgMSk7CgoJICAgICAgY2FzZSAiRUVFRSI6CgkgICAgICAgIHJldHVybiBvbmVPZihsb2Mud2Vla2RheXMoImxvbmciLCBmYWxzZSwgZmFsc2UpLCAxKTsKCgkgICAgICBjYXNlICJjY2MiOgoJICAgICAgICByZXR1cm4gb25lT2YobG9jLndlZWtkYXlzKCJzaG9ydCIsIHRydWUsIGZhbHNlK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ywge31dOwoJICB9Cgl9CgoJZnVuY3Rpb24gZGF0ZVRpbWVGcm9tTWF0Y2hlcyhtYXRjaGVzKSB7CgkgIHZhciB0b0ZpZWxkID0gZnVuY3Rpb24gdG9GaWVsZCh0b2tlbikgewoJICAgIHN3aXRjaCAodG9rZW4pIHsKCSAgICAgIGNhc2UgIlMiOgoJICAgICAgICByZXR1cm4gIm1pbGxpc2Vjb25kIjsKCgkgICAgICBjYXNlICJzIjoKCSAgICAgICAgcmV0dXJuICJzZWNvbmQiOwoKCSAgICAgIGNhc2UgIm0iOgoJICAgICAgICByZXR1cm4gIm1pbnV0ZSI7CgoJICAgICAgY2FzZSAiaCI6CgkgICAgICBjYXNlICJIIjoKCSAgICAgICAgcmV0dXJuICJob3VyIjsKCgkgICAgICBjYXNlICJkIjoKCSAgICAgICAgcmV0dXJuICJkYXkiOwoKCSAgICAgIGNhc2UgIm8iOgoJICAgICAgICByZXR1cm4gIm9yZGluYWwiOwoKCSAgICAgIGNhc2UgIkwiOgoJICAgICAgY2FzZSAiTSI6CgkgICAgICAgIHJldHVybiAibW9udGgiOwoKCSAgICAgIGNhc2UgInkiOgoJICAgICAgICByZXR1cm4gInllYXIiOwoKCSAgICAgIGNhc2UgIkUiOgoJICAgICAgY2FzZSAiYyI6CgkgICAgICAgIHJldHVybiAid2Vla2RheSI7CgoJICAgICAgY2FzZSAiVyI6CgkgICAgICAgIHJldHVybiAid2Vla051bWJlciI7CgoJICAgICAgY2FzZSAiayI6CgkgICAgICAgIHJldHVybiAid2Vla1llYXIiOwoKCSAgICAgIGNhc2UgInEiOgoJICAgICAgICByZXR1cm4gInF1YXJ0ZXIiOwoKCSAgICAgIGRlZmF1bHQ6CgkgICAgICAgIHJldHVybiBudWxsOwoJICAgIH0KCSAgfTsKCgkgIHZhciB6b25lID0gbnVsbDsKCSAgdmFyIHNwZWNpZmljT2Zmc2V0OwoKCSAgaWYgKCFpc1VuZGVmaW5lZChtYXRjaGVzLnopKSB7CgkgICAgem9uZS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S5lcXVhbHMoem9uZSk7CgoJICAgICAgaWYgKHVuY2hhbmdlZCkgewoJICAgICAgICB2YXIgX3JlZiA9IFtjb25maWcub2xkLmMsIGNvbmZpZy5vbGQub107CgkgICAgICAgIGMgPSBfcmVmWzBdOwoJICAgICAgICBvID0gX3JlZlsxXTsKCSAgICAgIH0gZWxzZSB7CgkgICAgICAgIHZhciBvdCA9IHpvbmUub2Zmc2V0KHRoaXMudHMpOwoJICAgICAgICBjID0gdHNUb09iaih0aGlzLnRzLCBvdCk7CgkgICAgICAgIGludmFsaWQgPSBOdW1iZXIuaXNOYU4oYy55ZWFyKSA/IG5ldyBJbnZhbGlkKCJpbnZhbGlkIGlucHV0IikgOiBudWxsOwoJICAgICAgICBjID0gaW52YWxpZCA/IG51bGwgOiBjOwoJICAgICAgICBvID0gaW52YWxpZCA/IG51bGwgOiBvdDsKCSAgICAgIH0KCSAgICB9CgkgICAgLyoqCgkgICAgICogQGFjY2VzcyBwcml2YXRlCgkgICAgICovCgoKCSAgICB0aGlzLl96b25lID0gem9uZTsKCSAgICAvKioKCSAgICAgKiBAYWNjZXNzIHByaXZhdGUKCSAgICAgKi8KCgkgICAgdGhpcy5sb2MgPSBjb25maWcubG9jIHx8IExvY2FsZS5jcmVhdGUoKTsKCSAgICAvKioKCSAgICAgKiBAYWNjZXNzIHByaXZhdGUKCSAgICAgKi8KCgkgICAgdGhpcy5pbnZhbGlkID0gaW52YWxpZDsKCSAgICAvKioKCSAgICAgKiBAYWNjZXNzIHByaXZhdGUKCSAgICAgKi8KCgkgICAgdGhpcy53ZWVrRGF0YSA9IG51bGw7CgkgICAgLyoqCgkgICAgICogQGFjY2VzcyBwcml2YXRlCgkgICAgICovCgoJICAgIHRoaXMuYyA9IGM7CgkgICAgLyoqCgkgICAgICogQGFjY2VzcyBwcml2YXRlCgkgICAgICovCgoJICAgIHRoaXMubyA9IG87CgkgICAgLyoqCgkgICAgICogQGFjY2VzcyBwcml2YXRlCgkgICAgICovCgoJICAgIHR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YWxlIHRvIHNldCBvbiB0aGUgcmVzdWx0aW5nIERhdGVUaW1lIGluc3RhbmNlCgkgICAqIEBwYXJhbSB7c3RyaW5nfSBbb3B0aW9ucy5vdXRwdXRDYWxlbmRhcl0gLSB0aGUgb3V0cHV0IGNhbGVuZGFyIHRvIHNldCBvbiB0aGUgcmVzdWx0aW5nIERhdGVUaW1lIGluc3RhbmNlCgkgICAqIEBwYXJhbSB7c3RyaW5nfSBbb3B0aW9ucy5udW1iZXJpbmdTeXN0ZW1dIC0gdGhlIG51bWJlcmluZyBzeXN0ZW0gdG8gc2V0IG9uIHRoZSByZXN1bHRpbmcgRGF0ZVRpbWUgaW5zdGFuY2UKCSAgICogQGV4YW1wbGUgRGF0ZVRpbWUudXRjKCkgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLy9+PiBub3cKCSAgICogQGV4YW1wbGUgRGF0ZVRpbWUudXRjKDIwMTcpICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLy9+PiAyMDE3LTAxLTAxVDAwOjAwOjAwWgoJICAgKiBAZXhhbXBsZSBEYXRlVGltZS51dGMoMjAxNywgMykgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvL34+IDIwMTctMDMtMDFUMDA6MDA6MDBaCgkgICAqIEBleGFtcGxlIERhdGVUaW1lLnV0YygyMDE3LCAzLCAxMikgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vfj4gMjAxNy0wMy0xMlQwMDowMDowMFoKCSAgICogQGV4YW1wbGUgRGF0ZVRpbWUudXRjKDIwMTcsIDMsIDEyLCA1KSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLy9+PiAyMDE3LTAzLTEyVDA1OjAwOjAwWgoJICAgKiBAZXhhbXBsZSBEYXRlVGltZS51dGMoMjAxNywgMywgMTIsIDUsIDQ1KSAgICAgICAgICAgICAgICAgICAgICAgICAgICAvL34+IDIwMTctMDMtMTJU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TZcdUQ4M0NbXHVEREU4LVx1RERFQ1x1RERFRVx1RERGMVx1RERGMlx1RERGNFx1RERGNi1cdURERkFcdURERkNcdURERkRcdURERkZdfFx1RERFN1x1RDgzQ1tcdURERTZcdURERTdcdURERTktXHVEREVGXHVEREYxLVx1RERGNFx1RERGNi1cdURERjlcdURERkJcdURERkNcdURERkVcdURERkZdfFx1RERFOFx1RDgzQ1tcdURERTZcdURERThcdURERTlcdURERUItXHVEREVFXHVEREYwLVx1RERGNVx1RERGN1x1RERGQS1cdURERkZdfFx1RERFOVx1RDgzQ1tcdURERUFcdURERUNcdURERUZcdURERjBcdURERjJcdURERjRcdURERkZdfFx1RERFQVx1RDgzQ1tcdURERTZcdURERThcdURERUFcdURERUNcdURERURcdURERjctXHVEREZBXXxcdURERUJcdUQ4M0NbXHVEREVFLVx1RERGMFx1RERGMlx1RERGNFx1RERGN118XHVEREVDXHVEODNDW1x1RERFNlx1RERFN1x1RERFOS1cdURERUVcdURERjEtXHVEREYzXHVEREY1LVx1RERGQVx1RERGQ1x1RERGRV18XHVEREVEXHVEODNDW1x1RERGMFx1RERGMlx1RERGM1x1RERGN1x1RERGOVx1RERGQV18XHVEREVFXHVEODNDW1x1RERFOC1cdURERUFcdURERjEtXHVEREY0XHVEREY2LVx1RERGOV18XHVEREVGXHVEODNDW1x1RERFQVx1RERGMlx1RERGNFx1RERGNV18XHVEREYwXHVEODNDW1x1RERFQVx1RERFQy1cdURERUVcdURERjJcdURERjNcdURERjVcdURERjdcdURERkNcdURERkVcdURERkZdfFx1RERGMVx1RDgzQ1tcdURERTYtXHVEREU4XHVEREVFXHVEREYwXHVEREY3LVx1RERGQlx1RERGRV18XHVEREYyXHVEODNDW1x1RERFNlx1RERFOC1cdURERURcdURERjAtXHVEREZGXXxcdURERjNcdUQ4M0NbXHVEREU2XHVEREU4XHVEREVBLVx1RERFQ1x1RERFRVx1RERGMVx1RERGNFx1RERGNVx1RERGN1x1RERGQVx1RERGRl18XHVEREY0XHVEODNDXHVEREYyfFx1RERGNVx1RDgzQ1tcdURERTZcdURERUEtXHVEREVEXHVEREYwLVx1RERGM1x1RERGNy1cdURERjlcdURERkNcdURERkVdfFx1RERGNlx1RDgzQ1x1RERFNnxcdURERjdcdUQ4M0NbXHVEREVBXHVEREY0XHVEREY4XHVEREZBXHVEREZDXXxcdURERjhcdUQ4M0NbXHVEREU2LVx1RERFQVx1RERFQy1cdURERjRcdURERjctXHVEREY5XHVEREZCXHVEREZELVx1RERGRl18XHVEREY5XHVEODNDW1x1RERFNlx1RERFOFx1RERFOVx1RERFQi1cdURERURcdURERUYtXHVEREY0XHVEREY3XHVEREY5XHVEREZCXHVEREZDXHVEREZGXXxcdURERkFcdUQ4M0NbXHVEREU2XHVEREVDXHVEREYyXHVEREYzXHVEREY4XHVEREZFXHVEREZGXXxcdURERkJcdUQ4M0NbXHVEREU2XHVEREU4XHVEREVBXHVEREVDXHVEREVFXHVEREYzXHVEREZBXXxcdURERkNcdUQ4M0NbXHVEREVCXHVEREY4XXxcdURERkRcdUQ4M0NcdURERjB8XHVEREZFXHVEODNDW1x1RERFQVx1RERGOV18XHVEREZGXHVEODNDW1x1RERFNlx1RERGMlx1RERGQ118XHVERkYzXHVGRTBGPyg/Olx1MjAwRCg/Olx1MjZBN1x1RkUwRj98XHVEODNDXHVERjA4KSk/fFx1REZGNCg/Olx1MjAwRFx1MjYyMFx1RkUwRj98XHVEQjQwXHVEQzY3XHVEQjQwXHVEQzYyXHVEQjQwKD86XHVEQzY1XHVEQjQwXHVEQzZFXHVEQjQwXHVEQzY3fFx1REM3M1x1REI0MFx1REM2M1x1REI0MFx1REM3NHxcdURDNzdcdURCNDBcdURDNkNcdURCNDBcdURDNzMpXHVEQjQwXHVEQzdGKT8pfFx1RDgzRCg/OltcdURDM0ZcdURDRkRcdURENDlcdURENEFcdURENkZcdURENzBcdURENzNcdURENzYtXHVERDc5XHVERDg3XHVERDhBLVx1REQ4RFx1RERBNVx1RERBOFx1RERCMVx1RERCMlx1R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QwRVx1REQxMC1cdUREMTdcdUREMjAtXHVERDI1XHVERDI3LVx1REQyRlx1REQzQVx1REQzRi1cdURENDVcdURENDctXHVERDc2XHVERDc4LVx1RERCNFx1RERCN1x1RERCQVx1RERCQy1cdUREQ0NcdURERDBcdURERTAtXHVEREZGXHVERTcwLVx1REU3NFx1REU3OC1cdURFN0NcdURFODAtXHVERTg2XHVERTkwLVx1REVBQ1x1REVCMC1cdURFQkFcdURFQzAtXHVERUMyXHVERUQwLVx1REVEOVx1REVFMC1cdURFRTddfFx1REQzQyg/Olx1MjAwRFtcdTI2NDBcdTI2NDJdXHVGRTBGP3xcdUQ4M0NbXHVERkZCLVx1REZGRl0pP3xcdURERDEoPzpcdTIwMEQoPzpbXHUyNjk1XHUyNjk2XHUyNzA4XVx1RkUwRj98XHVEODNDW1x1REYzRVx1REY3M1x1REY3Q1x1REY4NFx1REY5M1x1REZBNFx1REZBOFx1REZFQlx1REZFRF18XHVEODNEW1x1RENCQlx1RENCQ1x1REQyN1x1REQyQ1x1REU4MFx1REU5Ml18XHVEODNFKD86W1x1RERBRi1cdUREQjNcdUREQkNcdUREQkRdfFx1REQxRFx1MjAwRFx1RDgzRVx1REREMSkpfFx1RDgzQyg/Olx1REZGQig/Olx1MjAwRCg/OltcdTI2OTVcdTI2OTZcdTI3MDhdXHVGRTBGP3xcdTI3NjRcdUZFMEY/XHUyMDBEKD86XHVEODNEXHVEQzhCXHUyMDBEKT9cdUQ4M0VcdURERDFcdUQ4M0NbXHVERkZDLVx1REZGRl18XHVEODNDW1x1REYzRVx1REY3M1x1REY3Q1x1REY4NFx1REY5M1x1REZBNFx1REZBOFx1REZFQlx1REZFRF18XHVEODNEW1x1RENCQlx1RENCQ1x1REQyN1x1REQyQ1x1REU4MFx1REU5Ml18XHVEODNFKD86W1x1RERBRi1cdUREQjNcdUREQkNcdUREQkRdfFx1REQxRFx1MjAwRFx1RDgzRVx1REREMVx1RDgzQ1tcdURGRkItXHVERkZGXSkpKT98XHVERkZD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sdWU7DQoJICAgICAgICAgICAgY2FzZSAiaHRtbCI6DQoJICAgICAgICAgICAgICAgIHJldHVybiB3cmFwcGVkLnZhbHVlLm91dGVySFRNTDsNCgkgICAgICAgICAgICBjYXNlICJ3aWRnZXQiOg0KCSAgICAgICAgICAgICAgICByZXR1cm4gd3JhcHBlZC52YWx1ZS5tYXJrZG93bigpOw0KCSAgICAgICAgICAgIGNhc2UgImxpbmsiOg0KCSAgICAgICAgICAgICAgICByZXR1cm4gd3JhcHBlZC52YWx1ZS5tYXJrZG93bigpOw0KCSAgICAgICAgICAgIGNhc2UgImZ1bmN0aW9uIjoNCgkgICAgICAgICAgICAgICAgcmV0dXJuICI8ZnVuY3Rpb24+IjsNCgkgICAgICAgICAgICBjYXNlICJhcnJheSI6DQoJICAgICAgICAgICAgICAgIGxldCByZXN1bHQgPSAiIjsNCgkgICAgICAgICAgICAgICAgaWYgKHJlY3Vyc2l2ZSkNCgkgICAgICAgICAgICAgICAgICAgIHJlc3VsdCArPSAiWyI7DQoJICAgICAgICAgICAgICAgIHJlc3VsdCArPSB3cmFwcGVkLnZhbHVlLm1hcChmID0+IHRvU3RyaW5nKGYsIHNldHRpbmcsIHRydWUpKS5qb2luKCIsICIpOw0KCSAgICAgICAgICAgICAgICBpZiAocmVjdXJzaXZlKQ0KCSAgICAgICAgICAgICAgICAgICAgcmVzdWx0ICs9ICJdIjsNCgkgICAgICAgICAgICAgICAgcmV0dXJuIHJlc3VsdDsNCgkgICAgICAgICAgICBjYXNlICJvYmplY3QiOg0KCSAgICAgICAgICAgICAgICByZXR1cm4gKCJ7ICIgKw0KCSAgICAgICAgICAgICAgICAgICAgT2JqZWN0LmVudHJpZXMod3JhcHBlZC52YWx1ZSkNCgkgICAgICAgICAgICAgICAgICAgICAgICAubWFwKGUgPT4gZVswXSArICI6ICIgKyB0b1N0cmluZyhlWzFdLCBzZXR0aW5nLCB0cnVlKSkNCgkgICAgICAgICAgICAgICAgICAgICAgICAuam9pbigiLCAiKSArDQ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sNCgkgICAgICAgIHZhciBfYSwgX2I7DQoJICAgICAgICAvLyBIYW5kbGUgdW5kZWZpbmVkL251bGxzIGZpcnN0Lg0KCSAgICAgICAgaWYgKHZhbDEgPT09IHVuZGVmaW5lZCkNCgkgICAgICAgICAgICB2YWwxID0gbnVsbDsNCgkgICAgICAgIGlmICh2YWwyID09PSB1bmRlZmluZWQpDQoJICAgICAgICAgICAgdmFsMiA9IG51bGw7DQoJICAgICAgICBpZiAodmFsMSA9PT0gbnVsbCAmJiB2YWwyID09PSBudWxsKQ0KCSAgICAgICAgICAgIHJldHVybiAwOw0KCSAgICAgICAgZWxzZSBpZiAodmFsMSA9PT0gbnVsbCkNCgkgICAgICAgICAgICByZXR1cm4gLTE7DQoJICAgICAgICBlbHNlIGlmICh2YWwyID09PSBudWxsKQ0KCSAgICAgICAgICAgIHJldHVybiAxOw0KCSAgICAgICAgLy8gQSBub24tbnVsbCB2YWx1ZSBub3cgd2hpY2ggd2UgY2FuIHdyYXAgJiBjb21wYXJlIG9uLg0KCSAgICAgICAgbGV0IHdyYXAxID0gd3JhcFZhbHVlKHZhbDEpOw0KCSAgICAgICAgbGV0IHdyYXAyID0gd3JhcFZhbHVlKHZhbDIpOw0KCSAgICAgICAgaWYgKHdyYXAxID09PSB1bmRlZmluZWQgJiYgd3JhcDIgPT09IHVuZGVmaW5lZCkNCgkgICAgICAgICAgICByZXR1cm4gMDsNCgkgICAgICAgIGVsc2UgaWYgKHdyYXAxID09PSB1bmRlZmluZWQpDQoJICAgICAgICAgICAgcmV0dXJuIC0xOw0KCSAgICAgICAgZWxzZSBpZiAod3JhcDIgPT09IHVuZGVmaW5lZCkNCgkgICAgICAgICAgICByZXR1cm4gMTsNCgkgICAgICAgIC8vIFNob3J0LWNpcmN1aXQgb24gZGlmZmVyZW50IHR5cGVzIG9yIG9uIHJlZmVyZW5jZSBlcXVhbGl0eS4NCgkgICAgICAgIGlmICh3cmFwMS50eXBlICE9IHdyYXAyLnR5cGUpDQoJICAgICAgICAgICAgcmV0dXJuIHdyYXAxLnR5cGUubG9jYWxlQ29tcGFyZSh3cmFwMi50eXBlKTsNCgkgICAgICAgIGlmICh3cmFwMS52YWx1ZSA9PT0gd3JhcDIudmFsdWUpDQoJICAgICAgICAgICAgcmV0dXJuIDA7DQoJICAgICAgICBzd2l0Y2ggKHdyYXAxLnR5cGUpIHsNCgkgICAgICAgICAgICBjYXNlICJzdHJpbmciOg0KCSAgICAgICAgICAgICAgICByZXR1cm4gd3JhcDEudmFsdWUubG9jYWxlQ29tcGFyZSh3cmFwMi52YWx1ZSk7DQoJICAgICAgICAgICAgY2FzZSAibnVtYmVyIjoNCgkgICAgICAgICAgICAgICAgaWYgKHdyYXAxLnZhbHVlIDwgd3JhcDIudmFsdWUpDQoJICAgICAgICAgICAgICAgICAgICByZXR1cm4gLTE7DQoJICAgICAgICAgICAgICAgIGVsc2UgaWYgKHdyYXAxLnZhbHVlID09IHdyYXAyLnZhbHVlKQ0KCSAgICAgICAgICAgICAgICAgICAgcmV0dXJuIDA7DQoJICAgICAgICAgICAgICAgIHJldHVybiAxOw0KCSAgICAgICAgICAgIGNhc2UgIm51bGwiOg0KCSAgICAgICAgICAgICAgICByZXR1cm4gMDsNCgkgICAgICAgICAgICBjYXNlICJib29sZWFuIjoNCgkgICAgICAgICAgICAgICAgaWYgKHdyYXAxLnZhbHVlID09IHdyYXAyLnZhbHVlKQ0KCSAgICAgICAgICAgICAgICAgICAgcmV0dXJuIDA7DQoJICAgICAgICAgICAgICAgIGVsc2UNCgkgICAgICAgICAgICAgICAgICAgIHJldHVybiB3cmFwMS52YWx1ZSA/IDEgOiAtMTsNCgkgICAgICAgICAgICBjYXNlICJsaW5rIjoNCgkgICAgICAgICAgICAgICAgbGV0IGxpbmsxID0gd3JhcDEudmFsdWU7DQoJICAgICAgICAgICAgICAgIGxldCBsaW5rMiA9IHdyYXAyLnZhbHVlOw0KCSAgICAgICAgICAgICAgICBsZXQgbm9ybWFsaXplID0gbGlua05vcm1hbGl6ZXIgIT09IG51bGwgJiYgbGlua05vcm1hbGl6ZXIgIT09IHZvaWQgMCA/IGxpbmtOb3JtYWxpemVyIDogKCh4KSA9PiB4KTsNCgkgICAgICAgICAgICAgICAgLy8gV2UgY2FuJ3QgY29tcGFyZSBieSBmaWxlIG5hbWUgb3IgZGlzcGxheSwgc2luY2UgdGhhdCB3b3VsZCBicmVhayBsaW5rIGVxdWFsaXR5LiBDb21wYXJlIGJ5IHBhdGguDQoJICAgICAgICAgICAgICAgIGxldCBwYXRoQ29tcGFyZSA9IG5vcm1hbGl6ZShsaW5rMS5wYXRoKS5sb2NhbGVDb21wYXJlKG5vcm1hbGl6ZShsaW5rMi5wYXRoKSk7DQoJICAgICAgICAgICAgICAgIGlmIChwYXRoQ29tcGFyZSAhPSAwKQ0KCSAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHBhdGhDb21wYXJlOw0KCSAgICAgICAgICAgICAgICAvLyBUaGVuIGNvbXBhcmUgYnkgdHlwZS4NCgkgICAgICAgICAgICAgICAgbGV0IHR5cGVDb21wYXJlID0gbGluazEudHlwZS5sb2NhbGVDb21wYXJlKGxpbmsyLnR5cGUpOw0KCSAgICAgICAgICAgICAgICBpZiAodHlwZUNvbXBhcmUgIT0gMCkNCgkgICAgICAgICAgICAgICAgICAgIHJldHVybiB0eXBlQ29tcGFyZTsNCgkgICAgICAgICAgICAgICAgLy8gVGhlbiBjb21wYXJlIGJ5IHN1YnBhdGggZXhpc3RlbmNlLg0KCSAgICAgICAgICAgICAgICBpZiAobGluazEuc3VicGF0aCAmJiAhbGluazIuc3VicGF0aCkNCgkgICAgICAgICAgICAgICAgICAgIHJldHVybiAxOw0KCSAgICAgICAgICAgICAgICBpZiAoIWxpbmsxLnN1YnBhdGggJiYgbGluazIuc3VicGF0aCkNCgkgICAgICAgICAgICAgICAgICAgIHJldHVybiAtMTsNCgkgICAgICAgICAgICAgICAgaWYgKCFsaW5rMS5zdWJwYXRoICYmICFsaW5rMi5zdWJwYXRoKQ0KCSAgICAgICAgICAgICAgICAgICAgcmV0dXJuIDA7DQoJICAgICAgICAgICAgICAgIC8vIFNpbmNlIGJvdGggaGF2ZSBhIHN1YnBhdGgsIGNvbXBhcmUgYnkgc3VicGF0aC4NCgkgICAgICAgICAgICAgICAgcmV0dXJuICgoX2EgPSBsaW5rMS5zdWJwYXRoKSAhPT0gbnVsbCAmJiBfYSAhPT0gdm9pZCAwID8gX2EgOiAiIikubG9jYWxlQ29tcGFyZSgoX2IgPSBsaW5rMi5zdWJwYXRoKSAhPT0gbnVsbCAmJiBfYiAhPT0gdm9pZCAwID8gX2IgOiAiIik7DQoJICAgICAgICAgICAgY2FzZSAiZGF0ZSI6DQoJICAgICAgICAgICAgICAgIHJldHVybiB3cmFwMS52YWx1ZSA8IHdyYXAyLnZhbHVlDQoJICAgICAgICAgICAgICAgICAgICA/IC0xDQoJICAgICAgICAgICAgICAgICAgICA6IHdyYXAxLnZhbHVlLmVxdWFscyh3cmFwMi52YWx1ZSkNCgkgICAgICAgICAgICAgICAgICAgICAgICA/IDANCgkgICAgICAgICAgICAgICAgICAgICAgICA6IDE7DQoJICAgICAgICAgICAgY2FzZSAiZHVyYXRpb24iOg0KCSAgICAgICAgICAgICAgICByZXR1cm4gd3JhcDEudmFsdWUgPCB3cmFwMi52YWx1ZQ0KCSAgICAgICAgICAgICAgICAgICAgPyAtMQ0KCSAgICAgICAgICAgICAgICAgICAgOiB3cmFwMS52YWx1ZS5lcXVhbHMod3JhcDIudmFsdWUpDQoJICAgICAgICAgICAgICAgICAgICAgICAgPyAwDQoJICAgICAgICAgICAgICAgICAgICAgICAgOiAxOw0KCSAgICAgICAgICAgIGNhc2UgImFycmF5IjoNCgkgICAgICAgICAgICAgICAgbGV0IGYxID0gd3JhcDEudmFsdWU7DQoJICAgICAgICAgICAgICAgIGxldCBmMiA9IHdyYXAyLnZhbHVlOw0KCSAgICAgICAgICAgICAgICBmb3IgKGxldCBpbmRleCA9IDA7IGluZGV4IDwgTWF0aC5taW4oZjEubGVuZ3RoLCBmMi5sZW5ndGgpOyBpbmRleCsrKSB7DQoJICAgICAgICAgICAgICAgICAgICBsZXQgY29tcCA9IGNvbXBhcmVWYWx1ZShmMVtpbmRleF0sIGYyW2luZGV4XSk7DQoJICAgICAgICAgICAgICAgICAgICBpZiAoY29tcCAhPSAwKQ0KCSAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBjb21wOw0KCSAgICAgICAgICAgICAgICB9DQoJICAgICAgICAgICAgICAgIHJldHVybiBmMS5sZW5ndGggLSBmMi5sZW5ndGg7DQoJICAgICAgICAgICAgY2FzZSAib2JqZWN0IjoNCgkgICAgICAgICAgICAgICAgbGV0IG8xID0gd3JhcDEudmFsdWU7DQoJICAgICAgICAgICAgICAgIGxldCBvMiA9IHdyYXAyLnZhbHVlOw0KCSAgICAgICAgICAgICAgICBsZXQgazEgPSBBcnJheS5mcm9tKE9iamVjdC5rZXlzKG8xKSk7DQoJICAgICAgICAgICAgICAgIGxldCBrMiA9IEFycmF5LmZyb20oT2JqZWN0LmtleXMobzIpKTsNCgkgICAgICAgICAgICAgICAgazEuc29ydCgpOw0KCSAgICAgICAgICAgICAgICBrMi5zb3J0KCk7DQoJICAgICAgICAgICAgICAgIGxldCBrZXlDb21wYXJlID0gY29tcGFyZVZhbHVlKGsxLCBrMik7DQoJICAgICAgICAgICAgICAgIGlmIChrZXlDb21wYXJlICE9IDApDQoJICAgICAgICAgICAgICAgICAgICByZXR1cm4ga2V5Q29tcGFyZTsNCgkgICAgICAgICAgICAgICAgZm9yIChsZXQga2V5IG9mIGsxKSB7DQoJICAgICAgICAgICAgICAgICAgICBsZXQgY29tcCA9IGNvbXBhcmVWYWx1ZShvMVtrZXldLCBvMltrZXldKTsNCgkgICAgICAgICAgICAgICAgICAgIGlmIChjb21wICE9IDApDQoJICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGNvbXA7DQoJICAgICAgICAgICAgICAgIH0NCgkgICAgICAgICAgICAgICAgcmV0d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gMDsNCgkgICAgICAgICAgICBjYXNlICJib29sZWFuIjoNCgkgICAgICAgICAgICAgICAgcmV0dXJuIHdyYXBwZWQudmFsdWU7DQoJICAgICAgICAgICAgY2FzZSAibGluayI6DQoJICAgICAgICAgICAgICAgIHJldHVybiAhIXdyYXBwZWQudmFsdWUucGF0aDsNCgkgICAgICAgICAgICBjYXNlICJkYXRlIjoNCgkgICAgICAgICAgICAgICAgcmV0dXJuIHdyYXBwZWQudmFsdWUudG9NaWxsaXMoKSAhPSAwOw0KCSAgICAgICAgICAgIGNhc2UgImR1cmF0aW9uIjoNCgkgICAgICAgICAgICAgICAgcmV0dXJuIHdyYXBwZWQudmFsdWUuYXMoInNlY29uZHMiKSAhPSAwOw0KCSAgICAgICAgICAgIGNhc2UgIm9iamVjdCI6DQoJICAgICAgICAgICAgICAgIHJldHVybiBPYmplY3Qua2V5cyh3cmFwcGVkLnZhbHVlKS5sZW5ndGggPiAwOw0KCSAgICAgICAgICAgIGNhc2UgImFycmF5IjoNCgkgICAgICAgICAgICAgICAgcmV0dXJuIHdyYXBwZWQudmFsdWUubGVuZ3RoID4gMDsNCgkgICAgICAgICAgICBjYXNlICJudWxsIjoNCgkgICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlOw0KCSAgICAgICAgICAgIGNhc2UgImh0bWwiOg0KCSAgICAgICAgICAgIGNhc2UgIndpZGdldCI6DQoJICAgICAgICAgICAgY2FzZSAiZnVuY3Rpb24iOg0KCSAgICAgICAgICAgICAgICByZXR1cm4gdHJ1ZTsNCgkgICAgICAgIH0NCgkgICAgfQ0KCSAgICBWYWx1ZXMuaXNUcnV0aHkgPSBpc1RydXRoeTsNCgkgICAgLyoqIERlZXAgY29weSBhIGZpZWxkLiAqLw0KCSAgICBmdW5jdGlvbiBkZWVwQ29weShmaWVsZCkgew0KCSAgICAgICAgaWYgKGZpZWxkID09PSBudWxsIHx8IGZpZWxkID09PSB1bmRlZmluZWQpDQoJICAgICAgICAgICAgcmV0dXJuIGZp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gICByZXR1cm4gTGluay5maWxlKHRoaXMucGF0aCwgdGhpcy5lbWJlZCwgdGhpcy5kaXNwbGF5KTsNCgkgICAgfQ0KCSAgICAvKiogQ29udmVydCB0aGlzIGxpbmsgaW50byBhbiBlbWJlZGRlZCBsaW5rLiAqLw0KCSAgICB0b0VtYmVkKCkgew0KCSAgICAgICAgaWYgKHRoaXMuZW1iZWQpIHsNCgkgICAgICAgICAgICByZXR1cm4gdGhpczsNCgkgICAgICAgIH0NCgkgICAgICAgIGVsc2Ugew0KCSAgICAgICAgICAgIGxldCBsaW5rID0gbmV3IExpbmsodGhpcyk7DQoJICAgICAgICAgICAgbGluay5lbWJlZCA9IHRydWU7DQoJICAgICAgICAgICAgcmV0dXJuIGxpbms7DQoJICAgICAgICB9DQoJICAgIH0NCgkgICAgLyoqIENvbnZlcnQgdGhpcyBsaW5rIGludG8gYSBub24tZW1iZWRkZWQgbGluay4gKi8NCgkgICAgZnJvbUVtYmVkKCkgew0KCSAgICAgICAgaWYgKCF0aGlzLmVtYmVkKSB7DQoJICAgICAgICAgICAgcmV0dXJuIHRoaXM7DQoJICAgICAgICB9DQoJICAgICAgICBlbHNlIHsNCgkgICAgICAgICAgICBsZXQgbGluayA9IG5ldyBMaW5rKHRoaXMpOw0KCSAgICAgICAgICAgIGxpbmsuZW1iZWQgPSBmYWxzZTsNCgkgICAgICAgICAgICByZXR1cm4gbGluazsNCgkgICAgICAgIH0NCgkgICAgfQ0KCSAgICAvKiogQ29udmVydCB0aGlzIGxpbmsgdG8gbWFya2Rvd24gc28gaXQgY2FuIGJlIHJlbmRlcmVkLiAqLw0KCSAgICBtYXJrZG93bigpIHsNCgkgICAgICAgIGxldCByZXN1bHQgPSAodGhpcy5lbWJlZCA/ICIhIiA6ICIiKSArICJbWyIgKyB0aGlzLm9ic2lkaWFuTGluaygpOw0KCSAgICAgICAgaWYgKHRoaXMuZGlzcGxheSkgew0KCSAgICAgICAgICAgIHJlc3VsdCArPSAifCIgKyB0aGlzLmR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dHMubWFwKGwgPT4gcmVhbENhY2hlLmdldChsLmxpbmUpKSwNCgkgICAgICAgICAgICAgICAgdGFza3M6IHRoaXMubGlzdHMuZmlsdGVyKGwgPT4gISFsLnRhc2spLm1hcChsID0+IHJlYWxDYWNoZS5nZXQobC5saW5lKSksDQoJICAgICAgICAgICAgICAgIGN0aW1lOiB0aGlzLmN0aW1lLA0KCSAgICAgICAgICAgICAgICBjZGF5OiBzdHJpcFRpbWUodGhpcy5jdGltZSksDQoJICAgICAgICAgICAgICAgIG10aW1lOiB0aGlzLm10aW1lLA0KCSAgICAgICAgICAgICAgICBtZGF5OiBzdHJpcFRpbWUodGhpcy5tdGltZSksDQoJICAgICAgICAgICAgICAgIHNpemU6IHRoaXMuc2l6ZSwNCgkgICAgICAgICAgICAgICAgc3RhcnJlZDogaW5kZXguc3RhcnJlZC5zdGFycmVkKHRoaXMucGF0aCksDQoJICAgICAgICAgICAgICAgIGZyb250bWF0dGVyOiBWYWx1ZXMuZGVlcENvcHkodGhpcy5mcm9udG1hdHRlciksDQoJICAgICAgICAgICAgICAgIGV4dDogdGhpcy5leHRlbnNpb24oKSwNCgkgICAgICAgICAgICB9LA0KCSAgICAgICAgfTsNCgkgICAgICAgIC8vIEFkZCB0aGUgY3VycmVudCBkYXkgaWYgcHJlc2VudC4NCgkgICAgICAgIGlmICh0aGlzLmRheSkNCgkgICAgICAgICAgICByZXN1bHQuZmlsZS5kYXkgPSB0aGlzLmRheTsNCgkgICAgICAgIC8vIFRoZW4gYXBwZW5kIHRoZSBjb21wdXRlZCBmaWVsZHMuDQoJICAgICAgICBmb3IgKGxldCBba2V5LCB2YWx1ZV0gb2YgdGhpcy5maWVsZHMuZW50cmllcygpKSB7DQoJICAgICAgICAgICAgaWYgKGtleSBpbiByZXN1bHQpDQoJICAgICAgICAgICAgICAgIGNvbnRpbnVlOyAvLyBEb24ndCBhbGxvdyBmaWVsZHMgdG8gb3ZlcnJpZGUgZXhpc3Rpbmcga2V5cy4NCgkgICAg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ogdGhpcy5saW5lQ291bnQsDQoJICAgICAgICAgICAgbGlzdDogdGhpcy5saXN0LA0KCSAgICAgICAgICAgIG91dGxpbmtzOiBBcnJheS5mcm9tKHRoaXMubGlua3MpLA0KCSAgICAgICAgICAgIHBhdGg6IHRoaXMubGluay5wYXRoLA0KCSAgICAgICAgICAgIGNoaWxkcmVuOiBjaGlsZHJlbiwNCgkgICAgICAgICAgICB0YXNrOiAhIXRoaXMudGFzaywNCgkgICAgICAgICAgICBhbm5vdGF0ZWQ6IHRoaXMuZmllbGRzLnNpemUgPiAwLA0KCSAgICAgICAgICAgIHBvc2l0aW9uOiBWYWx1ZXMuZGVlcENvcHkodGhpcy5wb3NpdGlvbiksDQoJICAgICAgICAgICAgc3VidGFza3M6IGNoaWxkcmVuLA0KCSAgICAgICAgICAgIHJlYWw6ICEhdGhpcy50YXNrLA0KCSAgICAgICAgICAgIGhlYWRlcjogdGhpcy5zZWN0aW9uLCAvLyBAZGVwcmVjYXRlZCwgdXNlICdpdGVtLnNlY3Rpb24nIGluc3RlYWQuDQoJICAgICAgICB9Ow0KCSAgICAgICAgaWYgKHRoaXMucGFyZW50KQ0KCSAgICAgICAgICAgIHJlc3VsdC5wYXJlbnQgPSB0aGlzLnBhcmVudDsNCgkgICAgICAgIGlmICh0aGlzLmJsb2NrSWQpDQoJICAgICAgICAgICAgcmVzdWx0LmJsb2NrSWQgPSB0aGlzLmJsb2NrSWQ7DQoJICAgICAgICBhZGRGaWVsZHModGhpcy5maWVsZHMsIHJlc3VsdCk7DQoJICAgICAgICBpZiAodGhpcy50YXNrKSB7DQoJICAgICAgICAgICAgcmVzdWx0LnN0YXR1cyA9IHRoaXMudGFzay5zdGF0dXM7DQoJICAgICAgICAgICAgcmVzdWx0LmNoZWNrZWQgPSB0aGlzLnRhc2suY2hlY2tlZDsNCgkgICAgICAgICAgICByZXN1bHQuY29tcGxldGVkID0gdGhpcy50YXNrLmNvbXBsZXRlZDsNCgkgICAgICAgICAgICByZXN1bHQuZ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ZmluZWQgfHwgbGluZSA9PSBudWxsKQ0KCSAgICAgICAgICAgICAgICBjb250aW51ZTsNCgkgICAgICAgICAgICBpZiAobGlzdExpbmVzVG9Ta2lwLmhhcyhsaW5lbm8pKQ0KCSAgICAgICAgICAgICAgICBjb250aW51ZTsNCgkgICAgICAgICAgICAvLyBGYXN0IGJhaWwtb3V0IGZvciBsaW5lcyB0aGF0IGFyZSB0b28gbG9uZyBvciBkbyBub3QgY29udGFpbiAnOjonLg0KCSAgICAgICAgICAgIGlmIChsaW5lLmxlbmd0aCA+IDMyNzY4IHx8ICFsaW5lLmluY2x1ZGVzKCI6OiIpKQ0KCSAgICAgICAgICAgICAgICBjb250aW51ZTsNCgkgICAgICAgICAgICBsaW5lID0gbGluZS50cmltKCk7DQoJICAgICAgICAgICAgbGV0IGlubGluZUZpZWxkcyA9IGV4dHJhY3RJbmxpbmVGaWVsZHMobGluZSk7DQoJICAgICAgICAgICAgaWYgKGlubGluZUZpZWxkcy5sZW5ndGggPiAwKSB7DQoJICAgICAgICAgICAgICAgIGZvciAobGV0IGlmaWVsZCBvZiBpbmxpbmVGaWVsZHMpDQoJICAgICAgICAgICAgICAgICAgICBhZGRSYXdJbmxpbmVGaWVsZChpZmllbGQsIGZpZWxkcyk7DQoJICAgICAgICAgICAgfQ0KCSAgICAgICAgICAgIGVsc2Ugew0KCSAgICAgICAgICAgICAgICBsZXQgZnVsbExpbmUgPSBleHRyYWN0RnVsbExpbmVGaWVsZChsaW5lKTsNCgkgICAgICAgICAgICAgICAgaWYgKGZ1bGxMaW5lKQ0KCSAgICAgICAgICAgICAgICAgICAgYWRkUmF3SW5saW5lRmllbGQoZnVsbExpbmUsIGZpZWxkcyk7DQoJICAgICAgICAgICAgfQ0KCSAgICAgICAgfQ0KCSAgICB9DQoJICAgIHJldHVybiB7IGZpZWxkcywgbGlzdHMgfTsNCgl9DQoJLy8gVE9ETzogQ29uc2lkZXIgdXNpbmcgYW4gYWN0dWFsIHBhcnNlciBpbiBsZW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LmxpbmUsDQoJICAgICAgICAgICAgbGluZUNvdW50OiByYXdFbGVtZW50LnBvc2l0aW9uLmVuZC5saW5lIC0gcmF3RWxlbWVudC5wb3NpdGlvbi5zdGFydC5saW5lICsgMSwNCgkgICAgICAgICAgICBsaXN0OiBjb250YWluaW5nTGlzdElkID09IC0xID8gLTEgOiAobWV0YWRhdGEuc2VjdGlvbnMgfHwgW10pW2NvbnRhaW5pbmdMaXN0SWRdLnBvc2l0aW9uLnN0YXJ0LmxpbmUsDQoJICAgICAgICAgICAgcG9zaXRpb246IHJhd0VsZW1lbnQucG9zaXRpb24sDQoJICAgICAgICAgICAgY2hpbGRyZW46IFtdLA0KCSAgICAgICAgICAgIGJsb2NrSWQ6IHJhd0VsZW1lbnQuaWQsDQoJICAgICAgICB9KTsNCgkgICAgICAgIGlmIChyYXdFbGVtZW50LnBhcmVudCA+PSAwICYmIHJhd0VsZW1lbnQucGFyZW50ICE9IGl0ZW0ubGluZSkNCgkgICAgICAgICAgICBpdGVtLnBhcmVudCA9IHJhd0VsZW1lbnQucGFyZW50Ow0KCSAgICAgICAgLy8gU2V0IHVwIHRoZSBiYXNpYyB0YXNrIGluZm9ybWF0aW9uIGZvciBub3csIHRob3VnaCB3ZSBoYXZlIHRvIHJlY29tcHV0ZSBgZnVsbHlDb21wdXRlZGAgbGF0ZXIuDQoJICAgICAgICBpZiAocmF3RWxlbWVudC50YXNrKSB7DQoJICAgICAgICAgICAgaXRlbS50YXNrID0gew0KCSAgICAgICAgICAgICAgICBzdGF0dXM6IHJhd0VsZW1lbnQudGFzaywNCgkgICAgICAgICAgICAgICAgY2hlY2tlZDogcmF3RWxlbWVudC50YXNrICE9ICIiICYmIHJhd0VsZW1lbnQudGFzayAhPSAiICIsDQoJICAgICAgICAgICAgICAgIGNvbXBsZXRlZDogcmF3RWxlbWVudC50YXNrID09ICJYIiB8fCByYXdFbGVtZW50LnRhc2sgPT0gIngiLA0KCSAgICAgICAgICAgICAgICBmdWxseUNvbXBsZXR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AgICAgICAgICAgICAgcmV0dXJuIGRhdGU7DQoJICAgICAgICB9DQoJICAgIH0NCgkgICAgcmV0dXJuIGV4dHJhY3REYXRlKGdldEZpbGVUaXRsZShmaWxlKSk7DQoJfQ0KCS8qKiBSZWN1cnNpdmVseSBjb252ZXJ0IGZyb250bWF0dGVyIGludG8gZmllbGRzLiBXZSBoYXZlIHRvIGRhbmNlIGFyb3VuZCBZQU1MIHN0cnVjdHVyZS4gKi8NCglmdW5jdGlvbiBwYXJzZUZyb250bWF0dGVyKHZhbHVlKSB7DQoJICAgIGlmICh2YWx1ZSA9PSBudWxsKSB7DQoJICAgICAgICByZXR1cm4gbnVsbDsNCgkgICAgfQ0KCSAgICBlbHNlIGlmICh0eXBlb2YgdmFsdWUgPT09ICJvYmplY3QiKSB7DQoJICAgICAgICBpZiAoQXJyYXkuaXNBcnJheSh2YWx1ZSkpIHsNCgkgICAgICAgICAgICBsZXQgcmVzdWx0ID0gW107DQoJICAgICAgICAgICAgZm9yIChsZXQgY2hpbGQgb2YgdmFsdWUpIHsNCgkgICAgICAgICAgICAgICAgcmVzdWx0LnB1c2gocGFyc2VGcm9udG1hdHRlcihjaGlsZCkpOw0KCSAgICAgICAgICAgIH0NCgkgICAgICAgICAgICByZXR1cm4gcmVzdWx0Ow0KCSAgICAgICAgfQ0KCSAgICAgICAgZWxzZSB7DQoJICAgICAgICAgICAgbGV0IG9iamVjdCA9IHZhbHVlOw0KCSAgICAgICAgICAgIGxldCByZXN1bHQgPSB7fTsNCgkgICAgICAgICAgICBmb3IgKGxldCBrZXkgaW4gb2JqZWN0KSB7DQoJICAgICAgICAgICAgICAgIHJlc3VsdFtrZXldID0gcGFyc2VGcm9udG1hdHRlcihvYmplY3Rba2V5XSk7DQoJICAgICAgICAgICAgfQ0KCSAgICAgICAgICAgIHJldHVybiByZXN1bHQ7DQoJICAgICAgICB9DQoJICAgIH0NCgkgICAgZWxzZSBpZiAodHlwZW9mIHZhbHVlID09PSAibnVtYmVyIikgew0K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pIHsNCgkgICAgICAgICAgICBjYXNlICJudWxsIjoNCgkgICAgICAgICAgICBjYXNlICJudW1iZXIiOg0KCSAgICAgICAgICAgIGNhc2UgInN0cmluZyI6DQoJICAgICAgICAgICAgY2FzZSAiYm9vbGVhbiI6DQoJICAgICAgICAgICAgICAgIHJldHVybiB3cmFwcGVkLnZhbHVlOw0KCSAgICAgICAgICAgIGNhc2UgImRhdGUiOg0KCSAgICAgICAgICAgICAgICByZXR1cm4gew0KCSAgICAgICAgICAgICAgICAgICAgIl9fX3RyYW5zZmVyLXR5cGUiOiAiZGF0ZSIsDQoJICAgICAgICAgICAgICAgICAgICB2YWx1ZTogdHJhbnNmZXJhYmxlKHdyYXBwZWQudmFsdWUudG9PYmplY3QoKSksDQoJICAgICAgICAgICAgICAgICAgICBvcHRpb25zOiB7IHpvbmU6IHdyYXBwZWQudmFsdWUuem9uZU5hbWUgfSwNCgkgICAgICAgICAgICAgICAgfTsNCgkgICAgICAgICAgICBjYXNlICJkdXJhdGlvbiI6DQoJICAgICAgICAgICAgICAgIHJldHVybiB7ICJfX190cmFuc2Zlci10eXBlIjogImR1cmF0aW9uIiwgdmFsdWU6IHRyYW5zZmVyYWJsZSh3cmFwcGVkLnZhbHVlLnRvT2JqZWN0KCkpIH07DQoJICAgICAgICAgICAgY2FzZSAiYXJyYXkiOg0KCSAgICAgICAgICAgICAgICByZXR1cm4gd3JhcHBlZC52YWx1ZS5tYXAodiA9PiB0cmFuc2ZlcmFibGUodikpOw0KCSAgICAgICAgICAgIGNhc2UgImxpbmsiOg0KCSAgICAgICAgICAgICAgICByZXR1cm4geyAiX19fdHJhbnNmZXItdHlwZSI6ICJsaW5rIiwgdmFsdWU6IHRyYW5zZmVyYWJsZSh3cmFwcGVkLnZhbHVlLnRvT2JqZWN0KCkpIH07DQoJICAgICAgICAgICAgY2FzZSAib2JqZWN0IjoNCgkgICAgICAgICAgICAgICAgbGV0IHJlc3VsdCA9IHt9Ow0KCSAgICAgICAgICAgICAgICBm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gZm9yIChsZXQgdmFsIG9mIHRyYW5zZmVyYWJsZSkNCgkgICAgICAgICAgICAgICAgcmVhbC5hZGQodmFsdWUodmFsKSk7DQoJICAgICAgICAgICAgcmV0dXJuIHJlYWw7DQoJICAgICAgICB9DQoJICAgICAgICBlbHNlIGlmIChBcnJheS5pc0FycmF5KHRyYW5zZmVyYWJsZSkpIHsNCgkgICAgICAgICAgICByZXR1cm4gdHJhbnNmZXJhYmxlLm1hcCh2ID0+IHZhbHVlKHYpKTsNCgkgICAgICAgIH0NCgkgICAgICAgIGVsc2UgaWYgKHR5cGVvZiB0cmFuc2ZlcmFibGUgPT09ICJvYmplY3QiKSB7DQoJICAgICAgICAgICAgaWYgKCJfX190cmFuc2Zlci10eXBlIiBpbiB0cmFuc2ZlcmFibGUpIHsNCgkgICAgICAgICAgICAgICAgc3dpdGNoICh0cmFuc2ZlcmFibGVbIl9fX3RyYW5zZmVyLXR5cGUiXSkgew0KCSAgICAgICAgICAgICAgICAgICAgY2FzZSAiZGF0ZSI6DQoJICAgICAgICAgICAgICAgICAgICAgICAgbGV0IHJhd0RhdGUgPSBEYXRlVGltZV8xLmZyb21PYmplY3QodmFsdWUodHJhbnNmZXJhYmxlLnZhbHVlKSk7DQoJICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGRhdGVPcHRzID0gdmFsdWUodHJhbnNmZXJhYmxlLm9wdGlvbnMpOw0KCSAgICAgICAgICAgICAgICAgICAgICAgIGlmIChkYXRlT3B0cy56b25lKQ0KCSAgICAgICAgICAgICAgICAgICAgICAgICAgICByYXdEYXRlLnNldFpvbmUoZGF0ZU9wdHMuem9uZSk7DQoJICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHJhd0RhdGU7DQoJICAgICAgICAgICAgICAgICAgICBjYXNlICJkdXJhdGlvbiI6DQoJICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIER1cmF0aW9uXzEuZnJvbU9iamVjdCh2YWx1ZSh0cmFuc2ZlcmFibGUudmF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GVmaW5lZCB8fCBtZXRhZGF0YSA9PT0gbnVsbCkgew0KCSAgICAgICAgdGhyb3cgRXJyb3IoYENhbm5vdCBpbmRleCBmaWxlLCBzaW5jZSBpdCBoYXMgbm8gT2JzaWRpYW4gZmlsZSBtZXRhZGF0YS5gKTsNCgkgICAgfQ0KCSAgICByZXR1cm4gcnVuSW1wb3J0KHBhdGgsIGNvbnRlbnRzLCBzdGF0LCBtZXRhZGF0YSk7DQoJfQ0KCW9ubWVzc2FnZSA9IGFzeW5jIChldnQpID0+IHsNCgkgICAgdHJ5IHsNCgkgICAgICAgIGxldCB7IHBhdGgsIGNvbnRlbnRzLCBzdGF0LCBtZXRhZGF0YSB9ID0gZXZ0LmRhdGE7DQoJICAgICAgICBsZXQgcmVzdWx0ID0gZmFpbGFibGVJbXBvcnQocGF0aCwgY29udGVudHMsIHN0YXQsIG1ldGFkYXRhKTsNCgkgICAgICAgIHBvc3RNZXNzYWdlKHsgcGF0aDogZXZ0LmRhdGEucGF0aCwgcmVzdWx0OiBUcmFuc2ZlcmFibGUudHJhbnNmZXJhYmxlKHJlc3VsdCkgfSk7DQoJICAgIH0NCgkgICAgY2F0Y2ggKGVycm9yKSB7DQoJICAgICAgICBjb25zb2xlLmxvZyhlcnJvcik7DQoJICAgICAgICBwb3N0TWVzc2FnZSh7DQoJICAgICAgICAgICAgcGF0aDogZXZ0LmRhdGEucGF0aCwNCgkgICAgICAgICAgICByZXN1bHQ6IHsNCgkgICAgICAgICAgICAgICAgJGVycm9yOiBgRmFpbGVkIHRvIGluZGV4IGZpbGU6ICR7ZXZ0LmRhdGEucGF0aH06ICR7ZXJyb3J9YCwNCgkgICAgICAgICAgICB9LA0KCSAgICAgICAgfSk7DQoJICAgIH0NCgl9OwoKfSkoKTsKCg==', null, false); /* eslint-enable */ /** Controls and creates Dataview file importers, allowing for asynchronous loading and parsing of files. */ @@ -13816,12 +13871,13 @@ class FullIndex extends obsidian.Component { this.initialized = false; this.vault = app.vault; this.metadataCache = app.metadataCache; - this.persister = new LocalStorageCache(app.appId || "shared", indexVersion); this.pages = new Map(); - this.tags = new IndexMap(); - this.etags = new IndexMap(); + this.tags = new ValueCaseInsensitiveIndexMap(); + this.etags = new ValueCaseInsensitiveIndexMap(); this.links = new IndexMap(); this.revision = 0; + // Caches metadata via durable storage to speed up cache initialization when Obsidian restarts. + this.persister = new LocalStorageCache(app.appId || "shared", indexVersion); // Handles asynchronous reloading of files on web workers. this.addChild((this.importer = new FileImporter(2, this.vault, this.metadataCache))); // Prefix listens to file creation/deletion/rename, and not modifies, so we let it set up it's own listeners. @@ -14108,6 +14164,8 @@ class StarredCache extends obsidian.Component { this.onUpdate = onUpdate; this.stars = StarredCache.fetch(this.app); this.registerInterval(window.setInterval(() => this.reload(), StarredCache.REFRESH_INTERVAL)); + const initialHandler = window.setTimeout(() => this.reload(), StarredCache.INITIAL_DELAY); + this.register(() => window.clearTimeout(initialHandler)); } /** Determines if the given path is starred. */ starred(path) { @@ -14129,6 +14187,8 @@ class StarredCache extends obsidian.Component { return new Set(items.filter((l) => l.type === "file").map(l => l.path)); } } +/** Initial delay before checking the cache; we need to wait for it to asynchronously load the initial stars. */ +StarredCache.INITIAL_DELAY = 4 * 1000; /** How frequently to check for star updates. */ StarredCache.REFRESH_INTERVAL = 30 * 1000; /** A generic index which indexes variables of the form key -> value[], allowing both forward and reverse lookups. */ @@ -14138,7 +14198,7 @@ class IndexMap { this.map = new Map(); this.invMap = new Map(); } - /** Returns all values for the given key. (This is unused except for tests - does it really need to be here?) */ + /** Returns all values for the given key. */ get(key) { let result = this.map.get(key); if (result) { @@ -14205,6 +14265,38 @@ class IndexMap { } } IndexMap.EMPTY_SET = Object.freeze(new Set()); +/** Index map wrapper which is case-insensitive in the key. */ +class ValueCaseInsensitiveIndexMap { + /** Create a new, empty case insensitive index map. */ + constructor(delegate = new IndexMap()) { + this.delegate = delegate; + } + /** Returns all values for the given key. */ + get(key) { + return this.delegate.get(key); + } + /** Returns all keys that reference the given value. Mutating the returned set is not allowed. */ + getInverse(value) { + return this.delegate.getInverse(value.toLocaleLowerCase()); + } + /** Sets the key to the given values; this will delete the old mapping for the key if one was present. */ + set(key, values) { + this.delegate.set(key, new Set(Array.from(values).map(v => v.toLocaleLowerCase()))); + return this; + } + /** Clears all values for the given key so they can be re-added. */ + delete(key) { + return this.delegate.delete(key); + } + /** Rename all references to the given key to a new value. */ + rename(oldKey, newKey) { + return this.delegate.rename(oldKey, newKey); + } + /** Clear the entire index. */ + clear() { + this.delegate.clear(); + } +} /** Collect data matching a source query. */ /** Find source paths which match the given source. */ @@ -14716,7 +14808,7 @@ var DefaultFunctions; } return result; }; - // Reverse aan array or string. + // Reverse an array or string. DefaultFunctions.reverse = new FunctionBuilder("reverse") .add1("array", l => { let result = []; @@ -14855,6 +14947,24 @@ var DefaultFunctions; .vectorize(2, [0, 1]) .vectorize(3, [0, 1, 2]) .build(); + DefaultFunctions.truncate = new FunctionBuilder("truncate") + .add3("string", "number", "string", (str, length, suffix) => { + if (str.length > length - suffix.length) { + return str.substring(0, Math.max(0, length - suffix.length)) + suffix; + } + else { + return str; + } + }) + .add2("string", "number", (str, length, ctx) => DefaultFunctions.truncate(ctx, str, length, "...")) + .add2("null", "*", () => null) + .add2("*", "null", () => null) + .add3("null", "*", "*", () => null) + .add3("*", "null", "*", () => null) + .add3("*", "*", "null", () => null) + .vectorize(2, [0, 1]) + .vectorize(3, [0, 1, 2]) + .build(); DefaultFunctions.fdefault = new FunctionBuilder("default") .add2("*", "*", (v, bk) => (Values.isNull(v) ? bk : v)) .vectorize(2, [0, 1]) @@ -14986,6 +15096,7 @@ const DEFAULT_FUNCTIONS = { padleft: DefaultFunctions.padleft, padright: DefaultFunctions.padright, substring: DefaultFunctions.substring, + truncate: DefaultFunctions.truncate, // Date Operations. striptime: DefaultFunctions.striptime, // List operations. @@ -15911,7 +16022,7 @@ function RawEmbedHtml({ element }) { return v$1("span", { ref: container }); } /** Embeds an HTML element in the react DOM. */ -React.memo(RawEmbedHtml); +const EmbedHtml = React.memo(RawEmbedHtml); /** Intelligently render an arbitrary literal value. */ function RawLit({ value, sourcePath, inline = false, depth = 0, }) { var _a, _b, _c; @@ -15954,6 +16065,9 @@ function RawLit({ value, sourcePath, inline = false, depth = 0, }) { } return v$1(Markdown, { content: value.markdown(), sourcePath: sourcePath }); } + else if (Values.isHtml(value)) { + return v$1(EmbedHtml, { element: value }); + } else if (Values.isWidget(value)) { if (Widgets.isListPair(value)) { return (v$1(d$1, null, @@ -16035,16 +16149,18 @@ function useIndexBackedState(container, app, settings, index, initial, compute) let [initialized, setInitialized] = m(false); let [state, updateState] = m(initial); let [lastReload, setLastReload] = m(index.revision); + // Initial setup to queue fetching the correct state. if (!initialized) { - compute().then(v => updateState(v)); + setLastReload(index.revision); setInitialized(true); + compute().then(updateState); } // Updated on every container re-create; automatically updates state. y(() => { - let refreshOperation = () => { + const refreshOperation = () => { if (lastReload != index.revision && container.isShown() && settings.refreshEnabled) { + compute().then(updateState); setLastReload(index.revision); - compute().then(v => updateState(v)); } }; // Refresh after index changes stop. @@ -16055,7 +16171,7 @@ function useIndexBackedState(container, app, settings, index, initial, compute) app.workspace.offref(workEvent); nodeEvent(); }; - }, [container]); + }, [container, lastReload]); return state; } /** A trivial wrapper which allows a react component to live for the duration of a `MarkdownRenderChild`. */ @@ -16094,7 +16210,8 @@ function TaskItem({ item }) { line: item.line, }, }; - context.app.workspace.openLinkText(item.link.toFile().obsidianLink(), item.path, evt.ctrlKey, selectionState); + // MacOS interprets the Command key as Meta. + context.app.workspace.openLinkText(item.link.toFile().obsidianLink(), item.path, evt.ctrlKey || (evt.metaKey && obsidian.Platform.isMacOS), selectionState); }; // Check/uncheck trhe task in the original file. const onChecked = (evt) => { @@ -16106,7 +16223,7 @@ function TaskItem({ item }) { parent === null || parent === void 0 ? void 0 : parent.setAttribute("data-task", status); let updatedText = undefined; if (context.settings.taskCompletionTracking) - updatedText = setTaskCompletion(item.text, context.settings.taskCompletionText, completed); + updatedText = setTaskCompletion(item.text, context.settings.taskCompletionUseEmojiShorthand, context.settings.taskCompletionText, context.settings.taskCompletionDateFormat, completed); rewriteTask(context.app.vault, item, status, updatedText); }; const checked = item.status !== " "; @@ -16128,20 +16245,17 @@ function TaskList({ items }) { if (items.length == 0 && settings.warnOnEmptyResult) return v$1(ErrorMessage, { message: "Dataview: No results to show for task query." }); let [nest, _mask] = nestItems(items); - return (v$1("ul", { class: "contains-task-list" }, nest.map(item => (item.task ? v$1(TaskItem, { item: item }) : v$1(ListItem, { item: item }))))); + return (v$1("ul", { class: "contains-task-list" }, nest.map(item => item.task ? v$1(TaskItem, { key: listId(item), item: item }) : v$1(ListItem, { key: listId(item), item: item })))); } /** JSX component which recursively renders grouped tasks. */ function TaskGrouping({ items, sourcePath }) { const isGrouping = items.length > 0 && Groupings.isGrouping(items); return (v$1(d$1, null, isGrouping && - items.map(item => (v$1(d$1, null, + items.map(item => (v$1(d$1, { key: item.key }, v$1("h4", null, v$1(Lit, { value: item.key, sourcePath: sourcePath }), - v$1("span", { class: "dataview small-text" }, - "\u00A0(", - Groupings.count(item.rows), - ")")), + v$1("span", { class: "dataview small-text" }, Groupings.count(item.rows))), v$1("div", { class: "dataview result-group" }, v$1(TaskGrouping, { items: item.rows, sourcePath: sourcePath }))))), !isGrouping && v$1(TaskList, { items: items }))); @@ -16223,6 +16337,20 @@ function nestItems(raw) { let roots = raw.filter(elem => elem.parent == undefined || elem.parent == null || !elements.has(parentListId(elem))); return [replaceChildren(roots, elements), mask]; } +/** + * Recursively removes tasks from each subgroup if they are already present by being a child of another task. + * Fixes child pointers. Retains original order of input list. + */ +function nestGroups(raw) { + if (Groupings.isGrouping(raw)) { + return raw.map(g => { + return { key: g.key, rows: nestGroups(g.rows) }; + }); + } + else { + return nestItems(raw)[0]; + } +} /////////////////////// // Task Manipulation // /////////////////////// @@ -16235,11 +16363,16 @@ function trimEndingLines(text) { return parts.join("\n"); } /** Set the task completion key on check. */ -function setTaskCompletion(originalText, completionKey, complete) { - if (!complete) - return trimEndingLines(setInlineField(originalText, completionKey, undefined)); +function setTaskCompletion(originalText, useEmojiShorthand, completionKey, completionDateFormat, complete) { + if (!complete && !useEmojiShorthand) + return trimEndingLines(setInlineField(originalText, completionKey)); let parts = originalText.split(/\r?\n/u); - parts[parts.length - 1] = setInlineField(parts[parts.length - 1], completionKey, DateTime_1.now().toISODate()); + if (useEmojiShorthand) { + parts[parts.length - 1] = setEmojiShorthandCompletionField(parts[parts.length - 1], complete ? DateTime_1.now().toFormat("yyyy-MM-dd") : ""); + } + else { + parts[parts.length - 1] = setInlineField(parts[parts.length - 1], completionKey, DateTime_1.now().toFormat(completionDateFormat)); + } return parts.join("\n"); } /** Rewrite a task with the given completion status and new text. */ @@ -16314,10 +16447,7 @@ function TableGrouping({ headings, values, sourcePath, }) { v$1("thead", { class: "table-view-thead" }, v$1("tr", { class: "table-view-tr-header" }, headings.map((heading, index) => (v$1("th", { class: "table-view-th" }, v$1(Markdown, { sourcePath: sourcePath, content: heading }), - index == 0 && v$1("span", { class: "dataview small-text" }, - "\u00A0(", - values.length, - ")")))))), + index == 0 && v$1("span", { class: "dataview small-text" }, values.length)))))), v$1("tbody", { class: "table-view-tbody" }, values.map(row => (v$1("tr", null, row.map(element => (v$1("td", null, v$1(Lit, { value: element, sourcePath: sourcePath }))))))))), settings.warnOnEmptyResult && values.length == 0 && (v$1(ErrorMessage, { message: "Dataview: No results to show for table query." })))); @@ -19316,11 +19446,19 @@ class DataviewInlineApi { /////////////////////////////// /** Execute a Dataview query, returning the results in programmatic form. */ async query(source, originFile, settings) { - return this.api.query(source, originFile, settings); + return this.api.query(source, originFile !== null && originFile !== void 0 ? originFile : this.currentFilePath, settings); } /** Error-throwing version of {@link query}. */ async tryQuery(source, originFile, settings) { - return this.api.tryQuery(source, originFile, settings); + return this.api.tryQuery(source, originFile !== null && originFile !== void 0 ? originFile : this.currentFilePath, settings); + } + /** Execute a Dataview query, returning the results in Markdown. */ + async queryMarkdown(source, originFile, settings) { + return this.api.queryMarkdown(source, originFile !== null && originFile !== void 0 ? originFile : this.currentFilePath, settings); + } + /** Error-throwing version of {@link queryMarkdown}. */ + async tryQueryMarkdown(source, originFile, settings) { + return this.api.tryQueryMarkdown(source, originFile !== null && originFile !== void 0 ? originFile : this.currentFilePath, settings); } /** * Evaluate a dataview expression (like '2 + 2' or 'link("hello")'), returning the evaluated result. @@ -19505,6 +19643,21 @@ class DataviewInlineApi { taskList(tasks, groupByFile = true) { return this.api.taskList(tasks, groupByFile, this.container, this.component, this.currentFilePath); } + //////////////////////// + // Markdown Rendering // + //////////////////////// + /** Render a table directly to markdown, returning the markdown. */ + markdownTable(headers, values, settings) { + return this.api.markdownTable(headers, values, settings); + } + /** Render a list directly to markdown, returning the markdown. */ + markdownList(values, settings) { + return this.api.markdownList(values, settings); + } + /** Render at ask list directly to markdown, returning the markdown. */ + markdownTaskList(values, settings) { + return this.api.markdownTaskList(values, settings); + } } /** * Evaluate a script where 'this' for the script is set to the given context. Allows you to define global variables. @@ -19590,6 +19743,133 @@ class DataviewInlineJSRenderer extends DataviewRefreshableRenderer { } DataviewInlineJSRenderer.PREAMBLE = "const dataview = this;const dv=this;"; +//////////// +// Tables // +//////////// +/** Render a table of literals to Markdown. */ +function markdownTable(headers, values, settings) { + if (values.length > 0 && headers.length != values[0].length) + throw new Error(`The number of headers (${headers.length}) must match the number of columns (${values[0].length})`); + settings = settings !== null && settings !== void 0 ? settings : DEFAULT_SETTINGS; + const mvalues = []; + const maxLengths = Array.from(headers, v => escapeTable(v).length); + // Pre-construct the table in memory so we can size columns. + for (let row = 0; row < values.length; row++) { + const current = []; + for (let col = 0; col < values[row].length; col++) { + const text = tableLiteral(values[row][col], settings.allowHtml, settings); + current.push(text); + maxLengths[col] = Math.max(maxLengths[col], text.length); + } + mvalues.push(current); + } + // Then construct the actual table... + // Append the header fields first. + let table = `| ${headers.map((v, i) => padright(escapeTable(v), " ", maxLengths[i])).join(" | ")} |\n`; + // Then the separating column. + table += `| ${maxLengths.map(i => padright("", "-", i)).join(" | ")} |\n`; + // Then the data colunns. + for (let row = 0; row < values.length; row++) { + table += `| ${mvalues[row].map((v, i) => padright(v, " ", maxLengths[i])).join(" | ")} |\n`; + } + return table; +} +/** Convert a value to a Markdown-friendly string. */ +function tableLiteral(value, allowHtml = true, settings) { + return escapeTable(rawTableLiteral(value, allowHtml, settings)); +} +/** Convert a value to a Markdown-friendly string; does not do escaping. */ +function rawTableLiteral(value, allowHtml = true, settings) { + if (!allowHtml) + return Values.toString(value, settings); + if (Values.isArray(value)) { + return ``; + } + else if (Values.isObject(value)) { + const inner = Object.entries(value) + .map(([k, v]) => { + return `
  • ${tableLiteral(k, allowHtml, settings)}: ${tableLiteral(v, allowHtml, settings)}
  • `; + }) + .join(""); + return ``; + } + else { + return Values.toString(value, settings); + } +} +/** Don't need to import a library for this one... */ +function padright(text, padding, length) { + if (text.length >= length) + return text; + return text + padding.repeat(length - text.length); +} +/** Escape bars inside table content to prevent it from messing up table rows. */ +function escapeTable(text) { + return text.split(/(?!\\)\|/i).join("\\|"); +} +/////////// +// Lists // +/////////// +/** Render a list of literal elements to a markdown list. */ +function markdownList(values, settings) { + return markdownListRec(values, settings, 0); +} +/** Internal recursive function which renders markdown lists. */ +function markdownListRec(input, settings, depth = 0) { + if (Values.isArray(input)) { + let result = depth == 0 ? "" : "\n"; + for (let value of input) { + result += " ".repeat(depth) + "- "; + result += markdownListRec(value, settings, depth); + result += "\n"; + } + return result; + } + else if (Values.isObject(input)) { + let result = depth == 0 ? "" : "\n"; + for (let [key, value] of Object.entries(input)) { + result += " ".repeat(depth) + "- "; + result += Values.toString(key) + ": "; + result += markdownListRec(value, settings, depth); + result += "\n"; + } + return result; + } + else if (Values.isWidget(input) && Widgets.isListPair(input)) { + return `${Values.toString(input.key)}: ${markdownListRec(input.value, settings, depth + 1)}`; + } + return Values.toString(input); +} +/////////// +// Tasks // +/////////// +/** Render the result of a task query to markdown. */ +function markdownTaskList(tasks, settings, depth = 0) { + var _a; + if (Groupings.isGrouping(tasks)) { + let result = ""; + for (let element of tasks) { + result += "#".repeat(depth + 1) + " " + Values.toString(element.key) + "\n\n"; + result += markdownTaskList(element.rows, settings, depth + 1); + } + return result; + } + else { + let result = ""; + for (let element of tasks) { + result += " ".repeat(depth) + "- "; + if (Groupings.isElementGroup(element)) ; + else { + if (element.task) { + result += `[${element.status}] ${((_a = element.visual) !== null && _a !== void 0 ? _a : element.text).split("\n").join(" ")}\n`; + } + result += markdownTaskList(element.children, settings, depth + 1); + } + } + return result; + } +} + /** The general, externally accessible plugin API (available at `app.plugins.plugins.dataview.api` or as global `DataviewAPI`). */ /** Asynchronous API calls related to file / system IO. */ class DataviewIOApi { @@ -19834,6 +20114,26 @@ class DataviewApi { async tryQuery(source, originFile, settings) { return (await this.query(source, originFile, settings)).orElseThrow(); } + /** Execute an arbitrary dataview query, returning the results in well-formatted markdown. */ + async queryMarkdown(source, originFile, settings) { + const result = await this.query(source, originFile, settings); + if (!result.successful) + return result.cast(); + switch (result.value.type) { + case "list": + return Result.success(this.markdownList(result.value.values, settings)); + case "table": + return Result.success(this.markdownTable(result.value.headers, result.value.values, settings)); + case "task": + return Result.success(this.markdownTaskList(result.value.values, settings)); + case "calendar": + return Result.failure("Cannot render calendar queries to markdown."); + } + } + /** Error-throwing version of {@link queryMarkdown}. */ + async tryQueryMarkdown(source, originFile, settings) { + return (await this.queryMarkdown(source, originFile, settings)).orElseThrow(); + } /** * Evaluate a dataview expression (like '2 + 2' or 'link("hello")'), returning the evaluated result. * This takes an optional second argument which provides definitions for variables, such as: @@ -19940,6 +20240,33 @@ class DataviewApi { async renderValue(value, container, component, filePath, inline = false) { return renderValue(value, container, filePath, component, this.settings, inline); } + ///////////////// + // Data Export // + ///////////////// + /** Render data to a markdown table. */ + markdownTable(headers, values, settings) { + if (!headers) + headers = []; + if (!values) + values = []; + const combined = Object.assign({}, this.settings, settings); + return markdownTable(headers, values, combined); + } + /** Render data to a markdown list. */ + markdownList(values, settings) { + if (!values) + values = []; + const combined = Object.assign({}, this.settings, settings); + return markdownList(values, combined); + } + /** Render tasks or list items to a markdown task list. */ + markdownTaskList(values, settings) { + if (!values) + values = []; + const sparse = nestGroups(values); + const combined = Object.assign({}, this.settings, settings); + return markdownTaskList(sparse, combined); + } } /** Determines if source-path has a `?no-dataview` annotation that disables dataview. */ function isDataviewDisabled(sourcePath) { @@ -19979,6 +20306,304 @@ class DataviewInlineRenderer extends DataviewRefreshableRenderer { } } +/** Replaces raw textual inline fields in text containers with pretty HTML equivalents. */ +async function replaceInlineFields(ctx, init) { + let inlineFields = extractInlineFields(init.container.innerHTML); + if (inlineFields.length == 0) + return; + let component = new obsidian.MarkdownRenderChild(init.container); + ctx.addChild(component); + // Iterate through the raw HTML and replace inline field matches with corresponding rendered values. + let result = init.container.innerHTML; + for (let x = inlineFields.length - 1; x >= 0; x--) { + let field = inlineFields[x]; + let renderContainer = document.createElement("span"); + renderContainer.addClasses(["dataview", "inline-field"]); + // Block inline fields render the key, parenthesis ones do not. + if (field.wrapping == "[") { + const key = renderContainer.createSpan({ + cls: ["dataview", "inline-field-key"], + attr: { + "data-dv-key": field.key, + "data-dv-norm-key": canonicalizeVarName(field.key), + }, + }); + // Explicitly set the inner HTML to respect any key formatting that we should carry over. + key.innerHTML = field.key; + renderContainer.createSpan({ + cls: ["dataview", "inline-field-value"], + attr: { id: "dataview-inline-field-" + x }, + }); + } + else { + renderContainer.createSpan({ + cls: ["dataview", "inline-field-standalone-value"], + attr: { id: "dataview-inline-field-" + x }, + }); + } + result = result.slice(0, field.start) + renderContainer.outerHTML + result.slice(field.end); + } + // Use a