(function(r,a){typeof exports=="object"&&typeof module!="undefined"?module.exports=a():typeof define=="function"&&define.amd?define(a):(r=typeof globalThis!="undefined"?globalThis:r||self,r.piniaPersist=a())})(this,function(){"use strict";const r=typeof alert=="function",a=(e,t,n)=>{const s=e.storage,i=e.key||t.$id,f=r||(n==null?void 0:n.enforceCustomStorage);if(e.paths){const d=e.paths.reduce((c,g)=>(c[g]=t.$state[g],c),{});f&&s?s.setItem(i,JSON.stringify(d)):uni.setStorage({key:i,data:JSON.stringify(d)})}else f&&s?s.setItem(i,JSON.stringify(t.$state)):uni.setStorage({key:i,data:JSON.stringify(t.$state)})};var m=({options:e,store:t})=>{var n,s,i,f,d,c;if((n=e.persist)!=null&&n.enabled){const g=[{key:t.$id,storage:((s=e.persist)==null?void 0:s.H5Storage)||(window==null?void 0:window.sessionStorage)}],S=(f=(i=e.persist)==null?void 0:i.strategies)!=null&&f.length?(d=e.persist)==null?void 0:d.strategies:g;S.forEach(u=>{var h,p;const y=u.storage||((h=e.persist)==null?void 0:h.H5Storage)||(window==null?void 0:window.sessionStorage),l=u.key||t.$id;let o;r||((p=e.persist)==null?void 0:p.enforceCustomStorage)?o=y.getItem(l):o=uni.getStorageSync(l),o&&(t.$patch(JSON.parse(o)),a(u,t,e.persist))}),t.$subscribe(()=>{S.forEach(u=>{a(u,t,e.persist)})},{detached:!!((c=e.persist)!=null&&c.detached)})}};return m});
