UNPKG

@bjoerge/mutiny

Version:

Tiny toolkit for working with Sanity mutations in JavaScript & TypeScript

1,092 lines (1,091 loc) 213 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }); var rxjs = require("rxjs"), decode = require("./_chunks-cjs/decode.cjs"), mendoza = require("mendoza"), nanoid = require("nanoid"), utils = require("./_chunks-cjs/utils.cjs"), diffMatchPatch = require("@sanity/diff-match-patch"), getAtPath = require("./_chunks-cjs/getAtPath.cjs"), stringify = require("./_chunks-cjs/stringify.cjs"); function omitRev(document) { if (document === void 0) return; const { _rev, ...doc } = document; return doc; } function applyMendozaPatch(document, patch2) { const next = mendoza.applyPatch(omitRev(document), patch2); return next === null ? void 0 : next; } function getMutationDocumentId(mutation) { if (mutation.type === "patch") return mutation.id; if (mutation.type === "create") return mutation.document._id; if (mutation.type === "delete") return mutation.id; if (mutation.type === "createIfNotExists" || mutation.type === "createOrReplace") return mutation.document._id; throw new Error("Invalid mutation type"); } function applyAll(current, mutation) { return mutation.reduce((doc, m) => { const res = applyDocumentMutation(doc, m); if (res.status === "error") throw new Error(res.message); return res.status === "noop" ? doc : res.after; }, current); } function applyDocumentMutation(document, mutation) { if (mutation.type === "create") return create(document, mutation); if (mutation.type === "createIfNotExists") return createIfNotExists(document, mutation); if (mutation.type === "delete") return del(document, mutation); if (mutation.type === "createOrReplace") return createOrReplace(document, mutation); if (mutation.type === "patch") return patch(document, mutation); throw new Error(`Invalid mutation type: ${mutation.type}`); } function create(document, mutation) { if (document) return { status: "error", message: "Document already exist" }; const result = utils.assignId(mutation.document, nanoid.nanoid); return { status: "created", id: result._id, after: result }; } function createIfNotExists(document, mutation) { return utils.hasId(mutation.document) ? document ? { status: "noop" } : { status: "created", id: mutation.document._id, after: mutation.document } : { status: "error", message: "Cannot createIfNotExists on document without _id" }; } function createOrReplace(document, mutation) { return utils.hasId(mutation.document) ? document ? { status: "updated", id: mutation.document._id, before: document, after: mutation.document } : { status: "created", id: mutation.document._id, after: mutation.document } : { status: "error", message: "Cannot createIfNotExists on document without _id" }; } function del(document, mutation) { return document ? mutation.id !== document._id ? { status: "error", message: "Delete mutation targeted wrong document" } : { status: "deleted", id: mutation.id, before: document, after: void 0 } : { status: "noop" }; } function patch(document, mutation) { if (!document) return { status: "error", message: "Cannot apply patch on nonexistent document" }; const next = utils.applyPatchMutation(mutation, document); return document === next ? { status: "noop" } : { status: "updated", id: mutation.id, before: document, after: next }; } function applyMutations(mutations, dataset) { var _a; const updatedDocs = /* @__PURE__ */ Object.create(null); for (const mutation of mutations) { const documentId = getMutationDocumentId(mutation); if (!documentId) throw new Error("Unable to get document id from mutation"); const before = ((_a = updatedDocs[documentId]) == null ? void 0 : _a.after) || dataset.get(documentId), res = applyDocumentMutation(before, mutation); if (res.status === "error") throw new Error(res.message); res.status !== "noop" && (res.status === "updated" || res.status === "created" || res.status === "deleted") && (documentId in updatedDocs || (updatedDocs[documentId] = { before, after: void 0, muts: [] }), updatedDocs[documentId].after = res.after); } return Object.entries(updatedDocs).map( // eslint-disable-next-line no-shadow ([id, { before, after, muts }]) => ({ id, status: after ? before ? "updated" : "created" : "deleted", mutations: muts, before, after }) ); } function commit(results, dataset) { results.forEach((result) => { (result.status === "created" || result.status === "updated") && dataset.set(result.id, result.after), result.status === "deleted" && dataset.delete(result.id); }); } function createDataset() { const documents = /* @__PURE__ */ new Map(); return { set: (id, doc) => void documents.set(id, doc), get: (id) => documents.get(id), delete: (id) => documents.delete(id) }; } function takeUntilRight(arr, predicate, opts) { const result = []; for (const item of arr.slice().reverse()) { if (predicate(item)) return result; result.push(item); } return result.reverse(); } function isEqualPath(p1, p2) { return stringify.stringify(p1) === stringify.stringify(p2); } function supersedes(later, earlier) { return (earlier.type === "set" || earlier.type === "unset") && (later.type === "set" || later.type === "unset"); } function squashNodePatches(patches) { return compactSetIfMissingPatches( compactSetPatches(compactUnsetPatches(patches)) ); } function compactUnsetPatches(patches) { return patches.reduce( (earlierPatches, laterPatch) => { if (laterPatch.op.type !== "unset") return earlierPatches.push(laterPatch), earlierPatches; const unaffected = earlierPatches.filter( (earlierPatch) => !stringify.startsWith(laterPatch.path, earlierPatch.path) ); return unaffected.push(laterPatch), unaffected; }, [] ); } function compactSetPatches(patches) { return patches.reduceRight( (laterPatches, earlierPatch) => (laterPatches.find( (later) => supersedes(later.op, earlierPatch.op) && isEqualPath(later.path, earlierPatch.path) ) || laterPatches.unshift(earlierPatch), laterPatches), [] ); } function compactSetIfMissingPatches(patches) { return patches.reduce( (previousPatches, laterPatch) => laterPatch.op.type !== "setIfMissing" ? (previousPatches.push(laterPatch), previousPatches) : (takeUntilRight( previousPatches, (patch2) => patch2.op.type === "unset" ).find( (precedingPatch) => precedingPatch.op.type === "setIfMissing" && isEqualPath(precedingPatch.path, laterPatch.path) ) || previousPatches.push(laterPatch), previousPatches), [] ); } function compactDMPSetPatches(base, patches) { let edge = base; return patches.reduce( (earlierPatches, laterPatch) => { const before = edge; if (edge = utils.applyNodePatch(laterPatch, edge), laterPatch.op.type === "set" && typeof laterPatch.op.value == "string") { const current = getAtPath.getAtPath(laterPatch.path, before); if (typeof current == "string") { const replaced = { ...laterPatch, op: { type: "diffMatchPatch", value: diffMatchPatch.stringifyPatches( diffMatchPatch.makePatches(current, laterPatch.op.value) ) } }; return earlierPatches.flatMap((ep) => isEqualPath(ep.path, laterPatch.path) && ep.op.type === "diffMatchPatch" ? [] : ep).concat(replaced); } } return earlierPatches.push(laterPatch), earlierPatches; }, [] ); } function squashDMPStrings(remote, mutationGroups) { return mutationGroups.map((mutationGroup) => ({ ...mutationGroup, mutations: dmpIfyMutations(remote, mutationGroup.mutations) })); } function dmpIfyMutations(store, mutations) { return mutations.map((mutation, i) => mutation.type === "patch" ? dmpifyPatchMutation(store.get(mutation.id), mutation) : mutation); } function dmpifyPatchMutation(base, mutation) { return base ? { ...mutation, patches: compactDMPSetPatches(base, mutation.patches) } : mutation; } var commonjsGlobal = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, lodash = { exports: {} }; /** * @license * Lodash <https://lodash.com/> * Copyright OpenJS Foundation and other contributors <https://openjsf.org/> * Released under MIT license <https://lodash.com/license> * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE> * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors */ (function(module2, exports2) { (function() { var undefined$1, VERSION = "4.17.21", LARGE_ARRAY_SIZE = 200, CORE_ERROR_TEXT = "Unsupported core-js use. Try https://npms.io/search?q=ponyfill.", FUNC_ERROR_TEXT = "Expected a function", INVALID_TEMPL_VAR_ERROR_TEXT = "Invalid `variable` option passed into `_.template`", HASH_UNDEFINED = "__lodash_hash_undefined__", MAX_MEMOIZE_SIZE = 500, PLACEHOLDER = "__lodash_placeholder__", CLONE_DEEP_FLAG = 1, CLONE_FLAT_FLAG = 2, CLONE_SYMBOLS_FLAG = 4, COMPARE_PARTIAL_FLAG = 1, COMPARE_UNORDERED_FLAG = 2, WRAP_BIND_FLAG = 1, WRAP_BIND_KEY_FLAG = 2, WRAP_CURRY_BOUND_FLAG = 4, WRAP_CURRY_FLAG = 8, WRAP_CURRY_RIGHT_FLAG = 16, WRAP_PARTIAL_FLAG = 32, WRAP_PARTIAL_RIGHT_FLAG = 64, WRAP_ARY_FLAG = 128, WRAP_REARG_FLAG = 256, WRAP_FLIP_FLAG = 512, DEFAULT_TRUNC_LENGTH = 30, DEFAULT_TRUNC_OMISSION = "...", HOT_COUNT = 800, HOT_SPAN = 16, LAZY_FILTER_FLAG = 1, LAZY_MAP_FLAG = 2, LAZY_WHILE_FLAG = 3, INFINITY = 1 / 0, MAX_SAFE_INTEGER = 9007199254740991, MAX_INTEGER = 17976931348623157e292, NAN = NaN, MAX_ARRAY_LENGTH = 4294967295, MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1, HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1, wrapFlags = [ ["ary", WRAP_ARY_FLAG], ["bind", WRAP_BIND_FLAG], ["bindKey", WRAP_BIND_KEY_FLAG], ["curry", WRAP_CURRY_FLAG], ["curryRight", WRAP_CURRY_RIGHT_FLAG], ["flip", WRAP_FLIP_FLAG], ["partial", WRAP_PARTIAL_FLAG], ["partialRight", WRAP_PARTIAL_RIGHT_FLAG], ["rearg", WRAP_REARG_FLAG] ], argsTag = "[object Arguments]", arrayTag = "[object Array]", asyncTag = "[object AsyncFunction]", boolTag = "[object Boolean]", dateTag = "[object Date]", domExcTag = "[object DOMException]", errorTag = "[object Error]", funcTag = "[object Function]", genTag = "[object GeneratorFunction]", mapTag = "[object Map]", numberTag = "[object Number]", nullTag = "[object Null]", objectTag = "[object Object]", promiseTag = "[object Promise]", proxyTag = "[object Proxy]", regexpTag = "[object RegExp]", setTag = "[object Set]", stringTag = "[object String]", symbolTag = "[object Symbol]", undefinedTag = "[object Undefined]", weakMapTag = "[object WeakMap]", weakSetTag = "[object WeakSet]", arrayBufferTag = "[object ArrayBuffer]", dataViewTag = "[object DataView]", float32Tag = "[object Float32Array]", float64Tag = "[object Float64Array]", int8Tag = "[object Int8Array]", int16Tag = "[object Int16Array]", int32Tag = "[object Int32Array]", uint8Tag = "[object Uint8Array]", uint8ClampedTag = "[object Uint8ClampedArray]", uint16Tag = "[object Uint16Array]", uint32Tag = "[object Uint32Array]", reEmptyStringLeading = /\b__p \+= '';/g, reEmptyStringMiddle = /\b(__p \+=) '' \+/g, reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g, reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g, reUnescapedHtml = /[&<>"']/g, reHasEscapedHtml = RegExp(reEscapedHtml.source), reHasUnescapedHtml = RegExp(reUnescapedHtml.source), reEscape = /<%-([\s\S]+?)%>/g, reEvaluate = /<%([\s\S]+?)%>/g, reInterpolate = /<%=([\s\S]+?)%>/g, reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, reIsPlainProp = /^\w*$/, rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g, reRegExpChar = /[\\^$.*+?()[\]{}|]/g, reHasRegExpChar = RegExp(reRegExpChar.source), reTrimStart = /^\s+/, reWhitespace = /\s/, reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/, reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/, reSplitDetails = /,? & /, reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g, reForbiddenIdentifierChars = /[()=,{}\[\]\/\s]/, reEscapeChar = /\\(\\)?/g, reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g, reFlags = /\w*$/, reIsBadHex = /^[-+]0x[0-9a-f]+$/i, reIsBinary = /^0b[01]+$/i, reIsHostCtor = /^\[object .+?Constructor\]$/, reIsOctal = /^0o[0-7]+$/i, reIsUint = /^(?:0|[1-9]\d*)$/, reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g, reNoMatch = /($^)/, reUnescapedString = /['\n\r\u2028\u2029\\]/g, rsAstralRange = "\\ud800-\\udfff", rsComboMarksRange = "\\u0300-\\u036f", reComboHalfMarksRange = "\\ufe20-\\ufe2f", rsComboSymbolsRange = "\\u20d0-\\u20ff", rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange, rsDingbatRange = "\\u2700-\\u27bf", rsLowerRange = "a-z\\xdf-\\xf6\\xf8-\\xff", rsMathOpRange = "\\xac\\xb1\\xd7\\xf7", rsNonCharRange = "\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf", rsPunctuationRange = "\\u2000-\\u206f", rsSpaceRange = " \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000", rsUpperRange = "A-Z\\xc0-\\xd6\\xd8-\\xde", rsVarRange = "\\ufe0e\\ufe0f", rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange, rsApos = "['\u2019]", rsAstral = "[" + rsAstralRange + "]", rsBreak = "[" + rsBreakRange + "]", rsCombo = "[" + rsComboRange + "]", rsDigits = "\\d+", rsDingbat = "[" + rsDingbatRange + "]", rsLower = "[" + rsLowerRange + "]", rsMisc = "[^" + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + "]", rsFitz = "\\ud83c[\\udffb-\\udfff]", rsModifier = "(?:" + rsCombo + "|" + rsFitz + ")", rsNonAstral = "[^" + rsAstralRange + "]", rsRegional = "(?:\\ud83c[\\udde6-\\uddff]){2}", rsSurrPair = "[\\ud800-\\udbff][\\udc00-\\udfff]", rsUpper = "[" + rsUpperRange + "]", rsZWJ = "\\u200d", rsMiscLower = "(?:" + rsLower + "|" + rsMisc + ")", rsMiscUpper = "(?:" + rsUpper + "|" + rsMisc + ")", rsOptContrLower = "(?:" + rsApos + "(?:d|ll|m|re|s|t|ve))?", rsOptContrUpper = "(?:" + rsApos + "(?:D|LL|M|RE|S|T|VE))?", reOptMod = rsModifier + "?", rsOptVar = "[" + rsVarRange + "]?", rsOptJoin = "(?:" + rsZWJ + "(?:" + [rsNonAstral, rsRegional, rsSurrPair].join("|") + ")" + rsOptVar + reOptMod + ")*", rsOrdLower = "\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])", rsOrdUpper = "\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])", rsSeq = rsOptVar + reOptMod + rsOptJoin, rsEmoji = "(?:" + [rsDingbat, rsRegional, rsSurrPair].join("|") + ")" + rsSeq, rsSymbol = "(?:" + [rsNonAstral + rsCombo + "?", rsCombo, rsRegional, rsSurrPair, rsAstral].join("|") + ")", reApos = RegExp(rsApos, "g"), reComboMark = RegExp(rsCombo, "g"), reUnicode = RegExp(rsFitz + "(?=" + rsFitz + ")|" + rsSymbol + rsSeq, "g"), reUnicodeWord = RegExp([ rsUpper + "?" + rsLower + "+" + rsOptContrLower + "(?=" + [rsBreak, rsUpper, "$"].join("|") + ")", rsMiscUpper + "+" + rsOptContrUpper + "(?=" + [rsBreak, rsUpper + rsMiscLower, "$"].join("|") + ")", rsUpper + "?" + rsMiscLower + "+" + rsOptContrLower, rsUpper + "+" + rsOptContrUpper, rsOrdUpper, rsOrdLower, rsDigits, rsEmoji ].join("|"), "g"), reHasUnicode = RegExp("[" + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + "]"), reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/, contextProps = [ "Array", "Buffer", "DataView", "Date", "Error", "Float32Array", "Float64Array", "Function", "Int8Array", "Int16Array", "Int32Array", "Map", "Math", "Object", "Promise", "RegExp", "Set", "String", "Symbol", "TypeError", "Uint8Array", "Uint8ClampedArray", "Uint16Array", "Uint32Array", "WeakMap", "_", "clearTimeout", "isFinite", "parseInt", "setTimeout" ], templateCounter = -1, typedArrayTags = {}; typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = typedArrayTags[uint32Tag] = !0, typedArrayTags[argsTag] = typedArrayTags[arrayTag] = typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] = typedArrayTags[dataViewTag] = typedArrayTags[dateTag] = typedArrayTags[errorTag] = typedArrayTags[funcTag] = typedArrayTags[mapTag] = typedArrayTags[numberTag] = typedArrayTags[objectTag] = typedArrayTags[regexpTag] = typedArrayTags[setTag] = typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = !1; var cloneableTags = {}; cloneableTags[argsTag] = cloneableTags[arrayTag] = cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] = cloneableTags[boolTag] = cloneableTags[dateTag] = cloneableTags[float32Tag] = cloneableTags[float64Tag] = cloneableTags[int8Tag] = cloneableTags[int16Tag] = cloneableTags[int32Tag] = cloneableTags[mapTag] = cloneableTags[numberTag] = cloneableTags[objectTag] = cloneableTags[regexpTag] = cloneableTags[setTag] = cloneableTags[stringTag] = cloneableTags[symbolTag] = cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] = cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = !0, cloneableTags[errorTag] = cloneableTags[funcTag] = cloneableTags[weakMapTag] = !1; var deburredLetters = { // Latin-1 Supplement block. \u00C0: "A", \u00C1: "A", \u00C2: "A", \u00C3: "A", \u00C4: "A", \u00C5: "A", \u00E0: "a", \u00E1: "a", \u00E2: "a", \u00E3: "a", \u00E4: "a", \u00E5: "a", \u00C7: "C", \u00E7: "c", \u00D0: "D", \u00F0: "d", \u00C8: "E", \u00C9: "E", \u00CA: "E", \u00CB: "E", \u00E8: "e", \u00E9: "e", \u00EA: "e", \u00EB: "e", \u00CC: "I", \u00CD: "I", \u00CE: "I", \u00CF: "I", \u00EC: "i", \u00ED: "i", \u00EE: "i", \u00EF: "i", \u00D1: "N", \u00F1: "n", \u00D2: "O", \u00D3: "O", \u00D4: "O", \u00D5: "O", \u00D6: "O", \u00D8: "O", \u00F2: "o", \u00F3: "o", \u00F4: "o", \u00F5: "o", \u00F6: "o", \u00F8: "o", \u00D9: "U", \u00DA: "U", \u00DB: "U", \u00DC: "U", \u00F9: "u", \u00FA: "u", \u00FB: "u", \u00FC: "u", \u00DD: "Y", \u00FD: "y", \u00FF: "y", \u00C6: "Ae", \u00E6: "ae", \u00DE: "Th", \u00FE: "th", \u00DF: "ss", // Latin Extended-A block. \u0100: "A", \u0102: "A", \u0104: "A", \u0101: "a", \u0103: "a", \u0105: "a", \u0106: "C", \u0108: "C", \u010A: "C", \u010C: "C", \u0107: "c", \u0109: "c", \u010B: "c", \u010D: "c", \u010E: "D", \u0110: "D", \u010F: "d", \u0111: "d", \u0112: "E", \u0114: "E", \u0116: "E", \u0118: "E", \u011A: "E", \u0113: "e", \u0115: "e", \u0117: "e", \u0119: "e", \u011B: "e", \u011C: "G", \u011E: "G", \u0120: "G", \u0122: "G", \u011D: "g", \u011F: "g", \u0121: "g", \u0123: "g", \u0124: "H", \u0126: "H", \u0125: "h", \u0127: "h", \u0128: "I", \u012A: "I", \u012C: "I", \u012E: "I", \u0130: "I", \u0129: "i", \u012B: "i", \u012D: "i", \u012F: "i", \u0131: "i", \u0134: "J", \u0135: "j", \u0136: "K", \u0137: "k", \u0138: "k", \u0139: "L", \u013B: "L", \u013D: "L", \u013F: "L", \u0141: "L", \u013A: "l", \u013C: "l", \u013E: "l", \u0140: "l", \u0142: "l", \u0143: "N", \u0145: "N", \u0147: "N", \u014A: "N", \u0144: "n", \u0146: "n", \u0148: "n", \u014B: "n", \u014C: "O", \u014E: "O", \u0150: "O", \u014D: "o", \u014F: "o", \u0151: "o", \u0154: "R", \u0156: "R", \u0158: "R", \u0155: "r", \u0157: "r", \u0159: "r", \u015A: "S", \u015C: "S", \u015E: "S", \u0160: "S", \u015B: "s", \u015D: "s", \u015F: "s", \u0161: "s", \u0162: "T", \u0164: "T", \u0166: "T", \u0163: "t", \u0165: "t", \u0167: "t", \u0168: "U", \u016A: "U", \u016C: "U", \u016E: "U", \u0170: "U", \u0172: "U", \u0169: "u", \u016B: "u", \u016D: "u", \u016F: "u", \u0171: "u", \u0173: "u", \u0174: "W", \u0175: "w", \u0176: "Y", \u0177: "y", \u0178: "Y", \u0179: "Z", \u017B: "Z", \u017D: "Z", \u017A: "z", \u017C: "z", \u017E: "z", \u0132: "IJ", \u0133: "ij", \u0152: "Oe", \u0153: "oe", \u0149: "'n", \u017F: "s" }, htmlEscapes = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" }, htmlUnescapes = { "&amp;": "&", "&lt;": "<", "&gt;": ">", "&quot;": '"', "&#39;": "'" }, stringEscapes = { "\\": "\\", "'": "'", "\n": "n", "\r": "r", "\u2028": "u2028", "\u2029": "u2029" }, freeParseFloat = parseFloat, freeParseInt = parseInt, freeGlobal = typeof commonjsGlobal == "object" && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal, freeSelf = typeof self == "object" && self && self.Object === Object && self, root = freeGlobal || freeSelf || Function("return this")(), freeExports = exports2 && !exports2.nodeType && exports2, freeModule = freeExports && !0 && module2 && !module2.nodeType && module2, moduleExports = freeModule && freeModule.exports === freeExports, freeProcess = moduleExports && freeGlobal.process, nodeUtil = function() { try { var types = freeModule && freeModule.require && freeModule.require("util").types; return types || freeProcess && freeProcess.binding && freeProcess.binding("util"); } catch { } }(), nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer, nodeIsDate = nodeUtil && nodeUtil.isDate, nodeIsMap = nodeUtil && nodeUtil.isMap, nodeIsRegExp = nodeUtil && nodeUtil.isRegExp, nodeIsSet = nodeUtil && nodeUtil.isSet, nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray; function apply(func, thisArg, args) { switch (args.length) { case 0: return func.call(thisArg); case 1: return func.call(thisArg, args[0]); case 2: return func.call(thisArg, args[0], args[1]); case 3: return func.call(thisArg, args[0], args[1], args[2]); } return func.apply(thisArg, args); } function arrayAggregator(array, setter, iteratee, accumulator) { for (var index = -1, length = array == null ? 0 : array.length; ++index < length; ) { var value = array[index]; setter(accumulator, value, iteratee(value), array); } return accumulator; } function arrayEach(array, iteratee) { for (var index = -1, length = array == null ? 0 : array.length; ++index < length && iteratee(array[index], index, array) !== !1; ) ; return array; } function arrayEachRight(array, iteratee) { for (var length = array == null ? 0 : array.length; length-- && iteratee(array[length], length, array) !== !1; ) ; return array; } function arrayEvery(array, predicate) { for (var index = -1, length = array == null ? 0 : array.length; ++index < length; ) if (!predicate(array[index], index, array)) return !1; return !0; } function arrayFilter(array, predicate) { for (var index = -1, length = array == null ? 0 : array.length, resIndex = 0, result = []; ++index < length; ) { var value = array[index]; predicate(value, index, array) && (result[resIndex++] = value); } return result; } function arrayIncludes(array, value) { var length = array == null ? 0 : array.length; return !!length && baseIndexOf(array, value, 0) > -1; } function arrayIncludesWith(array, value, comparator) { for (var index = -1, length = array == null ? 0 : array.length; ++index < length; ) if (comparator(value, array[index])) return !0; return !1; } function arrayMap(array, iteratee) { for (var index = -1, length = array == null ? 0 : array.length, result = Array(length); ++index < length; ) result[index] = iteratee(array[index], index, array); return result; } function arrayPush(array, values) { for (var index = -1, length = values.length, offset = array.length; ++index < length; ) array[offset + index] = values[index]; return array; } function arrayReduce(array, iteratee, accumulator, initAccum) { var index = -1, length = array == null ? 0 : array.length; for (initAccum && length && (accumulator = array[++index]); ++index < length; ) accumulator = iteratee(accumulator, array[index], index, array); return accumulator; } function arrayReduceRight(array, iteratee, accumulator, initAccum) { var length = array == null ? 0 : array.length; for (initAccum && length && (accumulator = array[--length]); length--; ) accumulator = iteratee(accumulator, array[length], length, array); return accumulator; } function arraySome(array, predicate) { for (var index = -1, length = array == null ? 0 : array.length; ++index < length; ) if (predicate(array[index], index, array)) return !0; return !1; } var asciiSize = baseProperty("length"); function asciiToArray(string) { return string.split(""); } function asciiWords(string) { return string.match(reAsciiWord) || []; } function baseFindKey(collection, predicate, eachFunc) { var result; return eachFunc(collection, function(value, key, collection2) { if (predicate(value, key, collection2)) return result = key, !1; }), result; } function baseFindIndex(array, predicate, fromIndex, fromRight) { for (var length = array.length, index = fromIndex + (fromRight ? 1 : -1); fromRight ? index-- : ++index < length; ) if (predicate(array[index], index, array)) return index; return -1; } function baseIndexOf(array, value, fromIndex) { return value === value ? strictIndexOf(array, value, fromIndex) : baseFindIndex(array, baseIsNaN, fromIndex); } function baseIndexOfWith(array, value, fromIndex, comparator) { for (var index = fromIndex - 1, length = array.length; ++index < length; ) if (comparator(array[index], value)) return index; return -1; } function baseIsNaN(value) { return value !== value; } function baseMean(array, iteratee) { var length = array == null ? 0 : array.length; return length ? baseSum(array, iteratee) / length : NAN; } function baseProperty(key) { return function(object) { return object == null ? undefined$1 : object[key]; }; } function basePropertyOf(object) { return function(key) { return object == null ? undefined$1 : object[key]; }; } function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) { return eachFunc(collection, function(value, index, collection2) { accumulator = initAccum ? (initAccum = !1, value) : iteratee(accumulator, value, index, collection2); }), accumulator; } function baseSortBy(array, comparer) { var length = array.length; for (array.sort(comparer); length--; ) array[length] = array[length].value; return array; } function baseSum(array, iteratee) { for (var result, index = -1, length = array.length; ++index < length; ) { var current = iteratee(array[index]); current !== undefined$1 && (result = result === undefined$1 ? current : result + current); } return result; } function baseTimes(n, iteratee) { for (var index = -1, result = Array(n); ++index < n; ) result[index] = iteratee(index); return result; } function baseToPairs(object, props) { return arrayMap(props, function(key) { return [key, object[key]]; }); } function baseTrim(string) { return string && string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, ""); } function baseUnary(func) { return function(value) { return func(value); }; } function baseValues(object, props) { return arrayMap(props, function(key) { return object[key]; }); } function cacheHas(cache, key) { return cache.has(key); } function charsStartIndex(strSymbols, chrSymbols) { for (var index = -1, length = strSymbols.length; ++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1; ) ; return index; } function charsEndIndex(strSymbols, chrSymbols) { for (var index = strSymbols.length; index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1; ) ; return index; } function countHolders(array, placeholder) { for (var length = array.length, result = 0; length--; ) array[length] === placeholder && ++result; return result; } var deburrLetter = basePropertyOf(deburredLetters), escapeHtmlChar = basePropertyOf(htmlEscapes); function escapeStringChar(chr) { return "\\" + stringEscapes[chr]; } function getValue(object, key) { return object == null ? undefined$1 : object[key]; } function hasUnicode(string) { return reHasUnicode.test(string); } function hasUnicodeWord(string) { return reHasUnicodeWord.test(string); } function iteratorToArray(iterator) { for (var data, result = []; !(data = iterator.next()).done; ) result.push(data.value); return result; } function mapToArray(map) { var index = -1, result = Array(map.size); return map.forEach(function(value, key) { result[++index] = [key, value]; }), result; } function overArg(func, transform) { return function(arg) { return func(transform(arg)); }; } function replaceHolders(array, placeholder) { for (var index = -1, length = array.length, resIndex = 0, result = []; ++index < length; ) { var value = array[index]; (value === placeholder || value === PLACEHOLDER) && (array[index] = PLACEHOLDER, result[resIndex++] = index); } return result; } function setToArray(set) { var index = -1, result = Array(set.size); return set.forEach(function(value) { result[++index] = value; }), result; } function setToPairs(set) { var index = -1, result = Array(set.size); return set.forEach(function(value) { result[++index] = [value, value]; }), result; } function strictIndexOf(array, value, fromIndex) { for (var index = fromIndex - 1, length = array.length; ++index < length; ) if (array[index] === value) return index; return -1; } function strictLastIndexOf(array, value, fromIndex) { for (var index = fromIndex + 1; index--; ) if (array[index] === value) return index; return index; } function stringSize(string) { return hasUnicode(string) ? unicodeSize(string) : asciiSize(string); } function stringToArray(string) { return hasUnicode(string) ? unicodeToArray(string) : asciiToArray(string); } function trimmedEndIndex(string) { for (var index = string.length; index-- && reWhitespace.test(string.charAt(index)); ) ; return index; } var unescapeHtmlChar = basePropertyOf(htmlUnescapes); function unicodeSize(string) { for (var result = reUnicode.lastIndex = 0; reUnicode.test(string); ) ++result; return result; } function unicodeToArray(string) { return string.match(reUnicode) || []; } function unicodeWords(string) { return string.match(reUnicodeWord) || []; } var runInContext = function runInContext2(context) { context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps)); var Array2 = context.Array, Date = context.Date, Error2 = context.Error, Function2 = context.Function, Math = context.Math, Object2 = context.Object, RegExp2 = context.RegExp, String = context.String, TypeError = context.TypeError, arrayProto = Array2.prototype, funcProto = Function2.prototype, objectProto = Object2.prototype, coreJsData = context["__core-js_shared__"], funcToString = funcProto.toString, hasOwnProperty = objectProto.hasOwnProperty, idCounter = 0, maskSrcKey = function() { var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || ""); return uid ? "Symbol(src)_1." + uid : ""; }(), nativeObjectToString = objectProto.toString, objectCtorString = funcToString.call(Object2), oldDash = root._, reIsNative = RegExp2( "^" + funcToString.call(hasOwnProperty).replace(reRegExpChar, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$" ), Buffer = moduleExports ? context.Buffer : undefined$1, Symbol = context.Symbol, Uint8Array = context.Uint8Array, allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined$1, getPrototype = overArg(Object2.getPrototypeOf, Object2), objectCreate = Object2.create, propertyIsEnumerable = objectProto.propertyIsEnumerable, splice = arrayProto.splice, spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined$1, symIterator = Symbol ? Symbol.iterator : undefined$1, symToStringTag = Symbol ? Symbol.toStringTag : undefined$1, defineProperty = function() { try { var func = getNative(Object2, "defineProperty"); return func({}, "", {}), func; } catch { } }(), ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout, ctxNow = Date && Date.now !== root.Date.now && Date.now, ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout, nativeCeil = Math.ceil, nativeFloor = Math.floor, nativeGetSymbols = Object2.getOwnPropertySymbols, nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined$1, nativeIsFinite = context.isFinite, nativeJoin = arrayProto.join, nativeKeys = overArg(Object2.keys, Object2), nativeMax = Math.max, nativeMin = Math.min, nativeNow = Date.now, nativeParseInt = context.parseInt, nativeRandom = Math.random, nativeReverse = arrayProto.reverse, DataView = getNative(context, "DataView"), Map2 = getNative(context, "Map"), Promise2 = getNative(context, "Promise"), Set = getNative(context, "Set"), WeakMap = getNative(context, "WeakMap"), nativeCreate = getNative(Object2, "create"), metaMap = WeakMap && new WeakMap(), realNames = {}, dataViewCtorString = toSource(DataView), mapCtorString = toSource(Map2), promiseCtorString = toSource(Promise2), setCtorString = toSource(Set), weakMapCtorString = toSource(WeakMap), symbolProto = Symbol ? Symbol.prototype : undefined$1, symbolValueOf = symbolProto ? symbolProto.valueOf : undefined$1, symbolToString = symbolProto ? symbolProto.toString : undefined$1; function lodash2(value) { if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) { if (value instanceof LodashWrapper) return value; if (hasOwnProperty.call(value, "__wrapped__")) return wrapperClone(value); } return new LodashWrapper(value); } var baseCreate = /* @__PURE__ */ function() { function object() { } return function(proto) { if (!isObject(proto)) return {}; if (objectCreate) return objectCreate(proto); object.prototype = proto; var result2 = new object(); return object.prototype = undefined$1, result2; }; }(); function baseLodash() { } function LodashWrapper(value, chainAll) { this.__wrapped__ = value, this.__actions__ = [], this.__chain__ = !!chainAll, this.__index__ = 0, this.__values__ = undefined$1; } lodash2.templateSettings = { /** * Used to detect `data` property values to be HTML-escaped. * * @memberOf _.templateSettings * @type {RegExp} */ escape: reEscape, /** * Used to detect code to be evaluated. * * @memberOf _.templateSettings * @type {RegExp} */ evaluate: reEvaluate, /** * Used to detect `data` property values to inject. * * @memberOf _.templateSettings * @type {RegExp} */ interpolate: reInterpolate, /** * Used to reference the data object in the template text. * * @memberOf _.templateSettings * @type {string} */ variable: "", /** * Used to import variables into the compiled template. * * @memberOf _.templateSettings * @type {Object} */ imports: { /** * A reference to the `lodash` function. * * @memberOf _.templateSettings.imports * @type {Function} */ _: lodash2 } }, lodash2.prototype = baseLodash.prototype, lodash2.prototype.constructor = lodash2, LodashWrapper.prototype = baseCreate(baseLodash.prototype), LodashWrapper.prototype.constructor = LodashWrapper; function LazyWrapper(value) { this.__wrapped__ = value, this.__actions__ = [], this.__dir__ = 1, this.__filtered__ = !1, this.__iteratees__ = [], this.__takeCount__ = MAX_ARRAY_LENGTH, this.__views__ = []; } function lazyClone() { var result2 = new LazyWrapper(this.__wrapped__); return result2.__actions__ = copyArray(this.__actions__), result2.__dir__ = this.__dir__, result2.__filtered__ = this.__filtered__, result2.__iteratees__ = copyArray(this.__iteratees__), result2.__takeCount__ = this.__takeCount__, result2.__views__ = copyArray(this.__views__), result2; } function lazyReverse() { if (this.__filtered__) { var result2 = new LazyWrapper(this); result2.__dir__ = -1, result2.__filtered__ = !0; } else result2 = this.clone(), result2.__dir__ *= -1; return result2; } function lazyValue() { var array = this.__wrapped__.value(), dir = this.__dir__, isArr = isArray(array), isRight = dir < 0, arrLength = isArr ? array.length : 0, view = getView(0, arrLength, this.__views__), start = view.start, end = view.end, length = end - start, index = isRight ? end : start - 1, iteratees = this.__iteratees__, iterLength = iteratees.length, resIndex = 0, takeCount = nativeMin(length, this.__takeCount__); if (!isArr || !isRight && arrLength == length && takeCount == length) return baseWrapperValue(array, this.__actions__); var result2 = []; outer: for (; length-- && resIndex < takeCount; ) { index += dir; for (var iterIndex = -1, value = array[index]; ++iterIndex < iterLength; ) { var data = iteratees[iterIndex], iteratee2 = data.iteratee, type = data.type, computed = iteratee2(value); if (type == LAZY_MAP_FLAG) value = computed; else if (!computed) { if (type == LAZY_FILTER_FLAG) continue outer; break outer; } } result2[resIndex++] = value; } return result2; } LazyWrapper.prototype = baseCreate(baseLodash.prototype), LazyWrapper.prototype.constructor = LazyWrapper; function Hash(entries) { var index = -1, length = entries == null ? 0 : entries.length; for (this.clear(); ++index < length; ) { var entry = entries[index]; this.set(entry[0], entry[1]); } } function hashClear() { this.__data__ = nativeCreate ? nativeCreate(null) : {}, this.size = 0; } function hashDelete(key) { var result2 = this.has(key) && delete this.__data__[key]; return this.size -= result2 ? 1 : 0, result2; } function hashGet(key) { var data = this.__data__; if (nativeCreate) { var result2 = data[key]; return result2 === HASH_UNDEFINED ? undefined$1 : result2; } return hasOwnProperty.call(data, key) ? data[key] : undefined$1; } function hashHas(key) { var data = this.__data__; return nativeCreate ? data[key] !== undefined$1 : hasOwnProperty.call(data, key); } function hashSet(key, value) { var data = this.__data__; return this.size += this.has(key) ? 0 : 1, data[key] = nativeCreate && value === undefined$1 ? HASH_UNDEFINED : value, this; } Hash.prototype.clear = hashClear, Hash.prototype.delete = hashDelete, Hash.prototype.get = hashGet, Hash.prototype.has = hashHas, Hash.prototype.set = hashSet; function ListCache(entries) { var index = -1, length = entries == null ? 0 : entries.length; for (this.clear(); ++index < length; ) { var entry = entries[index]; this.set(entry[0], entry[1]); } } function listCacheClear() { this.__data__ = [], this.size = 0; } function listCacheDelete(key) { var data = this.__data__, index = assocIndexOf(data, key); if (index < 0) return !1; var lastIndex = data.length - 1; return index == lastIndex ? data.pop() : splice.call(data, index, 1), --this.size, !0; } function listCacheGet(key) { var data = this.__data__, index = assocIndexOf(data, key); return index < 0 ? undefined$1 : data[index][1]; } function listCacheHas(key) { return assocIndexOf(this.__data__, key) > -1; } function listCacheSet(key, value) { var data = this.__data__, index = assocIndexOf(data, key); return index < 0 ? (++this.size, data.push([key, value])) : data[index][1] = value, this; } ListCache.prototype.clear = listCacheClear, ListCache.prototype.delete = listCacheDelete, ListCache.prototype.get = listCacheGet, ListCache.prototype.has = listCacheHas, ListCache.prototype.set = listCacheSet; function MapCache(entries) { var index = -1, length = entries == null ? 0 : entries.length; for (this.clear(); ++index < length; ) { var entry = entries[index]; this.set(entry[0], entry[1]); } } function mapCacheClear() { this.size = 0, this.__data__ = { hash: new Hash(), map: new (Map2 || ListCache)(), string: new Hash() }; } function mapCacheDelete(key) { var result2 = getMapData(this, key).delete(key); return this.size -= result2 ? 1 : 0, result2; } function mapCacheGet(key) { return getMapData(this, key).get(key); } function mapCacheHas(key) { return getMapData(this, key).has(key); } function mapCacheSet(key, value) { var data = getMapData(this, key), size2 = data.size; return data.set(key, value), this.size += data.size == size2 ? 0 : 1, this; } MapCache.prototype.clear = mapCacheClear, MapCache.prototype.delete = mapCacheDelete, MapCache.prototype.get = mapCacheGet, MapCache.prototype.has = mapCacheHas, MapCache.prototype.set = mapCacheSet; function SetCache(values2) { var index = -1, length = values2 == null ? 0 : values2.length; for (this.__data__ = new MapCache(); ++index < length; ) this.add(values2[index]); } function setCacheAdd(value) { return this.__data__.set(value, HASH_UNDEFINED), this; } function setCacheHas(value) { return this.__data__.has(value); } SetCache.prototype.add = SetCache.prototype.push = setCacheAdd, SetCache.prototype.has = setCacheHas; function Stack(entries) { var data = this.__data__ = new ListCache(entries); this.size = data.size; } function stackClear() { this.__data__ = new ListCache(), this.size = 0; } function stackDelete(key) { var data = this.__data__, result2 = data.delete(key); return this.size = data.size, result2; } function stackGet(key) { return this.__data__.get(key); } function stackHas(key) { return this.__data__.has(key); } function stackSet(key, value) { var data = this.__data__; if (data instanceof ListCache) { var pairs = data.__data__; if (!Map2 || pairs.length < LARGE_ARRAY_SIZE - 1) return pairs.push([key, value]), this.size = ++data.size, this; data = this.__data__ = new MapCache(pairs); } return data.set(key, value), this.size = data.size, this; } Stack.prototype.clear = stackClear, Stack.prototype.delete = stackDelete, Stack.prototype.get = stackGet, Stack.prototype.has = stackHas, Stack.prototype.set = stackSet; function arrayLikeKeys(value, inherited) { var isArr = isArray(value), isArg = !isArr && isArguments(value), isBuff = !isArr && !isArg && isBuffer(value), isType = !isArr && !isArg && !isBuff && isTypedArray(value), skipIndexes = isArr || isArg || isBuff || isType, result2 = skipIndexes ? baseTimes(value.length, String) : [], length = result2.length; for (var key in value) (inherited || hasOwnProperty.call(value, key)) && !(skipIndexes && // Safari 9 has enumerable `arguments.length` in strict mode. (key == "length" || // Node.js 0.10 has enumerable non-index properties on buffers. isBuff && (key == "offset" || key == "parent") || // PhantomJS 2 has enumerable non-index properties on typed arrays. isType && (key == "buffer" || key == "byteLength" || key == "byteOffset") || // Skip index properties. isIndex(key, length))) && result2.push(key); return result2; } function arraySample(array) { var length = array.length; return length ? array[baseRandom(0, length - 1)] : undefined$1; } function arraySampleSize(array, n) { return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length)); } function arrayShuffle(array) { return shuffleSelf(copyArray(array)); } function assignMergeValue(object, key, value) { (value !== undefined$1 && !eq(object[key], value) || value === undefined$1 && !(key in object)) && baseAssignValue(object, key, value); } function assignValue(object, key, value) { var objValue = object[key]; (!(hasOwnProperty.call(object, key) && eq(objValue, value)) || value === undefined$1 && !(key in object)) && baseAssignValue(object, key, value); } function assocIndexOf(array, key) { for (var length = array.length; length--; ) if (eq(array[length][0], key)) return length; return -1; } function baseAggregator(collection, setter, iteratee2, accumulator) { return baseEach(collection, function(value, key, collection2) { setter(accumulator, value, iteratee2(value), collection2); }), accumulator; } function baseAssign(object, source) { return object && copyObject(source, keys(source), object); } function baseAssignIn(object, source) { return object && copyObject(source, keysIn(source), object); } function baseAssignValue(object, key, value) { key == "__proto__" && defineProperty ? defineProperty(object, key, { configurable: !0, enumerable: !0, value, writable: !0 }) : object[key] = value; } function baseAt(object, paths) { for (var index = -1, length = paths.length, result2 = Array2(length), skip = object == null; ++index < length; ) result2[index] = skip ? undefined$1 : get(object, paths[index]); return result2; } function baseClamp(number, lower, upper) { return number === number && (upper !== undefined$1 && (number = number <= upper ? number : upper), lower !== undefined$1 && (number = number >= lower ? number : lower)), number; } function baseClone(value, bitmask, customizer, key, object, stack) { var result2, isDeep = bitmask & CLONE_DEEP_FLAG, isFlat = bitmask & CLONE_FLAT_FLAG, isFull = bitmask & CLONE_SYMBOLS_FLAG; if (customizer && (result2 = object ? customizer(value, key, object, stack) : customizer(value)), result2 !== undefined$1) return result2; if (!isObject(value)) return value; var isArr = isArray(value); if (isArr) { if (result2 = initCloneArray(value), !isDeep) return copyArray(value, result2); } else { var tag = getTag(value), isFunc = tag == funcTag || tag == genTag;