{"version":3,"file":"vuex-persistedstate.umd.js","sources":["../node_modules/deepmerge/dist/cjs.js","../src/index.ts","../node_modules/shvl/dist/shvl.mjs"],"sourcesContent":["'use strict';\n\nvar isMergeableObject = function isMergeableObject(value) {\n\treturn isNonNullObject(value)\n\t\t&& !isSpecial(value)\n};\n\nfunction isNonNullObject(value) {\n\treturn !!value && typeof value === 'object'\n}\n\nfunction isSpecial(value) {\n\tvar stringValue = Object.prototype.toString.call(value);\n\n\treturn stringValue === '[object RegExp]'\n\t\t|| stringValue === '[object Date]'\n\t\t|| isReactElement(value)\n}\n\n// see https://github.com/facebook/react/blob/b5ac963fb791d1298e7f396236383bc955f916c1/src/isomorphic/classic/element/ReactElement.js#L21-L25\nvar canUseSymbol = typeof Symbol === 'function' && Symbol.for;\nvar REACT_ELEMENT_TYPE = canUseSymbol ? Symbol.for('react.element') : 0xeac7;\n\nfunction isReactElement(value) {\n\treturn value.$$typeof === REACT_ELEMENT_TYPE\n}\n\nfunction emptyTarget(val) {\n\treturn Array.isArray(val) ? [] : {}\n}\n\nfunction cloneUnlessOtherwiseSpecified(value, options) {\n\treturn (options.clone !== false && options.isMergeableObject(value))\n\t\t? deepmerge(emptyTarget(value), value, options)\n\t\t: value\n}\n\nfunction defaultArrayMerge(target, source, options) {\n\treturn target.concat(source).map(function(element) {\n\t\treturn cloneUnlessOtherwiseSpecified(element, options)\n\t})\n}\n\nfunction getMergeFunction(key, options) {\n\tif (!options.customMerge) {\n\t\treturn deepmerge\n\t}\n\tvar customMerge = options.customMerge(key);\n\treturn typeof customMerge === 'function' ? customMerge : deepmerge\n}\n\nfunction getEnumerableOwnPropertySymbols(target) {\n\treturn Object.getOwnPropertySymbols\n\t\t? Object.getOwnPropertySymbols(target).filter(function(symbol) {\n\t\t\treturn target.propertyIsEnumerable(symbol)\n\t\t})\n\t\t: []\n}\n\nfunction getKeys(target) {\n\treturn Object.keys(target).concat(getEnumerableOwnPropertySymbols(target))\n}\n\nfunction propertyIsOnObject(object, property) {\n\ttry {\n\t\treturn property in object\n\t} catch(_) {\n\t\treturn false\n\t}\n}\n\n// Protects from prototype poisoning and unexpected merging up the prototype chain.\nfunction propertyIsUnsafe(target, key) {\n\treturn propertyIsOnObject(target, key) // Properties are safe to merge if they don't exist in the target yet,\n\t\t&& !(Object.hasOwnProperty.call(target, key) // unsafe if they exist up the prototype chain,\n\t\t\t&& Object.propertyIsEnumerable.call(target, key)) // and also unsafe if they're nonenumerable.\n}\n\nfunction mergeObject(target, source, options) {\n\tvar destination = {};\n\tif (options.isMergeableObject(target)) {\n\t\tgetKeys(target).forEach(function(key) {\n\t\t\tdestination[key] = cloneUnlessOtherwiseSpecified(target[key], options);\n\t\t});\n\t}\n\tgetKeys(source).forEach(function(key) {\n\t\tif (propertyIsUnsafe(target, key)) {\n\t\t\treturn\n\t\t}\n\n\t\tif (propertyIsOnObject(target, key) && options.isMergeableObject(source[key])) {\n\t\t\tdestination[key] = getMergeFunction(key, options)(target[key], source[key], options);\n\t\t} else {\n\t\t\tdestination[key] = cloneUnlessOtherwiseSpecified(source[key], options);\n\t\t}\n\t});\n\treturn destination\n}\n\nfunction deepmerge(target, source, options) {\n\toptions = options || {};\n\toptions.arrayMerge = options.arrayMerge || defaultArrayMerge;\n\toptions.isMergeableObject = options.isMergeableObject || isMergeableObject;\n\t// cloneUnlessOtherwiseSpecified is added to `options` so that custom arrayMerge()\n\t// implementations can use it. The caller may not replace it.\n\toptions.cloneUnlessOtherwiseSpecified = cloneUnlessOtherwiseSpecified;\n\n\tvar sourceIsArray = Array.isArray(source);\n\tvar targetIsArray = Array.isArray(target);\n\tvar sourceAndTargetTypesMatch = sourceIsArray === targetIsArray;\n\n\tif (!sourceAndTargetTypesMatch) {\n\t\treturn cloneUnlessOtherwiseSpecified(source, options)\n\t} else if (sourceIsArray) {\n\t\treturn options.arrayMerge(target, source, options)\n\t} else {\n\t\treturn mergeObject(target, source, options)\n\t}\n}\n\ndeepmerge.all = function deepmergeAll(array, options) {\n\tif (!Array.isArray(array)) {\n\t\tthrow new Error('first argument should be an array')\n\t}\n\n\treturn array.reduce(function(prev, next) {\n\t\treturn deepmerge(prev, next, options)\n\t}, {})\n};\n\nvar deepmerge_1 = deepmerge;\n\nmodule.exports = deepmerge_1;\n","import { Store, MutationPayload } from \"vuex\";\nimport merge from \"deepmerge\";\nimport * as shvl from \"shvl\";\n\ninterface Storage {\n  getItem: (key: string) => any;\n  setItem: (key: string, value: any) => void;\n  removeItem: (key: string) => void;\n}\n\ninterface Options<State> {\n  key?: string;\n  paths?: string[];\n  reducer?: (state: State, paths: string[]) => object;\n  subscriber?: (\n    store: Store<State>\n    ) => (handler: (mutation: any, state: State) => void) => void;\n  storage?: Storage;\n  getState?: (key: string, storage: Storage) => any;\n  setState?: (key: string, state: any, storage: Storage) => void;\n  filter?: (mutation: MutationPayload) => boolean;\n  arrayMerger?: (state: any[], saved: any[]) => any;\n  rehydrated?: (store: Store<State>) => void;\n  fetchBeforeUse?: boolean;\n  overwrite?: boolean;\n  assertStorage?: (storage: Storage) => void | Error;\n}\n\nexport default function <State>(\n  options?: Options<State>\n): (store: Store<State>) => void {\n  options = options || {};\n\n  const storage = options.storage || (window && window.localStorage);\n  const key = options.key || \"vuex\";\n\n  function getState(key, storage) {\n    let value;\n\n    try {\n      return (value = storage.getItem(key)) && typeof value !== \"undefined\"\n        ? JSON.parse(value)\n        : undefined;\n    } catch (err) {}\n\n    return undefined;\n  }\n\n  function filter() {\n    return true;\n  }\n\n  function setState(key, state, storage) {\n    return storage.setItem(key, JSON.stringify(state));\n  }\n\n  function reducer(state, paths) {\n    return Array.isArray(paths)\n      ? paths.reduce(function (substate, path) {\n          return shvl.set(substate, path, shvl.get(state, path));\n        }, {})\n      : state;\n  }\n\n  function subscriber(store) {\n    return function (handler) {\n      return store.subscribe(handler);\n    };\n  }\n\n  const assertStorage =\n    options.assertStorage ||\n    (() => {\n      storage.setItem(\"@@\", 1);\n      storage.removeItem(\"@@\");\n    });\n\n  assertStorage(storage);\n\n  const fetchSavedState = () => (options.getState || getState)(key, storage);\n\n  let savedState;\n\n  if (options.fetchBeforeUse) {\n    savedState = fetchSavedState();\n  }\n\n  return function (store: Store<State>) {\n    if (!options.fetchBeforeUse) {\n      savedState = fetchSavedState();\n    }\n\n    if (typeof savedState === \"object\" && savedState !== null) {\n      store.replaceState(\n        options.overwrite\n          ? savedState\n          : merge(store.state, savedState, {\n              arrayMerge:\n                options.arrayMerger ||\n                function (store, saved) {\n                  return saved;\n                },\n              clone: false,\n            })\n      );\n      (options.rehydrated || function () {})(store);\n    }\n\n    (options.subscriber || subscriber)(store)(function (mutation, state) {\n      if ((options.filter || filter)(mutation)) {\n        (options.setState || setState)(\n          key,\n          (options.reducer || reducer)(state, options.paths),\n          storage\n        );\n      }\n    });\n  };\n}\n","function t(t,n,r){return void 0===(t=(n.split?n.split(\".\"):n).reduce(function(t,n){return t&&t[n]},t))?r:t}function n(t,n,r,e){return(n=n.split?n.split(\".\"):n).slice(0,-1).reduce(function(t,n){return t[n]=t[n]||{}},t)[n.pop()]=r,t}export{t as get,n as set};\n//# sourceMappingURL=shvl.mjs.map\n"],"names":["isMergeableObject","value","isNonNullObject","stringValue","Object","prototype","toString","call","$$typeof","REACT_ELEMENT_TYPE","isReactElement","isSpecial","Symbol","for","cloneUnlessOtherwiseSpecified","options","clone","deepmerge","Array","isArray","defaultArrayMerge","target","source","concat","map","element","getKeys","keys","getOwnPropertySymbols","filter","symbol","propertyIsEnumerable","getEnumerableOwnPropertySymbols","propertyIsOnObject","object","property","_","arrayMerge","sourceIsArray","destination","forEach","key","hasOwnProperty","propertyIsUnsafe","customMerge","getMergeFunction","mergeObject","all","array","Error","reduce","prev","next","storage","window","localStorage","assertStorage","setItem","removeItem","savedState","fetchSavedState","getState","getItem","JSON","parse","undefined","err","fetchBeforeUse","store","replaceState","overwrite","merge","state","arrayMerger","saved","rehydrated","subscriber","handler","subscribe","mutation","setState","stringify","reducer","paths","substate","path","t","n","r","e","split","slice","pop","shvl"],"mapp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