import{i as t}from"./vue-demi-71ba0ef2.js";import{ao as e,h as n,an as s,p as o,i as a,X as c,x as r,aw as i,ab as u,ax as f,g as p,f as l,n as h,ad as d,m as y}from"./@vue-37836d09.js"; /*! * pinia v2.3.1 * (c) 2025 Eduardo San Martin Morote * @license MIT */ /** * setActivePinia must be called to handle SSR at the top of functions like * `fetch`, `setup`, `serverPrefetch` and others */let b; /** * Sets or unsets the active pinia. Used in SSR and internally when calling * actions and getters * * @param pinia - Pinia instance */ // @ts-expect-error: cannot constrain the type of the return const v=t=>b=t,_=/* istanbul ignore next */Symbol();function m( // eslint-disable-next-line @typescript-eslint/no-explicit-any t){return t&&"object"==typeof t&&"[object Object]"===Object.prototype.toString.call(t)&&"function"!=typeof t.toJSON} // type DeepReadonly = { readonly [P in keyof T]: DeepReadonly } // TODO: can we change these to numbers? /** * Possible types for SubscriptionCallback */var j; /** * Creates a Pinia instance to be used by the application */ function O(){const o=e(!0),a=o.run((()=>n({}))); // 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 let c=[],r=[]; // plugins added before calling app.use(pinia) const i=s({install(t){ // this allows calling useStore() outside of a component setup after // installing pinia's plugin v(i),i._a=t,t.provide(_,i),t.config.globalProperties.$pinia=i,r.forEach((t=>c.push(t))),r=[]},use(e){return this._a||t?c.push(e):r.push(e),this},_p:c, // it's actually undefined here // @ts-expect-error _a:null,_e:o,_s:new Map,state:a});return i}!function(t){ /** * Direct mutation of the state: * * - `store.name = 'new name'` * - `store.$state.name = 'new name'` * - `store.list.push('new item')` */ t.direct="direct", /** * Mutated the state with `$patch` and an object * * - `store.$patch({ name: 'newName' })` */ t.patchObject="patch object", /** * Mutated the state with `$patch` and a function * * - `store.$patch(state => state.name = 'newName')` */ t.patchFunction="patch function"}(j||(j={}));const $=()=>{};function g(t,e,n,s=$){t.push(e);const o=()=>{const n=t.indexOf(e);n>-1&&(t.splice(n,1),s())};return!n&&p()&&l(o),o}function S(t,...e){t.slice().forEach((t=>{t(...e)}))}const P=t=>t() /** * Marks a function as an action for `$onAction` * @internal */,w=Symbol(),E=Symbol();function x(t,e){ // Handle Map instances t instanceof Map&&e instanceof Map?e.forEach(((e,n)=>t.set(n,e))):t instanceof Set&&e instanceof Set&& // Handle Set instances e.forEach(t.add,t); // no need to go through symbols because they cannot be serialized anyway for(const n in e){if(!e.hasOwnProperty(n))continue;const s=e[n],o=t[n];m(o)&&m(s)&&t.hasOwnProperty(n)&&!r(s)&&!i(s)? // NOTE: here I wanted to warn about inconsistent types but it's not possible because in setup stores one might // start the value of a property as a certain type e.g. a Map, and then for some reason, during SSR, change that // to `undefined`. When trying to hydrate, we want to override the Map with `undefined`. t[n]=x(o,s): // @ts-expect-error: subPatch is a valid value t[n]=s}return t}const I=/* istanbul ignore next */Symbol(); /** * Returns whether a value should be hydrated * * @param obj - target variable * @returns true if `obj` should be hydrated */const{assign:M}=Object;function A(t,s,o={},f,p,l){let d;const y=M({actions:{}},o),b={deep:!0}; // watcher options for $subscribe // internal state let _,O,A,F=[],k=[];// set to true at the end const z=f.state.value[t]; // avoid setting the state for option stores if it is set // by the setup // avoid triggering too many listeners // https://github.com/vuejs/pinia/issues/1129 let C;function J(e){let n;_=O=!1,"function"==typeof e?(e(f.state.value[t]),n={type:j.patchFunction,storeId:t,events:A}):(x(f.state.value[t],e),n={type:j.patchObject,payload:e,storeId:t,events:A});const s=C=Symbol();h().then((()=>{C===s&&(_=!0)})),O=!0, // because we paused the watcher, we need to manually call the subscriptions S(F,n,f.state.value[t])}l||z||(f.state.value[t]={}),n({});const N=l?function(){const{state:t}=o,e=t?t():{}; // we use a patch to group all changes into one single subscription this.$patch((t=>{ // @ts-expect-error: FIXME: shouldn't error? M(t,e)}))}:/* istanbul ignore next */ $; /** * Helper that wraps function so it can be tracked with $onAction * @param fn - action to wrap * @param name - name of the action */ const W=(e,n="")=>{if(w in e)return e[E]=n,e;const s=function(){v(f);const n=Array.from(arguments),o=[],a=[];let c; // @ts-expect-error S(k,{args:n,name:s[E],store:q,after:function(t){o.push(t)},onError:function(t){a.push(t)}});try{c=e.apply(this&&this.$id===t?this:q,n); // handle sync errors }catch(r){throw S(a,r),r}return c instanceof Promise?c.then((t=>(S(o,t),t))).catch((t=>(S(a,t),Promise.reject(t)))):( // trigger after callbacks S(o,c),c)};// will be set later // @ts-expect-error: we are intentionally limiting the returned type to just Fn // because all the added properties are internals that are exposed through `$onAction()` only return s[w]=!0,s[E]=n,s},X={_p:f, // _s: scope, $id:t,$onAction:g.bind(null,k),$patch:J,$reset:N,$subscribe(e,n={}){const s=g(F,e,n.detached,(()=>o())),o=d.run((()=>a((()=>f.state.value[t]),(s=>{("sync"===n.flush?O:_)&&e({storeId:t,type:j.direct,events:A},s)}),M({},b,n))));return s},$dispose:function(){d.stop(),F=[],k=[],f._s.delete(t)}},q=c(X); // store the partial store now so the setup of stores can instantiate each other before they are finished without // creating infinite loops. f._s.set(t,q);const B=(f._a&&f._a.runWithContext||P)((()=>f._e.run((()=>(d=e()).run((()=>s({action:W}))))))); // TODO: idea create skipSerialize that marks properties as non serializable and they are skipped // overwrite existing actions to support $onAction for(const e in B){const n=B[e];if(r(n)&&(!r(G=n)||!G.effect)||i(n)) // mark it as a piece of state to be serialized l||( // in setup stores we must hydrate the state and sync pinia state tree with the refs the user just created !z||m(D=n)&&D.hasOwnProperty(I)||(r(n)?n.value=z[e]: // probably a reactive object, lets recursively assign // @ts-expect-error: prop is unknown x(n,z[e])),f.state.value[t][e]=n); // action else if("function"==typeof n){const t=W(n,e); // this a hot module replacement store because the hotUpdate method needs // to do it with the right context /* istanbul ignore if */ // @ts-expect-error B[e]=t, // list actions so they can be used in plugins // @ts-expect-error y.actions[e]=n}} // add the state, getters, and action properties /* istanbul ignore if */var D,G;return M(q,B), // allows retrieving reactive objects with `storeToRefs()`. Must be called after assigning to the reactive object. // Make `storeToRefs()` work with `reactive()` #799 M(u(q),B), // 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(q,"$state",{get:()=>f.state.value[t],set:t=>{J((e=>{ // @ts-expect-error: FIXME: shouldn't error? M(e,t)}))}}), // apply all plugins f._p.forEach((t=>{M(q,d.run((()=>t({store:q,app:f._a,pinia:f,options:y}))))})), // only apply hydrate to option stores with an initial state in pinia z&&l&&o.hydrate&&o.hydrate(q.$state,z),_=!0,O=!0,q} // allows unused stores to be tree shaken /*! #__NO_SIDE_EFFECTS__ */function F( // TODO: add proper types from above t,e,n){let a,c;const r="function"==typeof e;function i(t,n){const i=f();(t= // in test mode, ignore the argument provided as we can always retrieve a // pinia instance with getActivePinia() t||(i?o(_,null):null))&&v(t),(t=b)._s.has(a)||( // creating the store registers it in `pinia._s` r?A(a,e,c,t):function(t,e,n){const{state:o,actions:a,getters:c}=e,r=n.state.value[t];let i;i=A(t,(function(){r||(n.state.value[t]=o?o():{}); // avoid creating a state in pinia.state.value const e=d(n.state.value[t]);return M(e,a,Object.keys(c||{}).reduce(((e,o)=>(e[o]=s(y((()=>{v(n); // it was created just before const e=n._s.get(t); // @ts-expect-error // return getters![name].call(context, context) // TODO: avoid reading the getter while assigning with a global variable return c[o].call(e,e)}))),e)),{}))}),e,n,0,!0)}(a,c,t)); // StoreGeneric cannot be casted towards Store return t._s.get(a)}return"string"==typeof t?(a=t, // the option store setup will contain the actual options in this case c=r?n:e):(c=t,a=t.id),i.$id=a,i}export{O as c,F as d}; //# sourceMappingURL=pinia-0c8641d4.js.map