{"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 {\n key?: string;\n paths?: string[];\n reducer?: (state: State, paths: string[]) => object;\n subscriber?: (\n store: Store\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) => void;\n fetchBeforeUse?: boolean;\n overwrite?: boolean;\n assertStorage?: (storage: Storage) => void | Error;\n}\n\nexport default function (\n options?: Options\n): (store: Store) => 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 const value = storage.getItem(key);\n\n try {\n return (typeof value === \"string\")\n ? JSON.parse(value) : (typeof value === \"object\")\n ? value : 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) {\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,r,e){return void 0===(t=(r.split?r.split(\".\"):r).reduce(function(t,r){return t&&t[r]},t))?e:t}function r(t,r,e,n){return!/^(__proto__|constructor|prototype)$/.test(r)&&((r=r.split?r.split(\".\"):r.slice(0)).slice(0,-1).reduce(function(t,r){return t[r]=t[r]||{}},t)[r.pop()]=e),t}export{t as get,r 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","getState","getItem","JSON","parse","undefined","err","setState","state","setItem","stringify","reducer","paths","substate","path","t","r","e","n","test","split","slice","pop","shvl","subscriber","store","handler","subscribe","assertStorage","removeItem","savedState","fetchSavedState","fetchBeforeUse","replaceState","overwrite","merge","arrayMerger","saved","rehydrated","mutation"],"mappings":"uOAEA,IAAIA,EAAoB,SAA2BC,GAClD,OAID,SAAyBA,GACxB,QAASA,GAA0B,iBAAVA,EALl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