text: /*!
    * pinia v2.0.0-beta.3
    * (c) 2021 Eduardo San Martin Morote
    * @license MIT
    */
  'use strict';
  
  Object.defineProperty(exports, '__esModule', { value: true });
  
  var vue = require('vue');
  require('@vue/devtools-api');
  
  /**
   * setActivePinia must be called to handle SSR at the top of functions like
   * `fetch`, `setup`, `serverPrefetch` and others
   */
  let activePinia;
  /**
   * Sets or unsets the active pinia. Used in SSR and internally when calling
   * actions and getters
   *
   * @param pinia - Pinia instance
   */
  const setActivePinia = (pinia) => (activePinia = pinia);
  /**
   * Get the currently active pinia
   */
  const getActivePinia = () => {
      return activePinia;
  };
  /**
   * Map of stores based on a Pinia instance. Allows setting and retrieving stores
   * for the current running application (with its pinia).
   */
  const storesMap = new WeakMap();
  const piniaSymbol = (/* istanbul ignore next */ Symbol());
  
  function isPlainObject(
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  o) {
      return (o &&
          typeof o === 'object' &&
          Object.prototype.toString.call(o) === '[object Object]' &&
          typeof o.toJSON !== 'function');
  }
  // type DeepReadonly<T> = { readonly [P in keyof T]: DeepReadonly<T[P]> }
  /**
   * Possible types for SubscriptionCallback
   */
  exports.MutationType = void 0;
  (function (MutationType) {
      /**
       * Direct mutation of the state:
       *
       * - `store.name = 'new name'`
       * - `store.$state.name = 'new name'`
       * - `store.list.push('new item')`
       */
      MutationType["direct"] = "direct";
      /**
       * Mutated the state with `$patch` and an object
       *
       * - `store.$patch({ name: 'newName' })`
       */
      MutationType["patchObject"] = "patch object";
      /**
       * Mutated the state with `$patch` and a function
       *
       * - `store.$patch(state => state.name = 'newName')`
       */
      MutationType["patchFunction"] = "patch function";
      // maybe reset? for $state = {} and $reset
  })(exports.MutationType || (exports.MutationType = {}));
  
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  
  var FileSaver_min = {exports: {}};
  
  (function (module, exports) {
  (function(a,b){b();})(commonjsGlobal,function(){function b(a,b){return "undefined"==typeof b?b={autoBom:!1}:"object"!=typeof b&&(console.warn("Deprecated: Expected third argument to be a object"),b={autoBom:!b}),b.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(a.type)?new Blob(["\uFEFF",a],{type:a.type}):a}function c(a,b,c){var d=new XMLHttpRequest;d.open("GET",a),d.responseType="blob",d.onload=function(){g(d.response,b,c);},d.onerror=function(){console.error("could not download file");},d.send();}function d(a){var b=new XMLHttpRequest;b.open("HEAD",a,!1);try{b.send();}catch(a){}return 200<=b.status&&299>=b.status}function e(a){try{a.dispatchEvent(new MouseEvent("click"));}catch(c){var b=document.createEvent("MouseEvents");b.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),a.dispatchEvent(b);}}var f="object"==typeof window&&window.window===window?window:"object"==typeof self&&self.self===self?self:"object"==typeof commonjsGlobal&&commonjsGlobal.global===commonjsGlobal?commonjsGlobal:void 0,a=f.navigator&&/Macintosh/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent)&&!/Safari/.test(navigator.userAgent),g=f.saveAs||("object"!=typeof window||window!==f?function(){}:"download"in HTMLAnchorElement.prototype&&!a?function(b,g,h){var i=f.URL||f.webkitURL,j=document.createElement("a");g=g||b.name||"download",j.download=g,j.rel="noopener","string"==typeof b?(j.href=b,j.origin===location.origin?e(j):d(j.href)?c(b,g,h):e(j,j.target="_blank")):(j.href=i.createObjectURL(b),setTimeout(function(){i.revokeObjectURL(j.href);},4E4),setTimeout(function(){e(j);},0));}:"msSaveOrOpenBlob"in navigator?function(f,g,h){if(g=g||f.name||"download","string"!=typeof f)navigator.msSaveOrOpenBlob(b(f,h),g);else if(d(f))c(f,g,h);else {var i=document.createElement("a");i.href=f,i.target="_blank",setTimeout(function(){e(i);});}}:function(b,d,e,g){if(g=g||open("","_blank"),g&&(g.document.title=g.document.body.innerText="downloading..."),"string"==typeof b)return c(b,d,e);var h="application/octet-stream"===b.type,i=/constructor/i.test(f.HTMLElement)||f.safari,j=/CriOS\/[\d]+/.test(navigator.userAgent);if((j||h&&i||a)&&"undefined"!=typeof FileReader){var k=new FileReader;k.onloadend=function(){var a=k.result;a=j?a:a.replace(/^data:[^;]*;/,"data:attachment/file;"),g?g.location.href=a:location=a,g=null;},k.readAsDataURL(b);}else {var l=f.URL||f.webkitURL,m=l.createObjectURL(b);g?g.location=m:location.href=m,g=null,setTimeout(function(){l.revokeObjectURL(m);},4E4);}});f.saveAs=g.saveAs=g,(module.exports=g);});
  
  
  }(FileSaver_min));
  
  const IS_CLIENT = typeof window !== 'undefined';
  
  /**
   * Creates a Pinia instance to be used by the application
   */
  function createPinia() {
      // NOTE: here we could check the window object for a state and directly set it
      // if there is anything like it with Vue 3 SSR
      const state = vue.ref({});
      let localApp;
      let _p = [];
      // plugins added before calling app.use(pinia)
      const toBeInstalled = [];
      const pinia = vue.markRaw({
          install(app) {
              pinia._a = localApp = app;
              app.provide(piniaSymbol, pinia);
              app.config.globalProperties.$pinia = pinia;
              if (IS_CLIENT) {
                  // this allows calling useStore() outside of a component setup after
                  // installing pinia's plugin
                  setActivePinia(pinia);
              }
              toBeInstalled.forEach((plugin) => _p.push(plugin));
          },
          use(plugin) {
              if (!localApp) {
                  toBeInstalled.push(plugin);
              }
              else {
                  _p.push(plugin);
              }
              return this;
          },
          _p,
          // it's actually undefined here
          _a: localApp,
          state,
      });
      return pinia;
  }
  
  function innerPatch(target, patchToApply) {
      // TODO: get all keys like symbols as well
      for (const key in patchToApply) {
          const subPatch = patchToApply[key];
          const targetValue = target[key];
          if (isPlainObject(targetValue) &&
              isPlainObject(subPatch) &&
              !vue.isRef(subPatch) &&
              !vue.isReactive(subPatch)) {
              target[key] = innerPatch(targetValue, subPatch);
          }
          else {
              // @ts-ignore
              target[key] = subPatch;
          }
      }
      return target;
  }
  const { assign } = Object;
  /**
   * Create an object of computed properties referring to
   *
   * @param rootStateRef - pinia.state
   * @param id - unique name
   */
  function computedFromState(rootStateRef, id) {
      // let asComputed = computed<T>()
      const reactiveObject = {};
      const state = rootStateRef.value[id];
      for (const key in state) {
          // @ts-expect-error: the key matches
          reactiveObject[key] = vue.computed({
              get: () => rootStateRef.value[id][key],
              set: (value) => (rootStateRef.value[id][key] = value),
          });
      }
      return reactiveObject;
  }
  /**
   * Creates a store with its state object. This is meant to be augmented with getters and actions
   *
   * @param id - unique identifier of the store, like a name. eg: main, cart, user
   * @param buildState - function to build the initial state
   * @param initialState - initial state applied to the store, Must be correctly typed to infer typings
   */
  function initStore($id, buildState = () => ({}), initialState) {
      const pinia = getActivePinia();
      pinia.state.value[$id] = initialState || buildState();
      // const state: Ref<S> = toRef(_p.state.value, $id)
      let isListening = true;
      let subscriptions = vue.markRaw([]);
      let actionSubscriptions = vue.markRaw([]);
      let debuggerEvents;
      function $patch(partialStateOrMutator) {
          let subscriptionMutation;
          isListening = false;
          if (typeof partialStateOrMutator === 'function') {
              partialStateOrMutator(pinia.state.value[$id]);
              subscriptionMutation = {
                  type: exports.MutationType.patchFunction,
                  storeId: $id,
                  events: debuggerEvents,
              };
          }
          else {
              innerPatch(pinia.state.value[$id], partialStateOrMutator);
              subscriptionMutation = {
                  type: exports.MutationType.patchObject,
                  payload: partialStateOrMutator,
                  storeId: $id,
                  events: debuggerEvents,
              };
          }
          isListening = true;
          // because we paused the watcher, we need to manually call the subscriptions
          subscriptions.forEach((callback) => {
              callback(subscriptionMutation, pinia.state.value[$id]);
          });
      }
      function $subscribe(callback) {
          subscriptions.push(callback);
          // watch here to link the subscription to the current active instance
          // e.g. inside the setup of a component
          const options = { deep: true, flush: 'sync' };
          const stopWatcher = vue.watch(() => pinia.state.value[$id], (state, oldState) => {
              if (isListening) {
                  callback({
                      storeId: $id,
                      type: exports.MutationType.direct,
                      events: debuggerEvents,
                  }, state);
              }
          }, options);
          const removeSubscription = () => {
              const idx = subscriptions.indexOf(callback);
              if (idx > -1) {
                  subscriptions.splice(idx, 1);
                  stopWatcher();
              }
          };
          if (vue.getCurrentInstance()) {
              vue.onUnmounted(removeSubscription);
          }
          return removeSubscription;
      }
      function $onAction(callback) {
          actionSubscriptions.push(callback);
          const removeSubscription = () => {
              const idx = actionSubscriptions.indexOf(callback);
              if (idx > -1) {
                  actionSubscriptions.splice(idx, 1);
              }
          };
          if (vue.getCurrentInstance()) {
              vue.onUnmounted(removeSubscription);
          }
          return removeSubscription;
      }
      function $reset() {
          pinia.state.value[$id] = buildState();
      }
      const storeWithState = {
          $id,
          _p: pinia,
          _as: actionSubscriptions,
          // $state is added underneath
          $patch,
          $subscribe,
          $onAction,
          $reset,
      };
      const injectionSymbol = /* istanbul ignore next */
              Symbol();
      return [
          storeWithState,
          {
              get: () => pinia.state.value[$id],
              set: (newState) => {
                  isListening = false;
                  pinia.state.value[$id] = newState;
                  isListening = true;
              },
          },
          injectionSymbol,
      ];
  }
  const noop = () => { };
  /**
   * Creates a store bound to the lifespan of where the function is called. This
   * means creating the store inside of a component's setup will bound it to the
   * lifespan of that component while creating it outside of a component will
   * create an ever living store
   *
   * @param partialStore - store with state returned by initStore
   * @param descriptor - descriptor to setup $state property
   * @param $id - unique name of the store
   * @param getters - getters of the store
   * @param actions - actions of the store
   */
  function buildStoreToUse(partialStore, descriptor, $id, getters = {}, actions = {}, options) {
      const pinia = getActivePinia();
      const computedGetters = {};
      for (const getterName in getters) {
          // @ts-ignore: it's only readonly for the users
          computedGetters[getterName] = vue.computed(() => {
              setActivePinia(pinia);
              // eslint-disable-next-line @typescript-eslint/no-use-before-define
              // @ts-expect-error: the argument count is correct
              return getters[getterName].call(store, store);
          });
      }
      const wrappedActions = {};
      for (const actionName in actions) {
          wrappedActions[actionName] = function () {
              setActivePinia(pinia);
              const args = Array.from(arguments);
              const localStore = this || store;
              let afterCallback = noop;
              let onErrorCallback = noop;
              function after(callback) {
                  afterCallback = callback;
              }
              function onError(callback) {
                  onErrorCallback = callback;
              }
              partialStore._as.forEach((callback) => {
                  // @ts-expect-error
                  callback({ args, name: actionName, store: localStore, after, onError });
              });
              let ret;
              try {
                  ret = actions[actionName].apply(localStore, args);
                  Promise.resolve(ret).then(afterCallback).catch(onErrorCallback);
              }
              catch (error) {
                  onErrorCallback(error);
                  throw error;
              }
              return ret;
          };
      }
      const store = vue.reactive(assign({}, partialStore, 
      // using this means no new properties can be added as state
      computedFromState(pinia.state, $id), computedGetters, wrappedActions));
      // use this instead of a computed with setter to be able to create it anywhere
      // without linking the computed lifespan to wherever the store is first
      // created.
      Object.defineProperty(store, '$state', descriptor);
      // apply all plugins
      pinia._p.forEach((extender) => {
          {
              // @ts-expect-error: conflict between A and ActionsTree
              assign(store, extender({ store, app: pinia._a, pinia, options }));
          }
      });
      return store;
  }
  /**
   * Creates a `useStore` function that retrieves the store instance
   * @param options - options to define the store
   */
  function defineStore(options) {
      const { id, state, getters, actions } = options;
      function useStore(pinia) {
          const currentInstance = vue.getCurrentInstance();
          // only run provide when pinia hasn't been manually passed
          const shouldProvide = currentInstance && !pinia;
          // avoid injecting if `useStore` when not possible
          pinia = pinia || (currentInstance && vue.inject(piniaSymbol));
          if (pinia)
              setActivePinia(pinia);
          // TODO: worth warning on server if no piniaKey as it can leak data
          pinia = getActivePinia();
          let stores = storesMap.get(pinia);
          if (!stores)
              storesMap.set(pinia, (stores = new Map()));
          let storeAndDescriptor = stores.get(id);
          let store;
          if (!storeAndDescriptor) {
              storeAndDescriptor = initStore(id, state, pinia.state.value[id]);
              // @ts-expect-error: annoying to type
              stores.set(id, storeAndDescriptor);
              store = buildStoreToUse(storeAndDescriptor[0], storeAndDescriptor[1], id, getters, actions, options);
              // allow children to reuse this store instance to avoid creating a new
              // store for each child
              if (shouldProvide) {
                  vue.provide(storeAndDescriptor[2], store);
              }
          }
          else {
              store =
                  (currentInstance && vue.inject(storeAndDescriptor[2], null)) ||
                      buildStoreToUse(storeAndDescriptor[0], storeAndDescriptor[1], id, getters, actions, options);
          }
          return store;
      }
      // needed by map helpers
      useStore.$id = id;
      return useStore;
  }
  
  function getCachedStore(vm, useStore) {
      const cache = '_pStores' in vm ? vm._pStores : (vm._pStores = {});
      const id = useStore.$id;
      return (cache[id] ||
          (cache[id] = useStore(vm.$pinia)));
  }
  let mapStoreSuffix = 'Store';
  /**
   * Changes the suffix added by `mapStores()`. Can be set to an empty string.
   * Defaults to `"Store"`. Make sure to extend the MapStoresCustomization
   * interface if you need are using TypeScript.
   *
   * @param suffix - new suffix
   */
  function setMapStoreSuffix(suffix // could be 'Store' but that would be annoying for JS
  ) {
      mapStoreSuffix = suffix;
  }
  /**
   * Allows using stores without the composition API (`setup()`) by generating an
   * object to be spread in the `computed` field of a component. It accepts a list
   * of store definitions.
   *
   * @example
   * ```js
   * export default {
   *   computed: {
   *     // other computed properties
   *     ...mapStores(useUserStore, useCartStore)
   *   },
   *
   *   created() {
   *     this.userStore // store with id "user"
   *     this.cartStore // store with id "cart"
   *   }
   * }
   * ```
   *
   * @param stores - list of stores to map to an object
   */
  function mapStores(...stores) {
      return stores.reduce((reduced, useStore) => {
          // @ts-ignore: $id is added by defineStore
          reduced[useStore.$id + mapStoreSuffix] = function () {
              return getCachedStore(this, useStore);
          };
          return reduced;
      }, {});
  }
  /**
   * Allows using state and getters from one store without using the composition
   * API (`setup()`) by generating an object to be spread in the `computed` field
   * of a component.
   *
   * @param useStore - store to map from
   * @param keysOrMapper - array or object
   */
  function mapState(useStore, keysOrMapper) {
      return Array.isArray(keysOrMapper)
          ? keysOrMapper.reduce((reduced, key) => {
              reduced[key] = function () {
                  // @ts-expect-error
                  return getCachedStore(this, useStore)[key];
              };
              return reduced;
          }, {})
          : Object.keys(keysOrMapper).reduce((reduced, key) => {
              reduced[key] = function () {
                  const store = getCachedStore(this, useStore);
                  const storeKey = keysOrMapper[key];
                  // for some reason TS is unable to infer the type of storeKey to be a
                  // function
                  return typeof storeKey === 'function'
                      ? storeKey.call(this, store)
                      : store[storeKey];
              };
              return reduced;
          }, {});
  }
  /**
   * Alias for `mapState()`. You should use `mapState()` instead.
   * @deprecated use `mapState()` instead.
   */
  const mapGetters = mapState;
  /**
   * Allows directly using actions from your store without using the composition
   * API (`setup()`) by generating an object to be spread in the `methods` field
   * of a component.
   *
   * @param useStore - store to map from
   * @param keysOrMapper - array or object
   */
  function mapActions(useStore, keysOrMapper) {
      return Array.isArray(keysOrMapper)
          ? keysOrMapper.reduce((reduced, key) => {
              // @ts-expect-error
              reduced[key] = function (...args) {
                  // @ts-expect-error
                  return getCachedStore(this, useStore)[key](...args);
              };
              return reduced;
          }, {})
          : Object.keys(keysOrMapper).reduce((reduced, key) => {
              // @ts-expect-error
              reduced[key] = function (...args) {
                  // @ts-expect-error
                  return getCachedStore(this, useStore)[keysOrMapper[key]](...args);
              };
              return reduced;
          }, {});
  }
  /**
   * Allows using state and getters from one store without using the composition
   * API (`setup()`) by generating an object to be spread in the `computed` field
   * of a component.
   *
   * @param useStore - store to map from
   * @param keysOrMapper - array or object
   */
  function mapWritableState(useStore, keysOrMapper) {
      return Array.isArray(keysOrMapper)
          ? keysOrMapper.reduce((reduced, key) => {
              // @ts-ignore
              reduced[key] = {
                  get() {
                      // @ts-expect-error
                      return getCachedStore(this, useStore)[key];
                  },
                  set(value) {
                      // it's easier to type it here as any
                      // @ts-expect-error
                      return (getCachedStore(this, useStore)[key] = value);
                  },
              };
              return reduced;
          }, {})
          : Object.keys(keysOrMapper).reduce((reduced, key) => {
              // @ts-ignore
              reduced[key] = {
                  get() {
                      // @ts-expect-error
                      return getCachedStore(this, useStore)[keysOrMapper[key]];
                  },
                  set(value) {
                      // it's easier to type it here as any
                      // @ts-expect-error
                      return (getCachedStore(this, useStore)[keysOrMapper[key]] =
                          value);
                  },
              };
              return reduced;
          }, {});
  }
  
  exports.createPinia = createPinia;
  exports.defineStore = defineStore;
  exports.mapActions = mapActions;
  exports.mapGetters = mapGetters;
  exports.mapState = mapState;
  exports.mapStores = mapStores;
  exports.mapWritableState = mapWritableState;
  exports.setActivePinia = setActivePinia;
  exports.setMapStoreSuffix = setMapStoreSuffix;
  