@storesjs/stores 0.12.0 β†’ 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -500,6 +500,7 @@ type PersistConfig<S, PersistedState extends Partial<S> = Partial<S>, PersistRet
500
500
  partialize?: (state: Readonly<S>) => PersistedState;
501
501
  /**
502
502
  * The throttle rate for the persist operation in milliseconds.
503
+ * Applies to synchronous storage. Async storage batches updates without a timed delay.
503
504
  * @default iOS: time.seconds(3) | Android: time.seconds(5)
504
505
  */
505
506
  persistThrottleMs?: PersistReturn extends Promise<unknown> ? undefined : number;
@@ -509,8 +510,10 @@ type PersistConfig<S, PersistedState extends Partial<S> = Partial<S>, PersistRet
509
510
  */
510
511
  serializer?: (storageValue: StorageValue<PersistedState>) => string;
511
512
  /**
512
- * Custom storage implementation. If async, `setState` will return a Promise that resolves
513
- * when the state is persisted. If sync, `setState` will return void.
513
+ * Custom storage implementation. If async, `setState` returns a Promise that resolves
514
+ * after its batched persistence attempt completes. Storage and serialization failures are
515
+ * logged without rejecting the promise. Unchanged-state updates resolve immediately.
516
+ * If sync, `setState` returns void.
514
517
  */
515
518
  storage?: PersistReturn extends Promise<unknown> ? AsyncStorageInterface : SyncStorageInterface;
516
519
  /**
@@ -1473,11 +1476,11 @@ declare function createVirtualStore<Store extends BaseStore<InferStoreState<Stor
1473
1476
  * Handle returned by `useListen`.
1474
1477
  *
1475
1478
  * The hook cleans itself up, so you normally ignore this handle.
1476
- * Keep it only when you need to pause or resume the listener manually
1477
- * (e.g. suspend heavy work while a long-lived component is off screen).
1479
+ * Keep it when you need to refresh the selection or pause and resume the listener manually.
1478
1480
  */
1479
1481
  type ListenHandle = {
1480
- /** `true` while the listener is attached. */isActive: boolean; /** Re-attach the listener. */
1482
+ /** `true` while the listener is attached. */isActive: boolean; /** Re-evaluate the selector and notify if its value changed. Does nothing while detached. */
1483
+ refresh: () => void; /** Re-attach the listener. */
1481
1484
  resubscribe: (options?: ResubscribeOptions) => void; /** Detach the listener. Safe to call more than once. */
1482
1485
  unsubscribe: () => void;
1483
1486
  };
@@ -1535,7 +1538,7 @@ type Reaction<S, Selected> = (current: Selected, previous: Selected, get: () =>
1535
1538
  * effects, or deciding yourself if or when a render should happen.
1536
1539
  *
1537
1540
  * The hook attaches the listener and cleans it up automatically. Use the returned `ListenHandle`
1538
- * only when you need to pause or resume the listener manually.
1541
+ * to refresh the selection or pause and resume the listener manually.
1539
1542
  *
1540
1543
  * ---
1541
1544
  * πŸ’‘ **Note:** With the exception of `enabled`, changes in `options` are **not reactive**.
@@ -1545,7 +1548,7 @@ type Reaction<S, Selected> = (current: Selected, previous: Selected, get: () =>
1545
1548
  * @param store - Store to listen to. Should be a stable reference.
1546
1549
  * @param selector - Selects the slice of the store state to listen to.
1547
1550
  * @param react - Triggered when the selected slice changes. Receives `(current, previous, get, unsubscribe)`.
1548
- * @param optionsOrEqualityFn - Optional `equalityFn`, `fireImmediately` settings, forwarded to `store.subscribe`.
1551
+ * @param optionsOrEqualityFn - Equality function or listener options, including `enabled` and `fireImmediately`.
1549
1552
  *
1550
1553
  * ---
1551
1554
  * @example
@@ -3,5 +3,5 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
3
3
  Persisted stores require a storage backend. Either:
4
4
  - Install MMKV (the default): yarn add react-native-mmkv
5
5
  - Or provide a custom adapter via configureStores()
6
- `+(e instanceof Error?`\n${e.message}`:``))}return w(t),t}return{clearAll:()=>n().clearAll(),contains:e=>n().contains(e),delete:e=>n().delete(e),get:e=>n().get(e),getAllKeys:()=>n().getAllKeys(),set:(e,t)=>n().set(e,t)}}function C(e){let{createMMKV:t,MMKV:n}=require("react-native-mmkv");if(typeof t==`function`)return t({id:e});if(typeof n==`function`)return new n({id:e});throw Error(`[stores]: react-native-mmkv module does not export MMKV/createMMKV.`)}function w(e){if(!e||typeof e.get!=`function`||typeof e.set!=`function`||typeof e.delete!=`function`||typeof e.clearAll!=`function`)throw Error(`[stores]: Storage instance does not conform to expected interface`)}let T={debug:(e,t)=>{r&&console.debug(e,t)},error:(e,t)=>{r&&!i&&console.error(e,t)},info:(e,t)=>{r&&console.info(e,t)},warn:(e,t)=>{r&&console.warn(e,t)}};function E(e){T=e}const D=Object.prototype.hasOwnProperty;function O(e,t){return D.call(e,t)}function ee(e){let t=e.charCodeAt(0);if(t<48||t>57)return!1;let n=Number(e);return Number.isInteger(n)&&n<4294967295&&String(n)===e}function k(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function A(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var j=class extends Error{constructor(e,t){super(e),this.name=`StoresError`,t!==void 0&&Object.defineProperty(this,"cause",{configurable:!0,value:t,writable:!0})}};function M(e){return e instanceof Error?e:Error(String(e))}var te=class{destroy(){}publish(){}},N=class{constructor(){this.sessionId=`noop`}register(e){return new te}};let ne;function P(){return ne||(ne=new N),ne}let F,I,L=!1;function R(e){r&&ie(),e.logger&&E(e.logger),F??(F=V(e)),I??(I=H(e))}function z(){if(F)return F}function B(){return I??(I=H(void 0))}function re(){L=!0}function V(e){if(e?.queryStoreDefaults)return{queryStoreDefaults:e.queryStoreDefaults}}function H(e){return{storage:e?.storage??S(e?.storageKeyPrefix??`stores:`),syncEngine:e?.syncEngine??P()}}function ie(){if(L)throw Error(`[stores]: configureStores() called after first store creation. Call it earlier before creating any stores.`)}const U={Error:`error`,Idle:`idle`,Loading:`loading`,Success:`success`},W={ms:e=>{"worklet";return e},seconds:e=>{"worklet";return e*1e3},minutes:e=>{"worklet";return e*6e4},hours:e=>{"worklet";return e*36e5},days:e=>{"worklet";return e*864e5},weeks:e=>{"worklet";return e*6048e5},infinity:1/0,zero:0};let G;function ae(){return G??(G=oe())}function oe(){let e=z()?.queryStoreDefaults;return{abortInterruptedFetches:e?.abortInterruptedFetches??!0,cacheTime:e?.cacheTime??W.days(7),debugMode:e?.debugMode??!1,disableAutoRefetching:e?.disableAutoRefetching??!1,keepPreviousData:e?.keepPreviousData??!1,minStaleTime:e?.minStaleTime??!1,onError:e?.onError,paramChangeThrottle:e?.paramChangeThrottle??!1,retry:e?.retry??5,retryDelay:e?.retryDelay,staleTime:e?.staleTime??W.minutes(2),suppressStaleTimeWarning:e?.suppressStaleTimeWarning??!1}}function se(e,t){let n=t?.baseDelay??W.seconds(5),r=t?.maxDelay??W.minutes(5);return Math.min(n*2**e,r)}function K(e,t){return t[1]===!0?e(t[0],!0):e(t[0])}function ce(e,t,n){if(n===!0)return le(t)?t(e):t;let r=le(t)?t(e):t;return Object.is(r,e)?e:!A(e)||!A(r)?r:{...e,...r}}function le(e){return typeof e==`function`}function q(e){return typeof e==`object`&&!!e&&`__type`in e&&e.__type===`Map`}function ue(e){return typeof e==`object`&&!!e&&`__type`in e&&e.__type===`Set`}function de(e,t){return t instanceof Map?{__type:`Map`,entries:Array.from(t.entries())}:t instanceof Set?{__type:`Set`,values:Array.from(t)}:t}function fe(e,t){return q(t)?new Map(t.entries):ue(t)?new Set(t.values):t}const pe=Object.freeze({QueryStore:Symbol(`queryStore`),VirtualStore:Symbol(`virtualStore`)});function me(e,t){return Object.assign(e,{[t]:!0})}function he(e,t){J(e)?e.getState().reset(t?.clearQueryCache):ye(e)&&e.destroy()}function ge(e,t){for(let n of Array.isArray(e)?e:Object.values(e))!n||t?.skipDestroy?.(n)||he(n,t)}function _e(e){let t=ve(e);return Se(e)?e.persist.getOptions().name??t:t}function ve(e){return typeof e==`function`?e.name:``}function ye(e){return`destroy`in e}function be(e){return`getSnapshot`in e}function J(e){return pe.QueryStore in e}function xe(e){return`flushUpdates`in e}function Se(e){return!(`persist`in e)||!e.persist?!1:typeof e.persist.getOptions().name==`string`}function Ce(e){return pe.VirtualStore in e}function we(e,t){let n=Te(e);return t?Object.assign(n,t):n}function Te(e){let t=e.getState(),n=o(),i=n;if(r&&!(typeof t==`object`&&t))throw Error(`[createStoreActions]: State is not an object`);if(Ce(e))for(let n in t)De(t,n)&&(i[n]=Ee(e,n));else for(let e in t)De(t,e)&&(i[e]=t[e]);return n}function Ee(e,t){return function(...n){let r=e.getState()[t];if(typeof r==`function`)return r(...n);throw Error(`[createVirtualStoreAction]: Method ${String(t)} is not a function`)}}function De(e,t){return typeof e[t]==`function`}function Oe(e,t){"worklet";if(typeof e!=`object`||!e||e===void 0||typeof t!=`object`||!t||t===void 0)return e===t;if(Object.is(e,t))return!0;let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let r of n)if(!(r in t)||!Oe(e[r],t[r]))return!1;return!0}function ke(e,t){"worklet";if(typeof e!=`object`||!e||e===void 0||typeof t!=`object`||!t||t===void 0)return e===t;if(Object.is(e,t))return!0;let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let r of n)if(!Object.is(e[r],t[r]))return!1;return!0}function Ae(e,t){let n=Object.prototype.hasOwnProperty;function r(e,t){for(let n of e.keys())if(Ae(n,t))return n}let i,a,o;if(e===t)return!0;if(e&&t&&(i=e.constructor)===t.constructor){if(i===Date)return e.getTime()===t.getTime();if(i===RegExp)return e.toString()===t.toString();if(i===Array){if((a=e.length)===t.length)for(;a--&&Ae(e[a],t[a]););return a===-1}if(i===Set){if(e.size!==t.size)return!1;for(let n of e)if(o=n,o&&typeof o==`object`&&(o=r(t,o),!o)||!t.has(o))return!1;return!0}if(i===Map){if(e.size!==t.size)return!1;for(let n of e)if(o=n[0],o&&typeof o==`object`&&(o=r(t,o),!o)||!Ae(n[1],t.get(o)))return!1;return!0}if(i===ArrayBuffer)e=new Uint8Array(e),t=new Uint8Array(t);else if(i===DataView){if((a=e.byteLength)===t.byteLength)for(;a--&&e.getInt8(a)===t.getInt8(a););return a===-1}if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(t)){let n=e,r=t;if((a=n.byteLength)===r.byteLength)for(;a--&&n[a]===r[a];);return a===-1}if(!i||typeof e==`object`){a=0;for(let r in e)if(n.call(e,r)&&++a&&!n.call(t,r)||!(r in t)||!Ae(e[r],t[r]))return!1;return Object.keys(t).length===a}}return e!==e&&t!==t}function je(e,t,n){if(t===0)return n;if(t===1){if(e===n)return null;let t=new Set;return t.add(e),t.add(n),t}return e.add(n),e.size===t?null:e}function Me(e,t,n){if(t===0)return null;if(t===1)return e===n?void 0:null;if(!e.delete(n))return null;if(t!==2)return e;for(let t of e)return t}function Ne(e,t,n,r,i){if(t!==0){if(t===1){n(e,r,i);return}for(let t of e)n(t,r,i)}}function Pe(e,t){t>1&&e.clear()}const Fe=t.unstable_batchedUpdates;let Y=!1,Ie=!1,Le=!1,X,Re,ze=0;const Be=new Map;let Ve=0,He=null,Z=1/0;function Ue(){return Y}function We(){return He}function Ge(){Y||(Y=!0,!Le&&(Le=!0,queueMicrotask(()=>{Le=!1,Ke()})))}function Ke(){if(Y){if(Ie){Xe();return}Ie=!0;try{Fe(Xe)}finally{et()}}}function qe(){if(Y){if(Ie){He===null&&Ze();return}Ie=!0;try{Ze()}catch(e){throw et(),e}finally{Ie=!1,He=null}}}function Je(e){if(Y){if(Re){Re.push(e);return}if(!X){X=e;return}Re=[X,e],X=void 0}}function Ye(e,t){if(!Y)return;let n=t<0?0:t|0,r=Be.get(n);r||(r=[],Be.set(n,r)),r.push(e),Ve+=1,n<Z&&(Z=n)}function Xe(){for(;Ve>0||tt();)Ze(),$e()}function Ze(){for(;Ve>0;){let e=Z,t=Be.get(e);if(!t){Z=1/0;for(let e of Be.keys())e<Z&&(Z=e);continue}Be.delete(e),Ve-=t.length,Qe(),He=e;for(let e=0;e<t.length;e++)t[e]();He=null}}function Qe(){Z=1/0;for(let e of Be.keys())e<Z&&(Z=e)}function $e(){for(;;){let e=X;if(e){X=void 0,e();continue}let t=Re;if(!t)return;for(;ze<t.length;)t[ze++]();Re=void 0,ze=0;return}}function et(){Y=!1,Ie=!1,He=null,X=void 0,Re=void 0,ze=0,Be.clear(),Ve=0,Z=1/0}function tt(){return!!X||!!Re}const Q=Symbol(`stores.subscribeCascadeState`);function nt(e){return Q in e}function rt(e,t){nt(e)&&(e[Q]=t(e[Q]))}const it=Symbol(),at=Symbol();function ot(e){let t,n,r,i=0;function a(e,a,o){let s=ce(t,e,a);if(Object.is(s,t))return o===it?at:void 0;let c=t;if(t=s,Ne(r,i,l,t,c),n){Ke();for(let e of n)e(t,c)}}function o(){return t}function s(){return d}function c(e,t,n){return t?g(e,t,n):f(e)}let u={[Q]:m,getInitialState:s,getState:o,setState:a,subscribe:c},d=t=st(e)?e(a,o,u):e;return u;function f(e){return(n??(n=new Set)).add(e),()=>{n?.delete(e),n?.size===0&&(n=void 0)}}function p(e){let t=je(r,i,e);return t!==null&&(r=t,i+=1),()=>h(e)}function m(e){function t(t,n){Ge(),e(t,n)}return p(t)}function h(e){let t=Me(r,i,e);t!==null&&(r=t,--i)}function g(e,n,r){let i=r?.equalityFn??Object.is,a=r?.isCascadeParticipant??!1,o=e(t);function s(t){let r=e(t);if(i(o,r))return;let s=o;o=r,a&&Ge(),n(r,s)}return r?.fireImmediately&&n(o,o),a?p(s):f(s)}}function st(e){return typeof e==`function`}function ct(e){return!!e&&typeof e==`object`&&`then`in e&&typeof e.then==`function`}const lt=Object.freeze({migrated:!1,state:void 0});function ut(e,t,n){return(r,i,a)=>{let o=ft(t),s,c=!1,l=0,u,d,f;function p(e){return o.storage.setItem(o.name,e,o.version)}function m(e,t){return(t===!0?r(e,t,it):r(e,!1,it))===at?n?s??(s=Promise.resolve()):void 0:p(i())}a.setState=m;let h=e(m,i,a);a.getInitialState=()=>h;function g(){let e=x(),t=o.onRehydrateStorage?.(i()??h);try{let n=o.storage.getItem(o.name);return ct(n)?n.then(n=>_(e,n,t)).catch(n=>C(e,t,n)):_(e,n,t)}catch(n){C(e,t,n)}}return Object.assign(a,{persist:b()}),o.skipHydration||g(),u??h;function _(e,t,n){let r=dt(o,t);return ct(r)?r.then(t=>v(e,t,n)).catch(t=>C(e,n,t)):v(e,r,n)}function v(e,t,n){let r=y(e,t);if(ct(r))return r.then(()=>S(e,n));S(e,n)}function y(e,t){if(e!==l)return;let n=o.merge(t.state,i()??h);if(u=n,r(n,!0),t.migrated)return p(i())}function b(){return{clearStorage:()=>{o.storage.removeItem(o.name)},getOptions:()=>o,hasHydrated:()=>c,onFinishHydration:e=>(f??(f=new Set),f.add(e),()=>{f?.delete(e),f?.size===0&&(f=void 0)}),onHydrate:e=>(d??(d=new Set),d.add(e),()=>{d?.delete(e),d?.size===0&&(d=void 0)}),rehydrate:g,setOptions:e=>{o=ft({...o,...e,storage:e.storage??o.storage})}}}function x(){let e=++l;return c=!1,d?.forEach(e=>e(i()??h)),e}function S(e,t){if(e!==l)return;t?.(u,void 0);let n=i();u=n,c=!0,f?.forEach(e=>e(n))}function C(e,t,n){e===l&&t?.(void 0,n)}}}function dt(e,t){if(!t)return lt;if(typeof t.version!=`number`||t.version===e.version)return{migrated:!1,state:t.state};if(!e.migrate)return console.error(`State loaded from storage couldn't be migrated since no migrate function was provided`),lt;let n=e.migrate(t.state,t.version);return ct(n)?n.then(e=>({migrated:!0,state:e})):{migrated:!0,state:n}}function ft(e){return{...e,merge:e.merge??pt,skipHydration:e.skipHydration??!1}}function pt(e,t){return e===void 0?t:{...t,...e}}function mt(){let e=!1,t,n,r=new Promise((e,r)=>{t=e,n=r});function i(){e||!t||(e=!0,t(),t=void 0,n=void 0)}function a(r){e||!n||(e=!0,n(r),n=void 0,t=void 0)}function o(){return e}return{complete:i,isHydrated:o,fail:a,promise:r}}function ht(e){let t,n=!1,r,i;return{hydrationPromise:()=>n?t?.promise??r??(r=Promise.resolve()):(t||(t=mt()),t.promise),stateCreator:(r,a,o)=>{let s;function c(...e){return n?K(r,e):(t||(t=mt()),s||(s=[]),s.push(e),t.promise)}return i=()=>{if(s?.length){for(let e of s)K(o.setState,e);s=void 0}},e(c,a,o)},wrapOnRehydrateStorage:(e,r)=>a=>{let o=e?.(a);return(e,a)=>{n=!0,r?.onHydrationComplete?.(),i&&i(),r?.onHydrationFlushEnd?.(),a?t?.fail(M(a)):t?.complete(),o?.(e,a)}}}}function gt(e){let t,n=null;function r(...r){return t=r,n||(n=new Promise(r=>{queueMicrotask(async()=>{try{await e(...t)}finally{n=null,r()}})})),n}return r}const _t=Math.max,vt=Math.min;function yt(e,t=0,n={}){let r,i,a,o,s,c,l=0,u=!1,d=!1,f=!0;if(typeof e!=`function`)throw TypeError(`Expected a function`);t=xt(t)||0,St(n)&&(u=!!n.leading,d=`maxWait`in n,a=d?_t(xt(n.maxWait)||0,t):void 0,f=`trailing`in n?!!n.trailing:f);function p(t){let n=r,a=i;return r=i=void 0,l=t,o=n?e.apply(a,n):e.apply(a),o}function m(e){return l=e,s=setTimeout(_,t),u?p(e):o}function h(e){let n=e-(c??0),r=e-l,i=t-n;return d&&a!==void 0?vt(i,a-r):i}function g(e){let n=e-(c??0),r=e-l;return c===void 0||n>=t||n<0||d&&a!==void 0&&r>=a}function _(){let e=bt();if(g(e))return v(e);s=setTimeout(_,h(e))}function v(e){return s=void 0,f&&r?p(e):(r=i=void 0,o)}function y(){s!==void 0&&clearTimeout(s),l=0,r=c=i=s=void 0}function b(){return s===void 0?o:v(bt())}function x(...e){let n=bt(),a=g(n);if(r=e,i=this,c=n,a){if(s===void 0)return m(c);if(d)return clearTimeout(s),s=setTimeout(_,t),p(c)}return s===void 0&&(s=setTimeout(_,t)),o}return x.cancel=y,x.flush=b,x}function bt(){return typeof performance<`u`&&typeof performance.now==`function`?performance.now():Date.now()}function xt(e){if(typeof e==`number`)return e;if(typeof e==`symbol`||e===void 0)return NaN;if(typeof e==`object`&&e){let t=typeof e.valueOf==`function`?e.valueOf():e;e=typeof t==`object`?t+``:t}return typeof e==`string`?(e=e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,``),/^0b[01]+$/i.test(e)?parseInt(e.slice(2),2):/^0o[0-7]+$/i.test(e)?parseInt(e.slice(2),8):/^[-+]0x[0-9a-f]+$/i.test(e)?NaN:+e):e===0?e:+e}function St(e){let t=typeof e;return e!==null&&(t===`object`||t===`function`)}function Ct(e){if(!k(e))return e;let t=o(),n=Object.keys(e);for(let r=0;r<n.length;r++){let i=n[r],a=e[i];typeof a!=`function`&&(t[i]=a)}return t}function wt(e,t){try{return JSON.stringify(e,t?de:void 0)}catch(e){throw T.error(new j(`[createBaseStore]: Failed to serialize store data`,e)),e}}function Tt(e,t){try{return JSON.parse(e,t?fe:void 0)}catch(e){throw T.error(new j(`[createBaseStore]: Failed to deserialize persisted store data`,e)),e}}const Et=i?0:n?W.seconds(3):W.seconds(5);function Dt(e,t,n){let r=t??e.storage??B().storage,i=(e.sync?void 0:e.persistThrottleMs??Et)||void 0,a=e.version??0;return r.async?{async:!0,persistStorage:kt(r,e,i,n),version:a}:{async:!1,persistStorage:Ot(r,e,i,n),version:a}}function Ot(e,t,n,r){let i=!t.deserializer&&!t.serializer&&!e.deserializer&&!e.serializer,a=typeof t.sync==`object`&&(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata)===!0,o=t.partialize??Ct,s=t.deserializer??e.deserializer??At(i),c=t.serializer??e.serializer??jt(i);function l(t,n,i){try{if(It(r))return;let s={state:o(n),version:i},l=Nt(r,a,s),u=c(s);try{e.set(t,u),Pt(r,l)}catch(e){T.error(new j(`[createBaseStore]: Failed to persist store data`,e))}}catch(e){T.error(new j(`[createBaseStore]: Failed to persist store data`,e))}}let u=n===void 0?l:yt(l,n,{leading:!1,maxWait:n,trailing:!0});return{getItem:t=>{let n=e.get(t);return n===void 0?null:s(n)},setItem:(e,t,n)=>{r?.getIsApplyingRemote()||u(e,t,n)},removeItem:t=>{try{e.delete(t)}catch(e){T.error(new j(`[createBaseStore]: Failed to delete persisted store data`,e))}}}}function kt(e,t,n,r){let i=!t.deserializer&&!t.serializer&&!e.deserializer&&!e.serializer,a=typeof t.sync==`object`&&(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata)===!0,o=t.partialize??Ct,s=t.deserializer??e.deserializer??At(i),c=t.serializer??e.serializer??jt(i);async function l(t,n,i){try{if(It(r))return;let s={state:o(n),version:i},l=Nt(r,a,s),u=c(s);try{await e.set(t,u),Pt(r,l)}catch(e){T.error(new j(`[createBaseStore]: Failed to persist store data`,e))}}catch(e){T.error(new j(`[createBaseStore]: Failed to serialize persisted store data`,e))}}let u=n===void 0?gt(l):yt(l,n,{leading:!1,maxWait:n,trailing:!0});return{getItem:async t=>{let n=await e.get(t);return n===void 0?null:s(n)},setItem:async(e,t,n)=>{if(!r?.getIsApplyingRemote())return await u(e,t,n)},removeItem:async t=>{try{await e.delete(t)}catch(e){T.error(new j(`[createBaseStore]: Failed to delete persisted store data`,e))}}}}function At(e){return t=>{if(typeof t!=`string`)throw new j(`[createBaseStore]: Received non-string serialized state without a custom deserializer. Provide a deserializer on the store or storage adapter.`);return Tt(t,e)}}function jt(e){return t=>wt(t,e)}const Mt=Object.freeze({shouldClear:!1});function Nt(e,t,n){if(!t||!e)return Mt;let r=e.getFieldTimestampSnapshot();return Ft(e,n),n.syncMetadata?r&&Object.keys(r).length>0?(n.syncMetadata.fields=r,{fieldSnapshot:r,shouldClear:!0}):(delete n.syncMetadata.fields,{fieldSnapshot:r,shouldClear:!1}):{fieldSnapshot:r,shouldClear:!1}}function Pt(e,t){!e||!t.shouldClear||!t.fieldSnapshot||!Object.keys(t.fieldSnapshot).length||e.clearFieldTimestamps(t.fieldSnapshot)}function Ft(e,t){let n=e.getSessionId(),r=e.getTimestamp();n!==void 0&&r!==void 0&&(t.syncMetadata={origin:n,timestamp:r})}function It(e){return e?!!e.getIsApplyingRemote():!1}function Lt(e,t,n){let r=t.engine??B().syncEngine;return(i,a,s)=>{let c=new Map,l=[],u=[],d=null,f=!1,p=!1,m=0,h=null,g=[],_=Promise.resolve(),v=!n?.isAsync;function y(){let e=Date.now(),t=e>m?e:m+1;return m=t,t}function b(e,t){if(!(!n||!r.sessionId)&&(n.setSessionId(r.sessionId),n.setTimestamp(e),t.length>0)){let r=o();for(let n of t)r[String(n)]=e;n.mergeFieldTimestamps(r)}}function x(e,t,n,i=!1){let a=r.sessionId;for(let t of e)c.set(t,[n,a]);!d||!p?u.push({keys:e,replace:i,timestamp:n,values:t}):d.publish?.({replace:i,sessionId:a,timestamp:n,values:t})}function S(){if(!(!d||!u.length)){for(let e of u){let t=r.sessionId;for(let n of e.keys)c.set(n,[e.timestamp,t]);b(e.timestamp,e.keys),d.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values})}u.length=0}}function C(e,t){if(f||!h)return t?i(e,t):i(e);let n=y(),r,a,s=t?i(c,!0):i(c);if(!r||!a)return s;function c(i){let s=ce(i,e,t);for(let e of g)Object.is(s[e],i[e])||((r??(r=[])).push(e),(a??(a=o()))[e]=s[e]);return r&&b(n,r),s}return ct(s)?s.finally(x.bind(void 0,r,a,n,t)):(x(r,a,n,t),s)}let w=s.setState;s.setState=C;let E=e(C,a,s);if(g=t.fields??Bt(E),!g.length)return E;h=new Set(g);async function D(e){m=Math.max(m,e.timestamp);let r=o(),i=a(),s=e.timestamp,l;if(e.replace)for(let t of g)O(e.values,t)||zt(c.get(t),s,e.sessionId)&&(l??(l=[])).push(t);for(let n of g){if(!Ut(e.values,n)||!h?.has(n)||!zt(c.get(n),s,e.sessionId))continue;let a=t.merge?.[n];if(a){let t=e.values[n],o=i[n];if(t!==void 0){let l=a(t,o,i,e.values),u=o===void 0?t:o;if(!Ht(l,u)){T.error(new j(`[sync] Merge function for field "${String(n)}" returned ${Vt(l)} but expected ${Vt(u)}`));return}r[n]=l,c.set(n,[s,e.sessionId])}}else r[n]=e.values[n],c.set(n,[s,e.sessionId])}if(!(!(Object.keys(r).length>0)&&!l?.length)){f=!0,n?.setIsApplyingRemote(!0);try{if(e.replace){let e={...i},t=!1;if(l?.length){t=!0;for(let t of l)delete e[t],c.delete(t)}for(let n in r){if(!O(r,n))continue;let i=r[n];if(i===void 0)continue;Object.is(e[n],i)||(t=!0);let a=e;a[n]=i}if(!t)return;await(n?.setWithoutPersist??w)(e,!0)}else await(n?.setWithoutPersist??w)(r)}finally{f=!1,n?.setIsApplyingRemote(!1)}}}function ee(e){n?.isAsync?_=_.then(()=>D(e)):D(e)}function k(){if(!l.length)return;let e=l.slice();l.length=0;for(let t of e)ee(t)}if(d=r.register({apply:e=>{if(!v){l.push(e);return}ee(e)},fields:g,getState:a,key:t.key}),d?.onFirstSubscribe||d?.onLastUnsubscribe){let e=d,t=0,n=s.subscribe;function A(n){return t++===0&&e.onFirstSubscribe?.(),r=>{n(r),--t,t||queueMicrotask(()=>{t||e.onLastUnsubscribe?.()})}}s.subscribe=(...e)=>A(e.length===1?n(e[0]):n(e[0],e[1],e[2])),rt(s,e=>t=>A(e(t)))}function M(){p=!0,S()}function te(){v=!0,k()}return n?.isAsync?(n.onHydrationComplete=M,n.onHydrationFlushEnd=te):d.onHydrated?(d.onHydrated(M),te()):(M(),te()),E}}function Rt(e){let t,n,r,i=!1;function a(e){if(!(!e||!r)){for(let t of Object.entries(e)){let e=t[0],n=t[1];r[e]===n&&delete r[e]}Object.keys(r).length||(r=void 0)}}function o(){if(r)return{...r}}function s(e){if(!r){r={...e};return}for(let t of Object.entries(e)){let e=t[0],n=t[1],i=r[e];(i===void 0||n>i)&&(r[e]=n)}}return{isAsync:e,clearFieldTimestamps:a,getFieldTimestampSnapshot:o,getIsApplyingRemote:()=>i,getSessionId:()=>t,getTimestamp:()=>n,mergeFieldTimestamps:s,onHydrationComplete:void 0,onHydrationFlushEnd:void 0,setIsApplyingRemote:e=>i=e,setSessionId:e=>t=e,setTimestamp:e=>n=e,setWithoutPersist:void 0}}function zt(e,t,n){if(!e)return!0;let r=e[0],i=e[1];return t<r?!1:t>r?!0:n>i}function Bt(e){let t=[];for(let n of Object.keys(e))Wt(e,n)&&t.push(n);return t}function Vt(e){if(e===null)return`null`;let t=typeof e;return t===`object`?Object.prototype.toString.call(e):t}function Ht(e,t){if(!r)return!0;if(e===null||t===null)return e===t;let n=typeof e;return n===typeof t?n===`object`?Object.prototype.toString.call(e)===Object.prototype.toString.call(t):!0:!1}function Ut(e,t){return O(e,t)}function Wt(e,t){return typeof e[t]!=`function`}function Gt(e,t){if(re(),!t)return ot(e);let n=t.storageKey,r=typeof n==`string`,i=r?t.storage??B().storage:void 0,a=Kt(t.sync,n),o=!i||!a?void 0:Rt(i.async??!1),s=a?Lt(e,a,o):e;if(!r)return ot(s);let c=Dt(t,i,o),l=c.async?ht(s):void 0,u=l?l.wrapOnRehydrateStorage(t.onRehydrateStorage,o):t.onRehydrateStorage,d=ot(ut(l?(e,t,n)=>(o&&(o.setWithoutPersist=n.setState),l.stateCreator(e,t,n)):s,{merge:t.merge,migrate:t.migrate,name:n,onRehydrateStorage:u,storage:c.persistStorage,version:c.version},c.async));return l?Object.assign(d,{persist:Object.assign(d.persist,{hydrationPromise:l.hydrationPromise})}):d}function Kt(e,t){if(!e)return null;let n=typeof e==`object`,r=n?e.key??t:e===!0?t:e;if(!r)throw new j(`[createBaseStore]: sync requires a key to be specified either directly or via storageKey`);return n?{...e,key:r}:{key:r}}function qt(e,t,n=`s`){return t===1?e:`${e}${n}`}const Jt=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});var Yt=class{constructor(e){this.invalidate=e,this.stateDependencyRevisionStamp=0,this.stateDependencyRevision=0}beginRebuild(e){this.clearSelectors(e),this.stateDependencyRevision+=1}addSelector(e){let t=this.selectorUnsubscribes;if(!t){this.selectorUnsubscribes=e;return}if(typeof t==`function`){this.selectorUnsubscribes=[t,e];return}t.push(e)}retainState(e){let t=this.stateDependencies;if(t){let n=t.get(e);if(n){n.revision=this.stateDependencyRevision;return}t.set(e,this.createStateDependency(e));return}let n=this.stateDependencyStore;if(!n){this.stateDependencyStore=e,this.stateDependencyRevisionStamp=this.stateDependencyRevision,this.stateDependencyUnsubscribe=this.subscribeState(e);return}if(n===e){this.stateDependencyRevisionStamp=this.stateDependencyRevision;return}let r=this.stateDependencyUnsubscribe;this.stateDependencyStore=void 0,this.stateDependencyUnsubscribe=void 0,this.stateDependencies=new Map,r&&this.stateDependencies.set(n,{revision:this.stateDependencyRevisionStamp,unsubscribe:r}),this.stateDependencies.set(e,this.createStateDependency(e))}finishRebuild(e){this.stateDependencyStore&&this.stateDependencyRevisionStamp!==this.stateDependencyRevision&&(this.stateDependencyUnsubscribe?.(e),this.stateDependencyStore=void 0,this.stateDependencyUnsubscribe=void 0);let t=this.stateDependencies;if(t){for(let n of t){let r=n[1];r.revision!==this.stateDependencyRevision&&(r.unsubscribe(e),t.delete(n[0]))}if(!t.size){this.stateDependencies=void 0;return}if(t.size===1){for(let e of t){this.stateDependencyStore=e[0],this.stateDependencyRevisionStamp=e[1].revision,this.stateDependencyUnsubscribe=e[1].unsubscribe;break}this.stateDependencies=void 0}}}clear(e){this.clearSelectors(e),this.stateDependencyUnsubscribe?.(e),this.stateDependencyStore=void 0,this.stateDependencyUnsubscribe=void 0;let t=this.stateDependencies;if(t){for(let n of t)n[1].unsubscribe(e);this.stateDependencies=void 0}}get size(){let e=this.selectorUnsubscribes;return(typeof e==`function`?1:e?.length??0)+ +!!this.stateDependencyStore+(this.stateDependencies?.size??0)}clearSelectors(e){let t=this.selectorUnsubscribes;if(this.selectorUnsubscribes=void 0,t){if(typeof t==`function`){t(e);return}for(let n=0;n<t.length;n++)t[n](e)}}createStateDependency(e){return{revision:this.stateDependencyRevision,unsubscribe:this.subscribeState(e)}}subscribeState(e){return nt(e)?e[Q](this.invalidate):e.subscribe(a,this.invalidate,Jt)}},Xt=class{constructor(){this.watcherCount=0,this.ordinaryWatcherCount=0,this.cascadeParticipantCount=0,this.cascadeStateListenerCount=0}addWatcher(e){let t=je(this.watchers,this.watcherCount,e);return t===null?!1:(this.watchers=t,this.watcherCount+=1,en(e)?this.cascadeParticipantCount+=1:this.ordinaryWatcherCount+=1,!0)}deleteWatcher(e){let t=Me(this.watchers,this.watcherCount,e);return t===null?!1:(this.watchers=t,--this.watcherCount,en(e)?--this.cascadeParticipantCount:--this.ordinaryWatcherCount,!0)}addCascadeStateListener(e){let t=je(this.cascadeStateListeners,this.cascadeStateListenerCount,e);return t===null?!1:(this.cascadeStateListeners=t,this.cascadeParticipantCount+=1,this.cascadeStateListenerCount+=1,!0)}deleteCascadeStateListener(e){let t=Me(this.cascadeStateListeners,this.cascadeStateListenerCount,e);return t===null?!1:(this.cascadeStateListeners=t,--this.cascadeParticipantCount,--this.cascadeStateListenerCount,!0)}notifyCascade(e,t){Ne(this.cascadeStateListeners,this.cascadeStateListenerCount,l,e,t),this.cascadeParticipantCount!==this.cascadeStateListenerCount&&Ne(this.watchers,this.watcherCount,Zt,e,t)}notifyOrdinary(e,t){Ne(this.watchers,this.watcherCount,Qt,e,t)}clear(){this.watchers=Pe(this.watchers,this.watcherCount),this.cascadeStateListeners=Pe(this.cascadeStateListeners,this.cascadeStateListenerCount),this.watcherCount=0,this.ordinaryWatcherCount=0,this.cascadeParticipantCount=0,this.cascadeStateListenerCount=0}};function Zt(e,t,n){typeof e==`function`||!e.isCascadeParticipant||$t(e,t)}function Qt(e,t,n){if(typeof e==`function`){e(t,n);return}e.isCascadeParticipant||$t(e,t)}function $t(e,t){let n=e.selector(t);if(e.equalityFn(e.currentSlice,n))return;let r=e.currentSlice;e.currentSlice=n,e.listener(n,r)}function en(e){return typeof e!=`function`&&e.isCascadeParticipant}const tn=Symbol(`stores.deriveProxy.unwrap`);function nn(e,t,n,r){let i=n.get(e);if(fn(i))return i;let a=rn(t,e,r);return n.set(e,a),a}function rn(e,t,n,r=[]){return!e||typeof e!=`object`?(n(t,r,!0),e):an(e,r,t,n,new WeakSet,new WeakMap)}function an(e,t,n,r,i,a){let o=Array.isArray(e);return new Proxy(e,{get(s,c,l){if(c===tn)return r(n,t,!0),s;if(i.has(s))return Reflect.get(s,c,l);if(c===`__proto__`||typeof c==`symbol`)return c===Symbol.iterator&&(r(n,t,!0),i.add(s)),Reflect.get(s,c,l);if(o&&ee(c))return r(n,t,!0),i.add(s),Reflect.get(s,c,l);let u=Reflect.get(s,c,s),d=String(c),f=t.concat(d);if(typeof u==`function`)return O(s,c)?function(...e){return r(n,f,!0,{args:e.length?e:void 0}),Reflect.apply(u,s,e)}:(r(n,t,!0),u.bind(e));let p=!!u&&typeof u==`object`;return r(n,f,!p),p?(a.has(u)||a.set(u,an(u,f,n,r,i,a)),a.get(u)):u},getOwnPropertyDescriptor(e,a){return r(n,t,!0),i.add(e),Reflect.getOwnPropertyDescriptor(e,a)},has(e,i){return r(n,t,!0),Reflect.has(e,i)},ownKeys(e){return r(n,t,!0),i.add(e),Reflect.ownKeys(e)}})}function on(e,t){return!e||typeof e!=`object`?e:un(e)||(Array.isArray(e)?sn(e,t):k(e)&&cn(e,t),e)}function sn(e,t){let n=dn(e,t);if(n)for(let t=0;t<e.length;t++)ln(e,String(t),n)}function cn(e,t){let n=dn(e,t);if(n)for(let t of Reflect.ownKeys(e))ln(e,t,n)}function ln(e,t,n){let r=Reflect.getOwnPropertyDescriptor(e,t);if(!r||!(`value`in r))return;let i=on(r.value,n);i!==r.value&&(r.value=i,Reflect.defineProperty(e,t,r))}function un(e){let t=Reflect.get(e,tn);return t&&typeof t==`object`?t:void 0}function dn(e,t){let n=t??new WeakSet;return n.has(e)?null:(n.add(e),n)}function fn(e){return e!==void 0}const pn=Object.freeze([]);function mn(){let e,t,n;return{buildProxySubscriptions(r,i,a){let o=[],s=t,c=e;if(s&&c)_n(s,c,[],0,o,a);else if(n)for(let e of n)_n(e[1],e[0],[],0,o,a);xn(o,r,i)},reset(){e=void 0,t=void 0,n=void 0},trackPath(r,i,a,o){let s=t;if(s){let i=e;if(i!==r)if(!i)e=r;else{let a=n??(n=new Map);a.set(i,s),s=hn(),a.set(r,s),e=void 0,t=void 0}}else{let i=n;i?(s=i.get(r),s||(s=hn(),i.set(r,s))):(s=hn(),e=r,t=s)}gn(s,i,a,o)}}}function hn(){return o()}function gn(e,t,n,r){let i=e;for(let e=0;e<t.length;e++){let n=t[e],r=i.children,a;if(r)a=r[n],a||(a=r[n]=hn());else if(a=i.child,!a)a=hn(),i.child=a,i.childKey=n;else if(i.childKey!==n){let e=i.childKey;if(e===void 0)i.childKey=n;else{let t=hn();t[e]=a,a=t[n]=hn(),i.child=void 0,i.childKey=void 0,i.children=t}}i=a}n&&(i.isLeaf=!0),r&&vn(i,r)}function _n(e,t,n,r,i,a=2){let o=e.child;if(o){let s=e.childKey;if(e.isLeaf){if(bn(e,t,n,i),!o.invocation||s===void 0)return}else if(s===void 0){bn(e,t,n,i);return}n.push(s),_n(o,t,n,r+1,i,a),n.pop();return}let s=e.children;if(!s){bn(e,t,n,i);return}if(e.isLeaf||r>=a){bn(e,t,n,i);for(let e in s){let o=s[e];o.invocation&&(n.push(e),_n(o,t,n,r+1,i,a),n.pop())}return}for(let e in s)n.push(e),_n(s[e],t,n,r+1,i,a),n.pop()}function vn(e,t){let n=e.invocation;if(!n){e.invocation=t;return}if(yn(n,t))return;let r=e.extraInvocations;if(!r){e.extraInvocations=[t];return}for(let e=0;e<r.length;e++)if(yn(r[e],t))return;r.push(t)}function yn(e,t){let n=e.args,r=t.args,i=n?.length??0;if(i!==(r?.length??0))return!1;if(!n||!r)return!0;for(let e=0;e<i;e++)if(!Object.is(n[e],r[e]))return!1;return!0}function bn(e,t,n,r){let i=n.slice(),a=e.invocation;if(!a){r.push({store:t,path:i});return}r.push({store:t,path:i,invocation:a});let o=e.extraInvocations;if(o)for(let e=0;e<o.length;e++)r.push({store:t,path:i,invocation:o[e]})}function xn(e,t,n){for(let n of e){let e=n.invocation?Cn(n.path,n.invocation):Sn(n.path);t(n.store,e,n.path)}n&&Tn(e)}function Sn(e){return e.length?t=>wn(t,e):a}function Cn(e,t){let n=e.slice(0,-1),r=e[e.length-1];return e=>{let i=wn(e,n),a=i&&typeof i==`object`?Reflect.get(i,r):void 0;return typeof a==`function`?Reflect.apply(a,i,t.args??pn):void 0}}function wn(e,t){let n=e;for(let e=0;e<t.length;e++){if(!n||typeof n!=`object`)return n;n=Reflect.get(n,t[e])}return n}function Tn(e){let t=e.length;console.log(`[πŸ“‘ ${t} ${qt(`Proxy Subscription`,t)} πŸ“‘]:`,JSON.stringify(e.map(e=>{let t=En(e.store),n=e.path.join(`.`);if(!e.invocation)return n?`$(${t}).${n}`:`$(${t})`;let r=e.invocation.args?.length??0;return`$(${t}).${n}${r?`(${r}_${qt(`arg`,r)})`:`()`}`}),null,2))}function En(e){return`name`in e&&typeof e.name==`string`?e.name:`store`}const Dn=Symbol(),On=Symbol(),kn=Symbol(`stores.derivedStore.readDependencyState`);function An(e,t=Object.is){let n,i=!1,o,s=!1,c=!1;typeof t==`function`?o=t:(n=t.debounce,i=r?t.debugMode??!1:!1,o=t.equalityFn??Object.is,s=t.keepAlive??!1,c=t.lockDependencies??!1);let l=new Xt,u=new Yt(k),d=+!!s,f,p,m=Dn,h=!1,g=!1,_=!0,v=!0,y=null,b=On;function x(e,t,n){if(!v)return(t??a)(Nn(e));if(!d)return(t??a)(e.getState());if(!t){let t=Nn(e);return!t||typeof t!=`object`?(u.retainState(e),t):(f||(f=new WeakMap),p||(p=mn()),nn(e,t,f,p.trackPath))}let r=n?{equalityFn:n,isCascadeParticipant:!0}:Jt;return u.addSelector(e.subscribe(t,k,r)),t(Nn(e))}function S(){if(!_&&$(m))return m;_=!1,v&&u.beginRebuild(!0);let t=!0,n=m,r=$(n);g=!0;try{let a=e(x),s=p?on(a):a;r&&o(n,s)?(i&&console.log(`[πŸ₯· Derive Complete πŸ₯·]: No change detected`),t=!1,m=n):m=s}finally{g=!1,v&&u.finishRebuild(!0)}let a=i&&(!r||i===`verbose`&&v);if(a){r?i===`verbose`&&console.log(`[πŸŒ€ Rebuilding Subscriptions πŸŒ€]: Created…`):console.log(`[πŸŒ€ Initial Derive Complete πŸŒ€]: Created…`);let e=u.size;console.log(`[🎯 ${e} ${qt(`Selector Subscription`,e)} 🎯]`)}return p&&v&&(p.buildProxySubscriptions((e,t)=>{u.addSelector(e.subscribe(t,k,Jt))},a),f=void 0,c?p=void 0:p.reset()),t&&r&&C(m,n),c&&(v=!1),m}function C(e,t){let n=l.cascadeParticipantCount,r=n>0&&l.ordinaryWatcherCount>0,a=l.ordinaryWatcherCount>0&&(r||We()!==null||Ue());if(r&&Ge(),i){let e=l.ordinaryWatcherCount+n;console.log(`[πŸ“» Derive Complete πŸ“»]: Notifying ${e} ${qt(`watcher`,e)}`)}if(n&&l.notifyCascade(e,t),l.ordinaryWatcherCount){if(a){b===On?(b=t,Je(w)):$(b)||(b=t);return}l.notifyOrdinary(e,t)}}function w(){d&&_&&!l.cascadeParticipantCount&&S();let e=b;b=On,l.ordinaryWatcherCount&&$(m)&&e!==On&&$(e)&&l.notifyOrdinary(m,e)}let T=n?yt(D,typeof n==`number`?n:n.delay,typeof n==`number`?{leading:!1,maxWait:n,trailing:!0}:n):void 0,E=T??(()=>{h||(h=!0,queueMicrotask(D))});function D(){if(h=!1,!d){s||P();return}_&&S()}function O(e){if(e!==void 0&&(e||T&&_)){queueMicrotask(O);return}!d&&!s&&P()}function ee(){let e=y;e===We()&&(D(),y===e&&(y=null))}function k(){if(!g){if(!T){if(l.cascadeParticipantCount){_=!0,Ge();let e=We(),t=e===null?0:e+1;if(y!==null&&t<=y)return;y=t,Ye(ee,t);return}if(_)return;if(_=!0,Ue()){b===On&&(b=Dn,Je(w));return}}_||(_=!0,y=null,E())}}function A(e){d+=1;try{return e()}finally{--d}}function j(){return _||!$(m)?d?S():A(S):(h&&d&&D(),m)}function M(){return Ue()&&We()===null&&qe(),_||!$(m)?d?S():e(x):m}function te(...e){if(e.length===1){let t=e[0];return l.addWatcher(t)&&(d+=1),$(m)||M(),()=>{l.deleteWatcher(t)&&(--d,d||O(!1))}}let[t,n,r]=e,i=r?.equalityFn??Object.is,a=r?.isCascadeParticipant??!1,o=t(d?M():A(M)),s={currentSlice:o,equalityFn:i,isCascadeParticipant:a,listener:n,selector:t};return l.addWatcher(s),d+=1,r?.fireImmediately&&n(o,o),()=>{l.deleteWatcher(s)&&(--d,d||O(a))}}function N(e){return d?M():A(M),l.addCascadeStateListener(e)&&(d+=1),()=>{l.deleteCascadeStateListener(e)&&(--d,d||O(!0))}}function ne(){d&&(T?T.flush():_&&S())}function P(){T?.cancel(),u.clear(),l.clear(),d=0,p=void 0,f=void 0,v=!0,h=!1,g=!1,_=!0,m=Dn,b=On,y=null}function F(){return _||h||!$(m)?d?S():A(S):m}return{[kn]:F,[Q]:N,destroy:P,flushUpdates:ne,getSnapshot:j,getState:M,subscribe:te,getInitialState:jn,setState:Mn}}function jn(){throw Error(`[createDerivedStore]: getInitialState() is not available on derived stores.`)}function Mn(){throw Error(`[createDerivedStore]: setState() is not available on derived stores.`)}function Nn(e){let t=e[kn];return t?t():e.getState()}function $(e){return e!==Dn}var Pn=class{constructor(e){this.count=0,this.lastSubscriptionTime=null,this.fetchThrottleMs=null,this.onSubscribe=null,this.onLastUnsubscribe=null,e&&(this.fetchThrottleMs=W.seconds(5))}init({onSubscribe:e,onLastUnsubscribe:t}){this.onSubscribe=e,this.onLastUnsubscribe=t}hasSubscribers(){return this.count>0}subscribe(){let e=this.count===0,t=this.fetchThrottleMs!==null,n=t&&this.lastSubscriptionTime!==null&&!e&&Date.now()-this.lastSubscriptionTime<=this.fetchThrottleMs;return this.count+=1,this.onSubscribe?.(e,n),t&&(this.lastSubscriptionTime=Date.now()),e=>{let t=this.count===1;this.count=Math.max(this.count-1,0),t&&(this.onLastUnsubscribe?.(e),this.lastSubscriptionTime=null)}}};function Fn(e,t=queueMicrotask){let n=!1,r;function i(){n=!1,e(...r)}function a(...e){r=e,!n&&(n=!0,t(i))}return a}const In=Symbol(`stores.queryParamConfig`);function Ln(e,t){return{[In]:!0,key:t.key,value:e}}function Rn(e){return!!e&&typeof e==`object`&&In in e}function zn(e){return JSON.stringify(Vn(e))}function Bn(e){return JSON.parse(e)}function Vn(e){return typeof e!=`object`||!e?e:Object.keys(e).sort().reduce((t,n)=>{let r=e[n];return t[n]=k(r)?Vn(r):r,t},o())}const Hn=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});function Un(e,t,n){let r=o(),i=null,a=!1;if(e)for(let n in e){if(!O(e,n))continue;let s=Wn(r,e[n],n,t);s&&((i??(i=o()))[n]=s,s.key!==void 0&&(a=!0))}return{buildKey(e=r){return zn(a?Yn(i,e):e)},complete(e){return e?Qn(e,n)?e:{...r,...e}:qn(r)},get(){return qn(r)},subscribe(e){return Jn(i,r,e)}}}function Wn(e,t,n,r){return Rn(t)?Kn(e,t.value,n,r,t.key):Kn(e,t,n,r)}function Gn(e,t){let n=[],r,i;function o(e,t,a){return t?(n.push(n=>e.subscribe(t,n,Xn(a))),t(Zn(e))):(r??(r=mn()),i??(i=new WeakMap),nn(e,Zn(e),i,r.trackPath))}function s(e,t=a){return t(Zn(e))}let c=e(o,t),l=r?on(c):c;return r&&(r.buildProxySubscriptions((e,t)=>{n.push(n=>e.subscribe(t,n,Hn))},!1),r=void 0),i=void 0,{initialValue:l,subscribe(r){let i=()=>r(e(s,t)),a=n.map(e=>e(i));return e=>{for(let t of a)t(e)}}}}function Kn(e,t,n,r,i){if($n(t)){let a=Gn(t,r);return e[n]=a.initialValue,i===void 0?{tracked:a}:{key:i,tracked:a}}return e[n]=t,i===void 0?null:{key:i}}function qn(e){let t=o();for(let n in e)O(e,n)&&(t[n]=e[n]);return t}function Jn(e,t,n){if(!e)return c;let r;for(let i in e){let a=e[i]?.tracked;a&&(r??(r=[])).push(a.subscribe(e=>{let r=t[i];Ae(r,e)||(t[i]=e,n(i,r,e))}))}return r?e=>{for(let t of r)t(e)}:c}function Yn(e,t){let n=o();for(let r in t){if(!O(t,r))continue;let i=e?.[r];if(i?.key===!1)continue;let a=t[r];n[r]=i?.key?i.key(a):a}return n}function Xn(e){return e?{equalityFn:e,isCascadeParticipant:!0}:Hn}function Zn(e){return be(e)?e.getSnapshot():e.getState()}function Qn(e,t){for(let n of t)if(!(n in e))return!1;return!0}function $n(e){return typeof e==`function`}const er={error:!0,lastFetchedAt:!0,queryCache:!0,queryKey:!0,status:!0,enabled:!1,fetch:!1,getCacheEntry:!1,getData:!1,getStatus:!1,isDataExpired:!1,isStale:!1,reset:!1},tr=Object.freeze({force:!0}),nr=Object.freeze({once:!0}),rr=new Set;let ir=!1;function ar(e){rr.add(e),!ir&&(ir=!0,queueMicrotask(()=>{ir=!1,Fe(or)}))}function or(){for(let e of rr)rr.delete(e),e()}function sr(e,t,n){re();let a=typeof t==`function`?t:dr,o=typeof t==`object`?t:n,c=cr(o)?o:void 0,l=ae(),u=l.minStaleTime,{fetcher:d,onError:f=l.onError,onFetched:p,setData:m,transform:h,abortInterruptedFetches:g=l.abortInterruptedFetches,cacheTime:_=l.cacheTime,debugMode:v=l.debugMode,disableAutoRefetching:y=l.disableAutoRefetching,disableCache:b=!1,enabled:x=!0,keepPreviousData:S=l.keepPreviousData,paramChangeThrottle:C=l.paramChangeThrottle,params:w,retry:E=l.retry,retryDelay:D=l.retryDelay,staleTime:O=l.staleTime,suppressStaleTimeWarning:ee=l.suppressStaleTimeWarning}=e,k=typeof O==`function`?l.staleTime:O;r&&u!==!1&&!y&&!ee&&k<u&&console.warn(`[createQueryStore${c?.storageKey?`: ${c.storageKey}`:``}] ❌ Stale times under ${u/1e3} seconds are not recommended. Provided staleTime: ${k/1e3} seconds`);let A=Error(`[createQueryStore: AbortError] Fetch interrupted`),te=typeof _==`function`,N=r&&v,ne=e.params?Object.keys(e.params):[],P=!1,F,I=[],L=null,R=null,z=null,B=null,V=null,H=null,ie=null,W={enabled:typeof x==`function`?!1:x,error:null,lastFetchedAt:null,queryCache:{},queryKey:``,status:U.Idle},G=new Pn(y);function oe(){z&&(B=null,z.abort(),z=null)}function K(){V&&(clearTimeout(V),V=null)}async function ce(e){let t=new AbortController;z=t;try{return await new Promise((n,r)=>{t.signal.addEventListener(`abort`,()=>r(A),nr),Promise.resolve(d(e,t)).then(n,r)})}finally{z===t&&(z=null)}}function le(e,t,n){let r=n.setState;function i(e,t){e!==t&&ie!==t&&(ie=t,t&&G.hasSubscribers()?queueMicrotask(()=>u.fetch(void 0,void 0,!0)):(V||g)&&(g&&oe(),K()))}function o(e){let t=typeof e==`function`;if(t||e.enabled!==void 0){let n,a=r(r=>{let a=t?e(r):e,o=a.enabled===void 0?r.enabled:a.enabled;return o!==r.enabled&&(n=()=>i(r.enabled,o)),a});return n?.(),a}else return r(e)}n.setState=o,G.init({onSubscribe:(n,r)=>{let i=t();if(i.enabled)if(n){let t=F.get(),n=F.buildKey(t);i.queryKey!==n&&e({queryKey:n}),i.isStale()?u.fetch(t,void 0,!0):s(t)}else y&&!r&&u.fetch(void 0,void 0,!0)},onLastUnsubscribe:e=>{K(),g&&!e&&oe()}});function s(e){if(y||k<=0||k===1/0||!G.hasSubscribers())return;K();let n=t();if(!n.enabled)return;let r=F.buildKey(e),i=(b?H===r&&n.lastFetchedAt:n.queryCache[r]?.lastFetchedAt)||null,a=i?k-(Date.now()-i):k;V=setTimeout(()=>{t().enabled&&u.fetch(e,tr,!0)},a)}function l(e){let n=t(),r=n.status;switch(e){case`isIdle`:return r===U.Idle;case`isLoading`:return r===U.Loading;case`isError`:case`isInitialLoad`:case`isSuccess`:case void 0:{let t=n.queryKey,i=b?void 0:n.queryCache[t],a=b?r===U.Error:typeof i?.errorInfo?.lastFailedAt==`number`;if(e===`isError`)return a;let o=((b?H===t&&n.lastFetchedAt:i?.lastFetchedAt)||null)!==null,s=!o&&!a&&n.enabled;if(e===`isInitialLoad`)return s;let c=o&&!a;return e===`isSuccess`?c:{isError:a,isIdle:r===U.Idle,isLoading:r===U.Loading,isInitialLoad:s,isSuccess:c}}}}let u={...a(o,t,n),...W,async fetch(n,r,i=!1,a=0){let l=!!r?.skipStoreUpdates,v=t();if(!l&&(!v.enabled&&!r?.force||i&&!G.hasSubscribers()))return null;let y=v.error,x=v.queryKey,C=v.status===U.Loading,w=F.complete(n),O=F.buildKey(w);if(C&&B?.promise&&B.key===O)return N&&console.log(`[πŸ”„ Using Active Fetch πŸ”„] for params:`,JSON.stringify(w)),B.promise;let ee=r?.staleTime??k,P=typeof r?.updateQueryKey==`boolean`?r.updateQueryKey:i?S:!1,I=(i||x===O||P)&&!l,L=B!==null;if(g&&I&&oe(),!r?.force){let t=v.lastFetchedAt,n=b?void 0:v.queryCache[O],r=n?.lastFetchedAt,i=n?.errorInfo,a=(b?H===O&&t:r)||null;if(!(!a||Date.now()-a>=ee)&&(!i||!i.retryAllowed||l))return I&&!V&&k!==0&&k!==1/0&&s(w),P&&e(e=>e.queryKey===O?e:{queryKey:O}),N&&console.log(`[πŸ’Ύ Returning Cached Data πŸ’Ύ] for params:`,JSON.stringify(w)),n?.data??null}let R=I?{key:O}:null,z=r?.cacheTime??(te?_(w):_);R&&(K(),P&&!L&&v.lastFetchedAt===null&&x!==O?e({error:null,queryKey:O,status:U.Loading}):(y||!C)&&e({error:null,status:U.Loading}),B=R);async function re(){let v=c?.storageKey||O;try{N&&(!i&&n&&ne.some(e=>!(e in n))?console.log(`[πŸ”„ Fetching with Partial Params πŸ”„]
7
- `,`- Provided params:`,`${JSON.stringify(n)}\n`,`- Filled in params:`,`${JSON.stringify(Object.fromEntries(Object.keys(w).filter(e=>!(e in n)).map(e=>[e,w[e]])))}`):console.log(`[πŸ”„ Fetching πŸ”„] for params:`,JSON.stringify(w)));let t=await(g&&I?ce(w):d(w,null)),a=Date.now();N&&console.log(`[βœ… Fetch Successful βœ…] for params:`,JSON.stringify(w));let c;try{c=pr(t,w,h)}catch(e){throw fr(v,`transform`,e)}if(l)return N&&console.log(`[πŸ₯· Successful Parallel Fetch πŸ₯·] for params:`,JSON.stringify(w)),r.skipStoreUpdates===`withCache`&&e(e=>{if(!m)return b?e:{queryCache:{...e.queryCache,[O]:{cacheTime:z,data:c,errorInfo:null,lastFetchedAt:a}}};let t=e,n=b?void 0:t.queryCache[O];try{m({data:c,params:w,queryKey:O,set:e=>{t=typeof e==`function`?{...t,...e(t)}:{...t,...e}}})}catch(e){throw fr(v,`setData`,e)}return!b&&Object.is(n,t.queryCache[O])&&(t={...t,queryCache:{...t.queryCache,[O]:{cacheTime:z,data:null,errorInfo:null,lastFetchedAt:a}}}),t}),c;if((m?o:e)(e=>{let t={...e,error:null,lastFetchedAt:a,queryKey:P?O:e.queryKey,status:U.Success};if(!m&&!b)N&&console.log(`[πŸ’Ύ Setting Cache πŸ’Ύ] for params:`,JSON.stringify(w),`| Has previous data?:`,!!t.queryCache[O]?.data),t.queryCache={...t.queryCache,[O]:{cacheTime:z,data:c,errorInfo:null,lastFetchedAt:a}};else if(m){N&&console.log(`[πŸ’Ύ Setting Data πŸ’Ύ] for params:`,JSON.stringify(w));let e=b?void 0:t.queryCache[O];try{m({data:c,params:w,queryKey:O,set:e=>{t=typeof e==`function`?{...t,...e(t)}:{...t,...e}}})}catch(e){throw fr(v,`setData`,e)}!b&&Object.is(e,t.queryCache[O])&&(t.queryCache={...t.queryCache,[O]:{cacheTime:z,data:null,errorInfo:null,lastFetchedAt:a}})}return b||_===1/0?t:ur(S,O,t)}),I&&(H=O,s(w)),p)try{p({data:c,fetch:u.fetch,params:w,set:o})}catch(e){T.error(fr(v,`onFetched callback`,e))}return c??null}catch(n){if(n===A)return N&&console.log(`[❌ Fetch Aborted ❌] for params:`,JSON.stringify(w)),null;let o=!i&&r?.throwOnError===!0,s=M(n);if(s instanceof j&&T.error(s),!I){if(o)throw s;return null}let c=b?void 0:t().queryCache[O],l,d;if(typeof E==`function`){l={error:s,params:w,queryKey:O,retryCount:a};try{d=E(l)}catch(e){T.error(fr(v,`retry callback`,e)),d=!1}}else d=E!==!1&&a<E;let p;if(d&&t().enabled&&G.hasSubscribers())if(D===void 0)p=se(a);else if(typeof D==`number`)p=D;else{l??(l={error:s,params:w,queryKey:O,retryCount:a});try{p=D(l)}catch(e){T.error(fr(v,`retryDelay callback`,e)),d=!1}}let m=p!==void 0;if(p!==void 0&&(K(),V=setTimeout(()=>{t().enabled&&u.fetch(w,tr,!0,a+1)},p)),e(b?e=>({error:s,queryKey:P?O:e.queryKey,status:U.Error}):e=>({error:s,queryCache:{...e.queryCache,[O]:{cacheTime:c?.cacheTime??z,data:c?.data??null,lastFetchedAt:c?.lastFetchedAt??null,errorInfo:{error:s,lastFailedAt:Date.now(),retryAllowed:d,retryCount:a}}},queryKey:P?O:e.queryKey,status:U.Error})),f)try{f({error:s,params:w,queryKey:O,retryCount:a,willRetry:m})}catch(e){T.error(fr(v,`onError callback`,e))}if(o)throw s;return null}finally{B===R&&(B=null)}}return R?(R.promise=re(),R.promise):re()},getCacheEntry(e){if(b)return null;let n=t(),r=e?typeof e==`string`?e:F.buildKey(F.complete(e)):n.queryKey;return n.queryCache[r]??null},getData(e){if(b)return null;let n=t().getCacheEntry(e);return!n||n.data===null?null:S?n.data:n.lastFetchedAt&&Date.now()-n.lastFetchedAt>=n.cacheTime?null:n.data},getStatus:l,isDataExpired(e){let n=t(),r=n.queryKey,i=b?void 0:n.queryCache[r],a=n.lastFetchedAt,o=(b?H===r&&a:i?.lastFetchedAt)||null;if(!o)return!0;let s=e??i?.cacheTime;return s===void 0||Date.now()-o>=s},isStale(e){let n=t(),r=n.queryKey,i=(b?H===r&&n.lastFetchedAt:n.queryCache[r]?.lastFetchedAt)||null;if(!i)return!0;let a=e??k;return Date.now()-i>=a},reset(t=!1){for(let e of I)e();I=[],F=Un(void 0,q,ne),L=null,R=null,oe(),K(),ye?.cancel(),B=null,H=null,t&&e(W)}},v=n.subscribe;return n.subscribe=(...e)=>{let t=P?void 0:G.subscribe(),n=e.length===1?v(e[0]):v(e[0],e[1],e[2]);return e=>{t?.(e),n(e)}},rt(n,e=>t=>{let n=P?void 0:G.subscribe(),r=e(t);return e=>{n?.(e),r(e)}}),u}let q=c?.storageKey?Gt(le,s(c,{partialize:lr(S,c.partialize)})):o&&!(`storageKey`in o)?Gt(le,o):Gt(le),ue=q.getState(),de=ue.error,fe=ue.enabled,he=ue.queryKey,ge=ue.fetch;he&&!de&&(H=he),P=!0,F=Un(w,q,ne),typeof x==`function`&&(L=Gn(x,q)),typeof e.staleTime==`function`&&(R=Gn(e.staleTime,q),k=R.initialValue);let _e=Fn(e=>{ge(e,void 0,!0)},ar);function ve(){if(S)_e(void 0);else{let e=F.get();q.setState({queryKey:F.buildKey(e)}),_e(e)}}let ye=i||!C?void 0:yt(ve,typeof C==`number`?C:C.delay,typeof C==`number`?{leading:!1,maxWait:C,trailing:!0}:C);function be(){if(K(),ye){let e=q.getState();S&&B?.key===e.queryKey&&e.lastFetchedAt===null?ve():ye();return}ve()}if(I.push(F.subscribe((e,t,n)=>{N&&console.log(`[πŸŒ€ Param Change πŸŒ€] -`,e,`- [Old]:`,`${t?.toString()},`,`[New]:`,n?.toString()),be()})),R){let e=R.initialValue;N&&console.log(`[πŸŒ€ StaleTime Subscription πŸŒ€] Initial value:`,e),I.push(R.subscribe(t=>{t!==e&&(N&&console.log(`[πŸŒ€ StaleTime Change πŸŒ€] - [Old]:`,`${e},`,`[New]:`,t),e=t,k=t,K(),ge(void 0,void 0,!0))}))}let J;if(L){let e=L.initialValue;fe!==e&&((J??(J={})).enabled=e),N&&console.log(`[πŸŒ€ Enabled Subscription πŸŒ€] Initial value:`,e),I.push(L.subscribe(t=>{t!==e&&(N&&console.log(`[πŸŒ€ Enabled Change πŸŒ€] - [Old]:`,`${e},`,`[New]:`,t),e=t,q.setState({enabled:t}))}))}else fe!==W.enabled&&((J??(J={})).enabled=W.enabled);let xe=F.buildKey();return xe!==he&&((J??(J={})).queryKey=xe),J&&q.setState(J),P=!1,me(q,pe.QueryStore)}function cr(e){return typeof e?.storageKey==`string`}function lr(e,t){return n=>{let r={...n},i=o();for(let e in r)O(r,e)&&e in er&&(er[e]&&(i[e]=r[e]),delete r[e]);return{...t?t(r):Ct(r),...ur(e,null,i)}}}function ur(e,t,n){if(!n.queryCache)return n;let r=Date.now(),i=t??(e&&n.queryKey||null),a=o(),s=!1;for(let e in n.queryCache){if(!O(n.queryCache,e))continue;let t=n.queryCache[e];t&&(r-(t.lastFetchedAt??t.errorInfo.lastFailedAt)<t.cacheTime||e===i)?a[e]=t:s=!0}return s?{...n,queryCache:a}:n}function dr(){return Object.create(null)}function fr(e,t,n){return new j(`[createQueryStore: ${e}]: ${t} failed`,n)}function pr(e,t,n){return n?n(e,t):e}const mr=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});function hr(e,t,n){let r=typeof t==`function`,i=r?t:void 0,a=r?n:t,o=new Set,s,c;function l(e,t){let n=e.getState(),r=t.getState();if(c)for(let e of c)u(e,t,n,r);if(s)for(let e of s)d(e,t,n,r);o.size&&Ke();for(let e of o)f(e,t,n,r)}function u(e,t,n,r){e.unsubscribe(),e.unsubscribe=gr(t,e.listener),!Object.is(r,n)&&(Ge(),e.listener(r,n))}function d(e,t,n,r){f(e,t,n,r)&&Ge()}function f(e,t,n,r){e.unsubscribe();let i=e.args;if(i.length===1){let a=i[0];e.unsubscribe=t.subscribe(a);let o=!Object.is(r,n);return o&&a(r,n),o}let a=i[0],o=i[1],s=i[2];s?.fireImmediately&&(s={...s,fireImmediately:!1});let c=a(n),l=a(r);return e.unsubscribe=t.subscribe(a,o,s),(s?.equalityFn??Object.is)(c,l)?!1:(o(l,c),!0)}function p(e,t){l(t,e),he(t)}let m=An(e,{debugMode:a?.debugMode??!1,lockDependencies:a?.lockDependencies??!0}),h;function g(){return h??(h=m.subscribe(p)),m.getState()}function _(...e){let t=g(),n={args:e,unsubscribe:e.length===1?t.subscribe(e[0]):t.subscribe(e[0],e[1],e[2])},r=e[2]?.isCascadeParticipant??!1;return r?(s??(s=new Set)).add(n):o.add(n),()=>{n.unsubscribe(),r?s?.delete(n)&&s.size===0&&(s=void 0):o.delete(n)}}function v(e){let t={listener:e,unsubscribe:gr(g(),e)};return(c??(c=new Set)).add(t),e=>{t.unsubscribe(e),c?.delete(t)&&c.size===0&&(c=void 0)}}return Object.assign({[Q]:v,[pe.VirtualStore]:!0,destroy:()=>{h?.(),h=void 0,m.destroy()},getInitialState:()=>g().getInitialState(),getState:()=>g().getState(),persist:_r(g),setState:vr(g),subscribe:_},i?.(g))}function gr(e,t){return nt(e)?e[Q](t):e.subscribe(a,t,mr)}function _r(e){return{clearStorage:()=>e().persist?.clearStorage(),getOptions:()=>e().persist?.getOptions()??{},hasHydrated:()=>e().persist?.hasHydrated()??!0,hydrationPromise:()=>e().persist?.hydrationPromise?.()??Promise.resolve(),onFinishHydration:t=>e().persist?.onFinishHydration(t)??c,onHydrate:t=>e().persist?.onHydrate(t)??c,rehydrate:()=>e().persist?.rehydrate(),setOptions:t=>e().persist?.setOptions(t)}}function vr(e){return function(...t){return t[1]===!0?e().setState(t[0],!0):e().setState(t[0])}}function yr(e,t){let n=Gt(e,t);return x(n,n.getState,n.getInitialState)}function br(e,t=Object.is){let n=An(e,t);return x(n,n.getSnapshot,void 0)}function xr(e,t,n){let r=sr(e,t,n);return x(r,r.getState,r.getInitialState)}function Sr(e,t,n){let r=hr(e,t,n);return x(r,r.getState,r.getInitialState)}const Cr=Symbol();function wr(t){let n=(0,e.useRef)(Cr);return n.current===Cr&&(n.current=t()),n}const Tr=Object.freeze({debugMode:!1,enabled:!0,equalityFn:Object.is,fireImmediately:!1});function Er(t,n,r,i=Tr){let a=wr(()=>Ar(n,r,i)),o=Mr(i);return Nr(a,n,r,i),(0,e.useLayoutEffect)(()=>{if(o)return Or(t,a),()=>kr(a)},[o,t]),a}const Dr=Object.freeze({fireImmediately:!1,forceResubscribe:!1});function Or(e,t,n=Dr){if(t.current.isActive){if(!n?.forceResubscribe)return;t.current.unsubscribe()}t.current.options.debugMode&&console.log(`[πŸ“‘ useListen πŸ“‘] Attaching listener`),t.current.isActive=!0,t.current.resubscribe=(n=Dr)=>Or(e,t,n);let r=e.subscribe(e=>t.current.selector(e),(n,i)=>t.current.react(n,i,e.getState,()=>{r(),t.current.isActive=!1}),n.fireImmediately?{...t.current.options,fireImmediately:!0}:t.current.options);t.current.unsubscribe=()=>{t.current.isActive&&(r(),t.current.isActive=!1)}}function kr(e){e.current.options.debugMode&&console.log(`[πŸ—‘οΈ useListen πŸ—‘οΈ] Detaching listener`),e.current.resubscribe=c,e.current.unsubscribe(),e.current.unsubscribe=c,e.current.isActive=!1}function Ar(e,t,n){return{selector:e,react:t,isActive:!1,options:jr(n),resubscribe:c,unsubscribe:c}}function jr(e){return typeof e==`function`?{equalityFn:e}:e??Tr}function Mr(e){return typeof e==`function`?Tr.enabled:e?.enabled??Tr.enabled}function Nr(e,t,n,r){e.current.selector=t,e.current.react=n,typeof r==`function`?e.current.options.equalityFn=r:r&&(e.current.options=r??Tr)}const Pr=Symbol();function Fr(t){let n=(0,e.useRef)(Pr);return n.current===Pr&&(n.current=t()),n.current}exports.QueryStatuses=U,exports.StoresError=j,exports.applyStateUpdate=ce,exports.configureStores=R,exports.createBaseStore=yr,exports.createDerivedStore=br,exports.createQueryStore=xr,exports.createStoreActions=we,exports.createVirtualStore=Sr,exports.deepEqual=Oe,exports.defaultRetryDelay=se,exports.destroyStore=he,exports.destroyStores=ge,exports.getQueryKey=zn,exports.getStoreName=_e,exports.hasGetSnapshot=be,exports.identity=a,exports.isDerivedStore=xe,exports.isPersistedStore=Se,exports.isQueryStore=J,exports.isVirtualStore=Ce,exports.nullObject=o,exports.parseQueryKey=Bn,exports.queryParam=Ln,exports.replacer=de,exports.reviver=fe,exports.shallowEqual=ke,exports.time=W,exports.useListen=Er,exports.useStableValue=Fr;
6
+ `+(e instanceof Error?`\n${e.message}`:``))}return w(t),t}return{clearAll:()=>n().clearAll(),contains:e=>n().contains(e),delete:e=>n().delete(e),get:e=>n().get(e),getAllKeys:()=>n().getAllKeys(),set:(e,t)=>n().set(e,t)}}function C(e){let{createMMKV:t,MMKV:n}=require("react-native-mmkv");if(typeof t==`function`)return t({id:e});if(typeof n==`function`)return new n({id:e});throw Error(`[stores]: react-native-mmkv module does not export MMKV/createMMKV.`)}function w(e){if(!e||typeof e.get!=`function`||typeof e.set!=`function`||typeof e.delete!=`function`||typeof e.clearAll!=`function`)throw Error(`[stores]: Storage instance does not conform to expected interface`)}let T={debug:(e,t)=>{r&&console.debug(e,t)},error:(e,t)=>{r&&!i&&console.error(e,t)},info:(e,t)=>{r&&console.info(e,t)},warn:(e,t)=>{r&&console.warn(e,t)}};function E(e){T=e}const D=Object.prototype.hasOwnProperty;function O(e,t){return D.call(e,t)}function ee(e){let t=e.charCodeAt(0);if(t<48||t>57)return!1;let n=Number(e);return Number.isInteger(n)&&n<4294967295&&String(n)===e}function k(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function A(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var j=class extends Error{constructor(e,t){super(e),this.name=`StoresError`,t!==void 0&&Object.defineProperty(this,"cause",{configurable:!0,value:t,writable:!0})}};function M(e){return e instanceof Error?e:Error(String(e))}var te=class{destroy(){}publish(){}},N=class{constructor(){this.sessionId=`noop`}register(e){return new te}};let ne;function P(){return ne||(ne=new N),ne}let F,I,L=!1;function R(e){r&&ie(),e.logger&&E(e.logger),F??(F=V(e)),I??(I=H(e))}function z(){if(F)return F}function B(){return I??(I=H(void 0))}function re(){L=!0}function V(e){if(e?.queryStoreDefaults)return{queryStoreDefaults:e.queryStoreDefaults}}function H(e){return{storage:e?.storage??S(e?.storageKeyPrefix??`stores:`),syncEngine:e?.syncEngine??P()}}function ie(){if(L)throw Error(`[stores]: configureStores() called after first store creation. Call it earlier before creating any stores.`)}const U={Error:`error`,Idle:`idle`,Loading:`loading`,Success:`success`},W={ms:e=>{"worklet";return e},seconds:e=>{"worklet";return e*1e3},minutes:e=>{"worklet";return e*6e4},hours:e=>{"worklet";return e*36e5},days:e=>{"worklet";return e*864e5},weeks:e=>{"worklet";return e*6048e5},infinity:1/0,zero:0};let G;function ae(){return G??(G=oe())}function oe(){let e=z()?.queryStoreDefaults;return{abortInterruptedFetches:e?.abortInterruptedFetches??!0,cacheTime:e?.cacheTime??W.days(7),debugMode:e?.debugMode??!1,disableAutoRefetching:e?.disableAutoRefetching??!1,keepPreviousData:e?.keepPreviousData??!1,minStaleTime:e?.minStaleTime??!1,onError:e?.onError,paramChangeThrottle:e?.paramChangeThrottle??!1,retry:e?.retry??5,retryDelay:e?.retryDelay,staleTime:e?.staleTime??W.minutes(2),suppressStaleTimeWarning:e?.suppressStaleTimeWarning??!1}}function se(e,t){let n=t?.baseDelay??W.seconds(5),r=t?.maxDelay??W.minutes(5);return Math.min(n*2**e,r)}function K(e,t){return t[1]===!0?e(t[0],!0):e(t[0])}function ce(e,t,n){if(n===!0)return le(t)?t(e):t;let r=le(t)?t(e):t;return Object.is(r,e)?e:!A(e)||!A(r)?r:{...e,...r}}function le(e){return typeof e==`function`}function q(e){return typeof e==`object`&&!!e&&`__type`in e&&e.__type===`Map`}function ue(e){return typeof e==`object`&&!!e&&`__type`in e&&e.__type===`Set`}function de(e,t){return t instanceof Map?{__type:`Map`,entries:Array.from(t.entries())}:t instanceof Set?{__type:`Set`,values:Array.from(t)}:t}function fe(e,t){return q(t)?new Map(t.entries):ue(t)?new Set(t.values):t}const pe=Object.freeze({QueryStore:Symbol(`queryStore`),VirtualStore:Symbol(`virtualStore`)});function me(e,t){return Object.assign(e,{[t]:!0})}function he(e,t){J(e)?e.getState().reset(t?.clearQueryCache):ye(e)&&e.destroy()}function ge(e,t){for(let n of Array.isArray(e)?e:Object.values(e))!n||t?.skipDestroy?.(n)||he(n,t)}function _e(e){let t=ve(e);return Se(e)?e.persist.getOptions().name??t:t}function ve(e){return typeof e==`function`?e.name:``}function ye(e){return`destroy`in e}function be(e){return`getSnapshot`in e}function J(e){return pe.QueryStore in e}function xe(e){return`flushUpdates`in e}function Se(e){return!(`persist`in e)||!e.persist?!1:typeof e.persist.getOptions().name==`string`}function Ce(e){return pe.VirtualStore in e}function we(e,t){let n=Te(e);return t?Object.assign(n,t):n}function Te(e){let t=e.getState(),n=o(),i=n;if(r&&!(typeof t==`object`&&t))throw Error(`[createStoreActions]: State is not an object`);if(Ce(e))for(let n in t)De(t,n)&&(i[n]=Ee(e,n));else for(let e in t)De(t,e)&&(i[e]=t[e]);return n}function Ee(e,t){return function(...n){let r=e.getState()[t];if(typeof r==`function`)return r(...n);throw Error(`[createVirtualStoreAction]: Method ${String(t)} is not a function`)}}function De(e,t){return typeof e[t]==`function`}function Oe(e,t){"worklet";if(typeof e!=`object`||!e||e===void 0||typeof t!=`object`||!t||t===void 0)return e===t;if(Object.is(e,t))return!0;let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let r of n)if(!(r in t)||!Oe(e[r],t[r]))return!1;return!0}function ke(e,t){"worklet";if(typeof e!=`object`||!e||e===void 0||typeof t!=`object`||!t||t===void 0)return e===t;if(Object.is(e,t))return!0;let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let r of n)if(!Object.is(e[r],t[r]))return!1;return!0}function Ae(e,t){let n=Object.prototype.hasOwnProperty;function r(e,t){for(let n of e.keys())if(Ae(n,t))return n}let i,a,o;if(e===t)return!0;if(e&&t&&(i=e.constructor)===t.constructor){if(i===Date)return e.getTime()===t.getTime();if(i===RegExp)return e.toString()===t.toString();if(i===Array){if((a=e.length)===t.length)for(;a--&&Ae(e[a],t[a]););return a===-1}if(i===Set){if(e.size!==t.size)return!1;for(let n of e)if(o=n,o&&typeof o==`object`&&(o=r(t,o),!o)||!t.has(o))return!1;return!0}if(i===Map){if(e.size!==t.size)return!1;for(let n of e)if(o=n[0],o&&typeof o==`object`&&(o=r(t,o),!o)||!Ae(n[1],t.get(o)))return!1;return!0}if(i===ArrayBuffer)e=new Uint8Array(e),t=new Uint8Array(t);else if(i===DataView){if((a=e.byteLength)===t.byteLength)for(;a--&&e.getInt8(a)===t.getInt8(a););return a===-1}if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(t)){let n=e,r=t;if((a=n.byteLength)===r.byteLength)for(;a--&&n[a]===r[a];);return a===-1}if(!i||typeof e==`object`){a=0;for(let r in e)if(n.call(e,r)&&++a&&!n.call(t,r)||!(r in t)||!Ae(e[r],t[r]))return!1;return Object.keys(t).length===a}}return e!==e&&t!==t}function je(e,t,n){if(t===0)return n;if(t===1){if(e===n)return null;let t=new Set;return t.add(e),t.add(n),t}return e.add(n),e.size===t?null:e}function Me(e,t,n){if(t===0)return null;if(t===1)return e===n?void 0:null;if(!e.delete(n))return null;if(t!==2)return e;for(let t of e)return t}function Ne(e,t,n,r,i){if(t!==0){if(t===1){n(e,r,i);return}for(let t of e)n(t,r,i)}}function Pe(e,t){t>1&&e.clear()}const Fe=t.unstable_batchedUpdates;let Y=!1,Ie=!1,Le=!1,X,Re,ze=0;const Be=new Map;let Ve=0,He=null,Z=1/0;function Ue(){return Y}function We(){return He}function Ge(){Y||(Y=!0,!Le&&(Le=!0,queueMicrotask(()=>{Le=!1,Ke()})))}function Ke(){if(Y){if(Ie){Xe();return}Ie=!0;try{Fe(Xe)}finally{et()}}}function qe(){if(Y){if(Ie){He===null&&Ze();return}Ie=!0;try{Ze()}catch(e){throw et(),e}finally{Ie=!1,He=null}}}function Je(e){if(Y){if(Re){Re.push(e);return}if(!X){X=e;return}Re=[X,e],X=void 0}}function Ye(e,t){if(!Y)return;let n=t<0?0:t|0,r=Be.get(n);r||(r=[],Be.set(n,r)),r.push(e),Ve+=1,n<Z&&(Z=n)}function Xe(){for(;Ve>0||tt();)Ze(),$e()}function Ze(){for(;Ve>0;){let e=Z,t=Be.get(e);if(!t){Z=1/0;for(let e of Be.keys())e<Z&&(Z=e);continue}Be.delete(e),Ve-=t.length,Qe(),He=e;for(let e=0;e<t.length;e++)t[e]();He=null}}function Qe(){Z=1/0;for(let e of Be.keys())e<Z&&(Z=e)}function $e(){for(;;){let e=X;if(e){X=void 0,e();continue}let t=Re;if(!t)return;for(;ze<t.length;)t[ze++]();Re=void 0,ze=0;return}}function et(){Y=!1,Ie=!1,He=null,X=void 0,Re=void 0,ze=0,Be.clear(),Ve=0,Z=1/0}function tt(){return!!X||!!Re}const Q=Symbol(`stores.subscribeCascadeState`);function nt(e){return Q in e}function rt(e,t){nt(e)&&(e[Q]=t(e[Q]))}const it=Symbol(),at=Symbol();function ot(e){let t,n,r,i=0;function a(e,a,o){let s=ce(t,e,a);if(Object.is(s,t))return o===it?at:void 0;let c=t;if(t=s,Ne(r,i,l,t,c),n){Ke();for(let e of n)e(t,c)}}function o(){return t}function s(){return d}function c(e,t,n){return t?g(e,t,n):f(e)}let u={[Q]:m,getInitialState:s,getState:o,setState:a,subscribe:c},d=t=st(e)?e(a,o,u):e;return u;function f(e){return(n??(n=new Set)).add(e),()=>{n?.delete(e),n?.size===0&&(n=void 0)}}function p(e){let t=je(r,i,e);return t!==null&&(r=t,i+=1),()=>h(e)}function m(e){function t(t,n){Ge(),e(t,n)}return p(t)}function h(e){let t=Me(r,i,e);t!==null&&(r=t,--i)}function g(e,n,r){let i=r?.equalityFn??Object.is,a=r?.isCascadeParticipant??!1,o=e(t);function s(t){let r=e(t);if(i(o,r))return;let s=o;o=r,a&&Ge(),n(r,s)}return r?.fireImmediately&&n(o,o),a?p(s):f(s)}}function st(e){return typeof e==`function`}function ct(e){return!!e&&typeof e==`object`&&`then`in e&&typeof e.then==`function`}const lt=Object.freeze({migrated:!1,state:void 0});function ut(e,t,n){return(r,i,a)=>{let o=ft(t),s,c=!1,l=0,u,d,f;function p(e){return o.storage.setItem(o.name,e,o.version)}function m(e,t){return(t===!0?r(e,t,it):r(e,!1,it))===at?n?s??(s=Promise.resolve()):void 0:p(i())}a.setState=m;let h=e(m,i,a);a.getInitialState=()=>h;function g(){let e=x(),t=o.onRehydrateStorage?.(i()??h);try{let n=o.storage.getItem(o.name);return ct(n)?n.then(n=>_(e,n,t)).catch(n=>C(e,t,n)):_(e,n,t)}catch(n){C(e,t,n)}}return Object.assign(a,{persist:b()}),o.skipHydration||g(),u??h;function _(e,t,n){let r=dt(o,t);return ct(r)?r.then(t=>v(e,t,n)).catch(t=>C(e,n,t)):v(e,r,n)}function v(e,t,n){let r=y(e,t);if(ct(r))return r.then(()=>S(e,n));S(e,n)}function y(e,t){if(e!==l)return;let n=o.merge(t.state,i()??h);if(u=n,r(n,!0),t.migrated)return p(i())}function b(){return{clearStorage:()=>{o.storage.removeItem(o.name)},getOptions:()=>o,hasHydrated:()=>c,onFinishHydration:e=>(f??(f=new Set),f.add(e),()=>{f?.delete(e),f?.size===0&&(f=void 0)}),onHydrate:e=>(d??(d=new Set),d.add(e),()=>{d?.delete(e),d?.size===0&&(d=void 0)}),rehydrate:g,setOptions:e=>{o=ft({...o,...e,storage:e.storage??o.storage})}}}function x(){let e=++l;return c=!1,d?.forEach(e=>e(i()??h)),e}function S(e,t){if(e!==l)return;t?.(u,void 0);let n=i();u=n,c=!0,f?.forEach(e=>e(n))}function C(e,t,n){e===l&&t?.(void 0,n)}}}function dt(e,t){if(!t)return lt;if(typeof t.version!=`number`||t.version===e.version)return{migrated:!1,state:t.state};if(!e.migrate)return console.error(`State loaded from storage couldn't be migrated since no migrate function was provided`),lt;let n=e.migrate(t.state,t.version);return ct(n)?n.then(e=>({migrated:!0,state:e})):{migrated:!0,state:n}}function ft(e){return{...e,merge:e.merge??pt,skipHydration:e.skipHydration??!1}}function pt(e,t){return e===void 0?t:{...t,...e}}function mt(){let e=!1,t,n,r=new Promise((e,r)=>{t=e,n=r});function i(){e||!t||(e=!0,t(),t=void 0,n=void 0)}function a(r){e||!n||(e=!0,n(r),n=void 0,t=void 0)}function o(){return e}return{complete:i,isHydrated:o,fail:a,promise:r}}function ht(e){let t,n=!1,r,i;return{hydrationPromise:()=>n?t?.promise??r??(r=Promise.resolve()):(t||(t=mt()),t.promise),stateCreator:(t,r,a)=>{let o;function s(...e){return n?K(t,e):new Promise((t,n)=>{(o??(o=[])).push(()=>{try{t(K(a.setState,e))}catch(e){n(e)}})})}return i=()=>{if(!o?.length)return;let e=o;o=void 0;for(let t of e)t()},e(s,r,a)},wrapOnRehydrateStorage:(e,r)=>a=>{let o=e?.(a);return(e,a)=>{let s=n;n=!0,r?.onHydrationComplete?.(),i&&i(),r?.onHydrationFlushEnd?.(),a?(!t&&!s&&(t=mt(),t.promise.catch(c)),t?.fail(M(a))):t?.complete(),o?.(e,a)}}}}const gt=Promise.resolve();function _t(e){let t,n,r,i=null,a=gt;function o(){return i=null,e(t,n,r)}function s(e,s,l){return t=e,n=s,r=l,i||(i=a.then(o),a=i.catch(c)),i}return s}const vt=Math.max,yt=Math.min;function bt(e,t=0,n={}){let r,i,a,o,s,c,l=0,u=!1,d=!1,f=!0;if(typeof e!=`function`)throw TypeError(`Expected a function`);t=St(t)||0,Ct(n)&&(u=!!n.leading,d=`maxWait`in n,a=d?vt(St(n.maxWait)||0,t):void 0,f=`trailing`in n?!!n.trailing:f);function p(t){let n=r,a=i;return r=i=void 0,l=t,o=n?e.apply(a,n):e.apply(a),o}function m(e){return l=e,s=setTimeout(_,t),u?p(e):o}function h(e){let n=e-(c??0),r=e-l,i=t-n;return d&&a!==void 0?yt(i,a-r):i}function g(e){let n=e-(c??0),r=e-l;return c===void 0||n>=t||n<0||d&&a!==void 0&&r>=a}function _(){let e=xt();if(g(e))return v(e);s=setTimeout(_,h(e))}function v(e){return s=void 0,f&&r?p(e):(r=i=void 0,o)}function y(){s!==void 0&&clearTimeout(s),l=0,r=c=i=s=void 0}function b(){return s===void 0?o:v(xt())}function x(...e){let n=xt(),a=g(n);if(r=e,i=this,c=n,a){if(s===void 0)return m(c);if(d)return clearTimeout(s),s=setTimeout(_,t),p(c)}return s===void 0&&(s=setTimeout(_,t)),o}return x.cancel=y,x.flush=b,x}function xt(){return typeof performance<`u`&&typeof performance.now==`function`?performance.now():Date.now()}function St(e){if(typeof e==`number`)return e;if(typeof e==`symbol`||e===void 0)return NaN;if(typeof e==`object`&&e){let t=typeof e.valueOf==`function`?e.valueOf():e;e=typeof t==`object`?t+``:t}return typeof e==`string`?(e=e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,``),/^0b[01]+$/i.test(e)?parseInt(e.slice(2),2):/^0o[0-7]+$/i.test(e)?parseInt(e.slice(2),8):/^[-+]0x[0-9a-f]+$/i.test(e)?NaN:+e):e===0?e:+e}function Ct(e){let t=typeof e;return e!==null&&(t===`object`||t===`function`)}function wt(e){if(!k(e))return e;let t=o(),n=Object.keys(e);for(let r=0;r<n.length;r++){let i=n[r],a=e[i];typeof a!=`function`&&(t[i]=a)}return t}function Tt(e,t){try{return JSON.stringify(e,t?de:void 0)}catch(e){throw T.error(new j(`[createBaseStore]: Failed to serialize store data`,e)),e}}function Et(e,t){try{return JSON.parse(e,t?fe:void 0)}catch(e){throw T.error(new j(`[createBaseStore]: Failed to deserialize persisted store data`,e)),e}}const Dt=i?0:n?W.seconds(3):W.seconds(5);function Ot(e,t,n){let r=t??e.storage??B().storage,i=e.version??0;return r.async?{async:!0,persistStorage:At(r,e,n),version:i}:{async:!1,persistStorage:kt(r,e,(e.sync?void 0:e.persistThrottleMs??Dt)||void 0,n),version:i}}function kt(e,t,n,r){let i=!t.deserializer&&!t.serializer&&!e.deserializer&&!e.serializer,a=typeof t.sync==`object`&&(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata)===!0,o=t.partialize??wt,s=t.deserializer??e.deserializer??jt(i),c=t.serializer??e.serializer??Mt(i);function l(t,n,i){try{if(Lt(r))return;let s={state:o(n),version:i},l=Pt(r,a,s),u=c(s);try{e.set(t,u),Ft(r,l)}catch(e){T.error(new j(`[createBaseStore]: Failed to persist store data`,e))}}catch(e){T.error(new j(`[createBaseStore]: Failed to persist store data`,e))}}let u=n===void 0?l:bt(l,n,{leading:!1,maxWait:n,trailing:!0});return{getItem:t=>{let n=e.get(t);return n===void 0?null:s(n)},setItem:(e,t,n)=>{r?.getIsApplyingRemote()||u(e,t,n)},removeItem:t=>{try{e.delete(t)}catch(e){T.error(new j(`[createBaseStore]: Failed to delete persisted store data`,e))}}}}function At(e,t,n){let r=!t.deserializer&&!t.serializer&&!e.deserializer&&!e.serializer,i=typeof t.sync==`object`&&(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata)===!0,a=t.partialize??wt,o=t.deserializer??e.deserializer??jt(r),s=t.serializer??e.serializer??Mt(r);async function c(t,r,o){try{if(Lt(n))return;let c={state:a(r),version:o},l=Pt(n,i,c),u=s(c);try{await e.set(t,u),Ft(n,l)}catch(e){T.error(new j(`[createBaseStore]: Failed to persist store data`,e))}}catch(e){T.error(new j(`[createBaseStore]: Failed to serialize persisted store data`,e))}}let l=_t(c);return{getItem:async t=>{let n=await e.get(t);return n===void 0?null:o(n)},setItem:(e,t,r)=>n?.getIsApplyingRemote()?Promise.resolve():l(e,t,r),removeItem:async t=>{try{await e.delete(t)}catch(e){T.error(new j(`[createBaseStore]: Failed to delete persisted store data`,e))}}}}function jt(e){return t=>{if(typeof t!=`string`)throw new j(`[createBaseStore]: Received non-string serialized state without a custom deserializer. Provide a deserializer on the store or storage adapter.`);return Et(t,e)}}function Mt(e){return t=>Tt(t,e)}const Nt=Object.freeze({shouldClear:!1});function Pt(e,t,n){if(!t||!e)return Nt;let r=e.getFieldTimestampSnapshot();return It(e,n),n.syncMetadata?r&&Object.keys(r).length>0?(n.syncMetadata.fields=r,{fieldSnapshot:r,shouldClear:!0}):(delete n.syncMetadata.fields,{fieldSnapshot:r,shouldClear:!1}):{fieldSnapshot:r,shouldClear:!1}}function Ft(e,t){!e||!t.shouldClear||!t.fieldSnapshot||!Object.keys(t.fieldSnapshot).length||e.clearFieldTimestamps(t.fieldSnapshot)}function It(e,t){let n=e.getSessionId(),r=e.getTimestamp();n!==void 0&&r!==void 0&&(t.syncMetadata={origin:n,timestamp:r})}function Lt(e){return e?!!e.getIsApplyingRemote():!1}function Rt(e,t,n){let r=t.engine??B().syncEngine;return(i,a,s)=>{let c=new Map,l=[],u=[],d=null,f=!1,p=!1,m=0,h=null,g=[],_=Promise.resolve(),v=!n?.isAsync;function y(){let e=Date.now(),t=e>m?e:m+1;return m=t,t}function b(e,t){if(!(!n||!r.sessionId)&&(n.setSessionId(r.sessionId),n.setTimestamp(e),t.length>0)){let r=o();for(let n of t)r[String(n)]=e;n.mergeFieldTimestamps(r)}}function x(e,t,n,i=!1){let a=r.sessionId;for(let t of e)c.set(t,[n,a]);!d||!p?u.push({keys:e,replace:i,timestamp:n,values:t}):d.publish?.({replace:i,sessionId:a,timestamp:n,values:t})}function S(){if(!(!d||!u.length)){for(let e of u){let t=r.sessionId;for(let n of e.keys)c.set(n,[e.timestamp,t]);b(e.timestamp,e.keys),d.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values})}u.length=0}}function C(e,t){if(f||!h)return t?i(e,t):i(e);let n=y(),r,a,s=t?i(c,!0):i(c);if(!r||!a)return s;function c(i){let s=ce(i,e,t);for(let e of g)Object.is(s[e],i[e])||((r??(r=[])).push(e),(a??(a=o()))[e]=s[e]);return r&&b(n,r),s}return ct(s)?s.finally(x.bind(void 0,r,a,n,t)):(x(r,a,n,t),s)}let w=s.setState;s.setState=C;let E=e(C,a,s);if(g=t.fields??Vt(E),!g.length)return E;h=new Set(g);async function D(e){m=Math.max(m,e.timestamp);let r=o(),i=a(),s=e.timestamp,l;if(e.replace)for(let t of g)O(e.values,t)||Bt(c.get(t),s,e.sessionId)&&(l??(l=[])).push(t);for(let n of g){if(!Wt(e.values,n)||!h?.has(n)||!Bt(c.get(n),s,e.sessionId))continue;let a=t.merge?.[n];if(a){let t=e.values[n],o=i[n];if(t!==void 0){let l=a(t,o,i,e.values),u=o===void 0?t:o;if(!Ut(l,u)){T.error(new j(`[sync] Merge function for field "${String(n)}" returned ${Ht(l)} but expected ${Ht(u)}`));return}r[n]=l,c.set(n,[s,e.sessionId])}}else r[n]=e.values[n],c.set(n,[s,e.sessionId])}if(!(!(Object.keys(r).length>0)&&!l?.length)){f=!0,n?.setIsApplyingRemote(!0);try{if(e.replace){let e={...i},t=!1;if(l?.length){t=!0;for(let t of l)delete e[t],c.delete(t)}for(let n in r){if(!O(r,n))continue;let i=r[n];if(i===void 0)continue;Object.is(e[n],i)||(t=!0);let a=e;a[n]=i}if(!t)return;await(n?.setWithoutPersist??w)(e,!0)}else await(n?.setWithoutPersist??w)(r)}finally{f=!1,n?.setIsApplyingRemote(!1)}}}function ee(e){n?.isAsync?_=_.then(()=>D(e)):D(e)}function k(){if(!l.length)return;let e=l.slice();l.length=0;for(let t of e)ee(t)}if(d=r.register({apply:e=>{if(!v){l.push(e);return}ee(e)},fields:g,getState:a,key:t.key}),d?.onFirstSubscribe||d?.onLastUnsubscribe){let e=d,t=0,n=s.subscribe;function A(n){return t++===0&&e.onFirstSubscribe?.(),r=>{n(r),--t,t||queueMicrotask(()=>{t||e.onLastUnsubscribe?.()})}}s.subscribe=(...e)=>A(e.length===1?n(e[0]):n(e[0],e[1],e[2])),rt(s,e=>t=>A(e(t)))}function M(){p=!0,S()}function te(){v=!0,k()}return n?.isAsync?(n.onHydrationComplete=M,n.onHydrationFlushEnd=te):d.onHydrated?(d.onHydrated(M),te()):(M(),te()),E}}function zt(e){let t,n,r,i=!1;function a(e){if(!(!e||!r)){for(let t of Object.entries(e)){let e=t[0],n=t[1];r[e]===n&&delete r[e]}Object.keys(r).length||(r=void 0)}}function o(){if(r)return{...r}}function s(e){if(!r){r={...e};return}for(let t of Object.entries(e)){let e=t[0],n=t[1],i=r[e];(i===void 0||n>i)&&(r[e]=n)}}return{isAsync:e,clearFieldTimestamps:a,getFieldTimestampSnapshot:o,getIsApplyingRemote:()=>i,getSessionId:()=>t,getTimestamp:()=>n,mergeFieldTimestamps:s,onHydrationComplete:void 0,onHydrationFlushEnd:void 0,setIsApplyingRemote:e=>i=e,setSessionId:e=>t=e,setTimestamp:e=>n=e,setWithoutPersist:void 0}}function Bt(e,t,n){if(!e)return!0;let r=e[0],i=e[1];return t<r?!1:t>r?!0:n>i}function Vt(e){let t=[];for(let n of Object.keys(e))Gt(e,n)&&t.push(n);return t}function Ht(e){if(e===null)return`null`;let t=typeof e;return t===`object`?Object.prototype.toString.call(e):t}function Ut(e,t){if(!r)return!0;if(e===null||t===null)return e===t;let n=typeof e;return n===typeof t?n===`object`?Object.prototype.toString.call(e)===Object.prototype.toString.call(t):!0:!1}function Wt(e,t){return O(e,t)}function Gt(e,t){return typeof e[t]!=`function`}function Kt(e,t){if(re(),!t)return ot(e);let n=t.storageKey,r=typeof n==`string`,i=r?t.storage??B().storage:void 0,a=qt(t.sync,n),o=!i||!a?void 0:zt(i.async??!1),s=a?Rt(e,a,o):e;if(!r)return ot(s);let c=Ot(t,i,o),l=c.async?ht(s):void 0,u=l?l.wrapOnRehydrateStorage(t.onRehydrateStorage,o):t.onRehydrateStorage,d=ot(ut(l?(e,t,n)=>(o&&(o.setWithoutPersist=n.setState),l.stateCreator(e,t,n)):s,{merge:t.merge,migrate:t.migrate,name:n,onRehydrateStorage:u,storage:c.persistStorage,version:c.version},c.async));return l?Object.assign(d,{persist:Object.assign(d.persist,{hydrationPromise:l.hydrationPromise})}):d}function qt(e,t){if(!e)return null;let n=typeof e==`object`,r=n?e.key??t:e===!0?t:e;if(!r)throw new j(`[createBaseStore]: sync requires a key to be specified either directly or via storageKey`);return n?{...e,key:r}:{key:r}}function Jt(e,t,n=`s`){return t===1?e:`${e}${n}`}const Yt=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});var Xt=class{constructor(e){this.invalidate=e,this.stateDependencyRevisionStamp=0,this.stateDependencyRevision=0}beginRebuild(e){this.clearSelectors(e),this.stateDependencyRevision+=1}addSelector(e){let t=this.selectorUnsubscribes;if(!t){this.selectorUnsubscribes=e;return}if(typeof t==`function`){this.selectorUnsubscribes=[t,e];return}t.push(e)}retainState(e){let t=this.stateDependencies;if(t){let n=t.get(e);if(n){n.revision=this.stateDependencyRevision;return}t.set(e,this.createStateDependency(e));return}let n=this.stateDependencyStore;if(!n){this.stateDependencyStore=e,this.stateDependencyRevisionStamp=this.stateDependencyRevision,this.stateDependencyUnsubscribe=this.subscribeState(e);return}if(n===e){this.stateDependencyRevisionStamp=this.stateDependencyRevision;return}let r=this.stateDependencyUnsubscribe;this.stateDependencyStore=void 0,this.stateDependencyUnsubscribe=void 0,this.stateDependencies=new Map,r&&this.stateDependencies.set(n,{revision:this.stateDependencyRevisionStamp,unsubscribe:r}),this.stateDependencies.set(e,this.createStateDependency(e))}finishRebuild(e){this.stateDependencyStore&&this.stateDependencyRevisionStamp!==this.stateDependencyRevision&&(this.stateDependencyUnsubscribe?.(e),this.stateDependencyStore=void 0,this.stateDependencyUnsubscribe=void 0);let t=this.stateDependencies;if(t){for(let n of t){let r=n[1];r.revision!==this.stateDependencyRevision&&(r.unsubscribe(e),t.delete(n[0]))}if(!t.size){this.stateDependencies=void 0;return}if(t.size===1){for(let e of t){this.stateDependencyStore=e[0],this.stateDependencyRevisionStamp=e[1].revision,this.stateDependencyUnsubscribe=e[1].unsubscribe;break}this.stateDependencies=void 0}}}clear(e){this.clearSelectors(e),this.stateDependencyUnsubscribe?.(e),this.stateDependencyStore=void 0,this.stateDependencyUnsubscribe=void 0;let t=this.stateDependencies;if(t){for(let n of t)n[1].unsubscribe(e);this.stateDependencies=void 0}}get size(){let e=this.selectorUnsubscribes;return(typeof e==`function`?1:e?.length??0)+ +!!this.stateDependencyStore+(this.stateDependencies?.size??0)}clearSelectors(e){let t=this.selectorUnsubscribes;if(this.selectorUnsubscribes=void 0,t){if(typeof t==`function`){t(e);return}for(let n=0;n<t.length;n++)t[n](e)}}createStateDependency(e){return{revision:this.stateDependencyRevision,unsubscribe:this.subscribeState(e)}}subscribeState(e){return nt(e)?e[Q](this.invalidate):e.subscribe(a,this.invalidate,Yt)}},Zt=class{constructor(){this.watcherCount=0,this.ordinaryWatcherCount=0,this.cascadeParticipantCount=0,this.cascadeStateListenerCount=0}addWatcher(e){let t=je(this.watchers,this.watcherCount,e);return t===null?!1:(this.watchers=t,this.watcherCount+=1,tn(e)?this.cascadeParticipantCount+=1:this.ordinaryWatcherCount+=1,!0)}deleteWatcher(e){let t=Me(this.watchers,this.watcherCount,e);return t===null?!1:(this.watchers=t,--this.watcherCount,tn(e)?--this.cascadeParticipantCount:--this.ordinaryWatcherCount,!0)}addCascadeStateListener(e){let t=je(this.cascadeStateListeners,this.cascadeStateListenerCount,e);return t===null?!1:(this.cascadeStateListeners=t,this.cascadeParticipantCount+=1,this.cascadeStateListenerCount+=1,!0)}deleteCascadeStateListener(e){let t=Me(this.cascadeStateListeners,this.cascadeStateListenerCount,e);return t===null?!1:(this.cascadeStateListeners=t,--this.cascadeParticipantCount,--this.cascadeStateListenerCount,!0)}notifyCascade(e,t){Ne(this.cascadeStateListeners,this.cascadeStateListenerCount,l,e,t),this.cascadeParticipantCount!==this.cascadeStateListenerCount&&Ne(this.watchers,this.watcherCount,Qt,e,t)}notifyOrdinary(e,t){Ne(this.watchers,this.watcherCount,$t,e,t)}clear(){this.watchers=Pe(this.watchers,this.watcherCount),this.cascadeStateListeners=Pe(this.cascadeStateListeners,this.cascadeStateListenerCount),this.watcherCount=0,this.ordinaryWatcherCount=0,this.cascadeParticipantCount=0,this.cascadeStateListenerCount=0}};function Qt(e,t,n){typeof e==`function`||!e.isCascadeParticipant||en(e,t)}function $t(e,t,n){if(typeof e==`function`){e(t,n);return}e.isCascadeParticipant||en(e,t)}function en(e,t){let n=e.selector(t);if(e.equalityFn(e.currentSlice,n))return;let r=e.currentSlice;e.currentSlice=n,e.listener(n,r)}function tn(e){return typeof e!=`function`&&e.isCascadeParticipant}const nn=Symbol(`stores.deriveProxy.unwrap`);function rn(e,t,n,r){let i=n.get(e);if(pn(i))return i;let a=an(t,e,r);return n.set(e,a),a}function an(e,t,n,r=[]){return!e||typeof e!=`object`?(n(t,r,!0),e):on(e,r,t,n,new WeakSet,new WeakMap)}function on(e,t,n,r,i,a){let o=Array.isArray(e);return new Proxy(e,{get(s,c,l){if(c===nn)return r(n,t,!0),s;if(i.has(s))return Reflect.get(s,c,l);if(c===`__proto__`||typeof c==`symbol`)return c===Symbol.iterator&&(r(n,t,!0),i.add(s)),Reflect.get(s,c,l);if(o&&ee(c))return r(n,t,!0),i.add(s),Reflect.get(s,c,l);let u=Reflect.get(s,c,s),d=String(c),f=t.concat(d);if(typeof u==`function`)return O(s,c)?function(...e){return r(n,f,!0,{args:e.length?e:void 0}),Reflect.apply(u,s,e)}:(r(n,t,!0),u.bind(e));let p=!!u&&typeof u==`object`;return r(n,f,!p),p?(a.has(u)||a.set(u,on(u,f,n,r,i,a)),a.get(u)):u},getOwnPropertyDescriptor(e,a){return r(n,t,!0),i.add(e),Reflect.getOwnPropertyDescriptor(e,a)},has(e,i){return r(n,t,!0),Reflect.has(e,i)},ownKeys(e){return r(n,t,!0),i.add(e),Reflect.ownKeys(e)}})}function sn(e,t){return!e||typeof e!=`object`?e:dn(e)||(Array.isArray(e)?cn(e,t):k(e)&&ln(e,t),e)}function cn(e,t){let n=fn(e,t);if(n)for(let t=0;t<e.length;t++)un(e,String(t),n)}function ln(e,t){let n=fn(e,t);if(n)for(let t of Reflect.ownKeys(e))un(e,t,n)}function un(e,t,n){let r=Reflect.getOwnPropertyDescriptor(e,t);if(!r||!(`value`in r))return;let i=sn(r.value,n);i!==r.value&&(r.value=i,Reflect.defineProperty(e,t,r))}function dn(e){let t=Reflect.get(e,nn);return t&&typeof t==`object`?t:void 0}function fn(e,t){let n=t??new WeakSet;return n.has(e)?null:(n.add(e),n)}function pn(e){return e!==void 0}const mn=Object.freeze([]);function hn(){let e,t,n;return{buildProxySubscriptions(r,i,a){let o=[],s=t,c=e;if(s&&c)vn(s,c,[],0,o,a);else if(n)for(let e of n)vn(e[1],e[0],[],0,o,a);Sn(o,r,i)},reset(){e=void 0,t=void 0,n=void 0},trackPath(r,i,a,o){let s=t;if(s){let i=e;if(i!==r)if(!i)e=r;else{let a=n??(n=new Map);a.set(i,s),s=gn(),a.set(r,s),e=void 0,t=void 0}}else{let i=n;i?(s=i.get(r),s||(s=gn(),i.set(r,s))):(s=gn(),e=r,t=s)}_n(s,i,a,o)}}}function gn(){return o()}function _n(e,t,n,r){let i=e;for(let e=0;e<t.length;e++){let n=t[e],r=i.children,a;if(r)a=r[n],a||(a=r[n]=gn());else if(a=i.child,!a)a=gn(),i.child=a,i.childKey=n;else if(i.childKey!==n){let e=i.childKey;if(e===void 0)i.childKey=n;else{let t=gn();t[e]=a,a=t[n]=gn(),i.child=void 0,i.childKey=void 0,i.children=t}}i=a}n&&(i.isLeaf=!0),r&&yn(i,r)}function vn(e,t,n,r,i,a=2){let o=e.child;if(o){let s=e.childKey;if(e.isLeaf){if(xn(e,t,n,i),!o.invocation||s===void 0)return}else if(s===void 0){xn(e,t,n,i);return}n.push(s),vn(o,t,n,r+1,i,a),n.pop();return}let s=e.children;if(!s){xn(e,t,n,i);return}if(e.isLeaf||r>=a){xn(e,t,n,i);for(let e in s){let o=s[e];o.invocation&&(n.push(e),vn(o,t,n,r+1,i,a),n.pop())}return}for(let e in s)n.push(e),vn(s[e],t,n,r+1,i,a),n.pop()}function yn(e,t){let n=e.invocation;if(!n){e.invocation=t;return}if(bn(n,t))return;let r=e.extraInvocations;if(!r){e.extraInvocations=[t];return}for(let e=0;e<r.length;e++)if(bn(r[e],t))return;r.push(t)}function bn(e,t){let n=e.args,r=t.args,i=n?.length??0;if(i!==(r?.length??0))return!1;if(!n||!r)return!0;for(let e=0;e<i;e++)if(!Object.is(n[e],r[e]))return!1;return!0}function xn(e,t,n,r){let i=n.slice(),a=e.invocation;if(!a){r.push({store:t,path:i});return}r.push({store:t,path:i,invocation:a});let o=e.extraInvocations;if(o)for(let e=0;e<o.length;e++)r.push({store:t,path:i,invocation:o[e]})}function Sn(e,t,n){for(let n of e){let e=n.invocation?wn(n.path,n.invocation):Cn(n.path);t(n.store,e,n.path)}n&&En(e)}function Cn(e){return e.length?t=>Tn(t,e):a}function wn(e,t){let n=e.slice(0,-1),r=e[e.length-1];return e=>{let i=Tn(e,n),a=i&&typeof i==`object`?Reflect.get(i,r):void 0;return typeof a==`function`?Reflect.apply(a,i,t.args??mn):void 0}}function Tn(e,t){let n=e;for(let e=0;e<t.length;e++){if(!n||typeof n!=`object`)return n;n=Reflect.get(n,t[e])}return n}function En(e){let t=e.length;console.log(`[πŸ“‘ ${t} ${Jt(`Proxy Subscription`,t)} πŸ“‘]:`,JSON.stringify(e.map(e=>{let t=Dn(e.store),n=e.path.join(`.`);if(!e.invocation)return n?`$(${t}).${n}`:`$(${t})`;let r=e.invocation.args?.length??0;return`$(${t}).${n}${r?`(${r}_${Jt(`arg`,r)})`:`()`}`}),null,2))}function Dn(e){return`name`in e&&typeof e.name==`string`?e.name:`store`}const On=Symbol(),kn=Symbol(),An=Symbol(`stores.derivedStore.readDependencyState`);function jn(e,t=Object.is){let n,i=!1,o,s=!1,c=!1;typeof t==`function`?o=t:(n=t.debounce,i=r?t.debugMode??!1:!1,o=t.equalityFn??Object.is,s=t.keepAlive??!1,c=t.lockDependencies??!1);let l=new Zt,u=new Xt(k),d=+!!s,f,p,m=On,h=!1,g=!1,_=!0,v=!0,y=null,b=kn;function x(e,t,n){if(!v)return(t??a)(Pn(e));if(!d)return(t??a)(e.getState());if(!t){let t=Pn(e);return!t||typeof t!=`object`?(u.retainState(e),t):(f||(f=new WeakMap),p||(p=hn()),rn(e,t,f,p.trackPath))}let r=n?{equalityFn:n,isCascadeParticipant:!0}:Yt;return u.addSelector(e.subscribe(t,k,r)),t(Pn(e))}function S(){if(!_&&$(m))return m;_=!1,v&&u.beginRebuild(!0);let t=!0,n=m,r=$(n);g=!0;try{let a=e(x),s=p?sn(a):a;r&&o(n,s)?(i&&console.log(`[πŸ₯· Derive Complete πŸ₯·]: No change detected`),t=!1,m=n):m=s}finally{g=!1,v&&u.finishRebuild(!0)}let a=i&&(!r||i===`verbose`&&v);if(a){r?i===`verbose`&&console.log(`[πŸŒ€ Rebuilding Subscriptions πŸŒ€]: Created…`):console.log(`[πŸŒ€ Initial Derive Complete πŸŒ€]: Created…`);let e=u.size;console.log(`[🎯 ${e} ${Jt(`Selector Subscription`,e)} 🎯]`)}return p&&v&&(p.buildProxySubscriptions((e,t)=>{u.addSelector(e.subscribe(t,k,Yt))},a),f=void 0,c?p=void 0:p.reset()),t&&r&&C(m,n),c&&(v=!1),m}function C(e,t){let n=l.cascadeParticipantCount,r=n>0&&l.ordinaryWatcherCount>0,a=l.ordinaryWatcherCount>0&&(r||We()!==null||Ue());if(r&&Ge(),i){let e=l.ordinaryWatcherCount+n;console.log(`[πŸ“» Derive Complete πŸ“»]: Notifying ${e} ${Jt(`watcher`,e)}`)}if(n&&l.notifyCascade(e,t),l.ordinaryWatcherCount){if(a){b===kn?(b=t,Je(w)):$(b)||(b=t);return}l.notifyOrdinary(e,t)}}function w(){d&&_&&!l.cascadeParticipantCount&&S();let e=b;b=kn,l.ordinaryWatcherCount&&$(m)&&e!==kn&&$(e)&&l.notifyOrdinary(m,e)}let T=n?bt(D,typeof n==`number`?n:n.delay,typeof n==`number`?{leading:!1,maxWait:n,trailing:!0}:n):void 0,E=T??(()=>{h||(h=!0,queueMicrotask(D))});function D(){if(h=!1,!d){s||P();return}_&&S()}function O(e){if(e!==void 0&&(e||T&&_)){queueMicrotask(O);return}!d&&!s&&P()}function ee(){let e=y;e===We()&&(D(),y===e&&(y=null))}function k(){if(!g){if(!T){if(l.cascadeParticipantCount){_=!0,Ge();let e=We(),t=e===null?0:e+1;if(y!==null&&t<=y)return;y=t,Ye(ee,t);return}if(_)return;if(_=!0,Ue()){b===kn&&(b=On,Je(w));return}}_||(_=!0,y=null,E())}}function A(e){d+=1;try{return e()}finally{--d,d||queueMicrotask(O)}}function j(){return _||!$(m)?d?S():A(S):(h&&d&&D(),m)}function M(){return Ue()&&We()===null&&qe(),_||!$(m)?d?S():e(x):m}function te(...e){if(e.length===1){let t=e[0];return l.addWatcher(t)&&(d+=1),$(m)||M(),()=>{l.deleteWatcher(t)&&(--d,d||O(!1))}}let[t,n,r]=e,i=r?.equalityFn??Object.is,a=r?.isCascadeParticipant??!1,o=t(d?M():A(M)),s={currentSlice:o,equalityFn:i,isCascadeParticipant:a,listener:n,selector:t};return l.addWatcher(s),d+=1,r?.fireImmediately&&n(o,o),()=>{l.deleteWatcher(s)&&(--d,d||O(a))}}function N(e){return d?M():A(M),l.addCascadeStateListener(e)&&(d+=1),()=>{l.deleteCascadeStateListener(e)&&(--d,d||O(!0))}}function ne(){d&&(T?T.flush():_&&S())}function P(){T?.cancel(),u.clear(),l.clear(),d=0,p=void 0,f=void 0,v=!0,h=!1,g=!1,_=!0,m=On,b=kn,y=null}function F(){return _||h||!$(m)?d?S():A(S):m}return{[An]:F,[Q]:N,destroy:P,flushUpdates:ne,getSnapshot:j,getState:M,subscribe:te,getInitialState:Mn,setState:Nn}}function Mn(){throw Error(`[createDerivedStore]: getInitialState() is not available on derived stores.`)}function Nn(){throw Error(`[createDerivedStore]: setState() is not available on derived stores.`)}function Pn(e){let t=e[An];return t?t():e.getState()}function $(e){return e!==On}var Fn=class{constructor(e){this.count=0,this.lastSubscriptionTime=null,this.fetchThrottleMs=null,this.onSubscribe=null,this.onLastUnsubscribe=null,e&&(this.fetchThrottleMs=W.seconds(5))}init({onSubscribe:e,onLastUnsubscribe:t}){this.onSubscribe=e,this.onLastUnsubscribe=t}hasSubscribers(){return this.count>0}subscribe(){let e=this.count===0,t=this.fetchThrottleMs!==null,n=t&&this.lastSubscriptionTime!==null&&!e&&Date.now()-this.lastSubscriptionTime<=this.fetchThrottleMs;return this.count+=1,this.onSubscribe?.(e,n),t&&(this.lastSubscriptionTime=Date.now()),e=>{let t=this.count===1;this.count=Math.max(this.count-1,0),t&&(this.onLastUnsubscribe?.(e),this.lastSubscriptionTime=null)}}};function In(e,t=queueMicrotask){let n=!1,r;function i(){n=!1,e(...r)}function a(...e){r=e,!n&&(n=!0,t(i))}return a}const Ln=Symbol(`stores.queryParamConfig`);function Rn(e,t){return{[Ln]:!0,key:t.key,value:e}}function zn(e){return!!e&&typeof e==`object`&&Ln in e}function Bn(e){return JSON.stringify(Hn(e))}function Vn(e){return JSON.parse(e)}function Hn(e){return typeof e!=`object`||!e?e:Object.keys(e).sort().reduce((t,n)=>{let r=e[n];return t[n]=k(r)?Hn(r):r,t},o())}const Un=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});function Wn(e,t,n){let r=o(),i=null,a=!1;if(e)for(let n in e){if(!O(e,n))continue;let s=Gn(r,e[n],n,t);s&&((i??(i=o()))[n]=s,s.key!==void 0&&(a=!0))}return{buildKey(e=r){return Bn(a?Xn(i,e):e)},complete(e){return e?$n(e,n)?e:{...r,...e}:Jn(r)},get(){return Jn(r)},subscribe(e){return Yn(i,r,e)}}}function Gn(e,t,n,r){return zn(t)?qn(e,t.value,n,r,t.key):qn(e,t,n,r)}function Kn(e,t){let n=[],r,i;function o(e,t,a){return t?(n.push(n=>e.subscribe(t,n,Zn(a))),t(Qn(e))):(r??(r=hn()),i??(i=new WeakMap),rn(e,Qn(e),i,r.trackPath))}function s(e,t=a){return t(Qn(e))}let c=e(o,t),l=r?sn(c):c;return r&&(r.buildProxySubscriptions((e,t)=>{n.push(n=>e.subscribe(t,n,Un))},!1),r=void 0),i=void 0,{initialValue:l,subscribe(r){let i=()=>r(e(s,t)),a=n.map(e=>e(i));return e=>{for(let t of a)t(e)}}}}function qn(e,t,n,r,i){if(er(t)){let a=Kn(t,r);return e[n]=a.initialValue,i===void 0?{tracked:a}:{key:i,tracked:a}}return e[n]=t,i===void 0?null:{key:i}}function Jn(e){let t=o();for(let n in e)O(e,n)&&(t[n]=e[n]);return t}function Yn(e,t,n){if(!e)return c;let r;for(let i in e){let a=e[i]?.tracked;a&&(r??(r=[])).push(a.subscribe(e=>{let r=t[i];Ae(r,e)||(t[i]=e,n(i,r,e))}))}return r?e=>{for(let t of r)t(e)}:c}function Xn(e,t){let n=o();for(let r in t){if(!O(t,r))continue;let i=e?.[r];if(i?.key===!1)continue;let a=t[r];n[r]=i?.key?i.key(a):a}return n}function Zn(e){return e?{equalityFn:e,isCascadeParticipant:!0}:Un}function Qn(e){return be(e)?e.getSnapshot():e.getState()}function $n(e,t){for(let n of t)if(!(n in e))return!1;return!0}function er(e){return typeof e==`function`}const tr={error:!0,lastFetchedAt:!0,queryCache:!0,queryKey:!0,status:!0,enabled:!1,fetch:!1,getCacheEntry:!1,getData:!1,getStatus:!1,isDataExpired:!1,isStale:!1,reset:!1},nr=Object.freeze({force:!0}),rr=Object.freeze({once:!0}),ir=new Set;let ar=!1;function or(e){ir.add(e),!ar&&(ar=!0,queueMicrotask(()=>{ar=!1,Fe(sr)}))}function sr(){for(let e of ir)ir.delete(e),e()}function cr(e,t,n){re();let a=typeof t==`function`?t:fr,o=typeof t==`object`?t:n,c=lr(o)?o:void 0,l=ae(),u=l.minStaleTime,{fetcher:d,onError:f=l.onError,onFetched:p,setData:m,transform:h,abortInterruptedFetches:g=l.abortInterruptedFetches,cacheTime:_=l.cacheTime,debugMode:v=l.debugMode,disableAutoRefetching:y=l.disableAutoRefetching,disableCache:b=!1,enabled:x=!0,keepPreviousData:S=l.keepPreviousData,paramChangeThrottle:C=l.paramChangeThrottle,params:w,retry:E=l.retry,retryDelay:D=l.retryDelay,staleTime:O=l.staleTime,suppressStaleTimeWarning:ee=l.suppressStaleTimeWarning}=e,k=typeof O==`function`?l.staleTime:O;r&&u!==!1&&!y&&!ee&&k<u&&console.warn(`[createQueryStore${c?.storageKey?`: ${c.storageKey}`:``}] ❌ Stale times under ${u/1e3} seconds are not recommended. Provided staleTime: ${k/1e3} seconds`);let A=Error(`[createQueryStore: AbortError] Fetch interrupted`),te=typeof _==`function`,N=r&&v,ne=e.params?Object.keys(e.params):[],P=!1,F,I=[],L=null,R=null,z=null,B=null,V=null,H=null,ie=null,W={enabled:typeof x==`function`?!1:x,error:null,lastFetchedAt:null,queryCache:{},queryKey:``,status:U.Idle},G=new Fn(y);function oe(){z&&(B=null,z.abort(),z=null)}function K(){V&&(clearTimeout(V),V=null)}async function ce(e){let t=new AbortController;z=t;try{return await new Promise((n,r)=>{t.signal.addEventListener(`abort`,()=>r(A),rr),Promise.resolve(d(e,t)).then(n,r)})}finally{z===t&&(z=null)}}function le(e,t,n){let r=n.setState;function i(e,t){e!==t&&ie!==t&&(ie=t,t&&G.hasSubscribers()?queueMicrotask(()=>u.fetch(void 0,void 0,!0)):(V||g)&&(g&&oe(),K()))}function o(e){let t=typeof e==`function`;if(t||e.enabled!==void 0){let n,a=r(r=>{let a=t?e(r):e,o=a.enabled===void 0?r.enabled:a.enabled;return o!==r.enabled&&(n=()=>i(r.enabled,o)),a});return n?.(),a}else return r(e)}n.setState=o,G.init({onSubscribe:(n,r)=>{let i=t();if(i.enabled)if(n){let t=F.get(),n=F.buildKey(t);i.queryKey!==n&&e({queryKey:n}),i.isStale()?u.fetch(t,void 0,!0):s(t)}else y&&!r&&u.fetch(void 0,void 0,!0)},onLastUnsubscribe:e=>{K(),g&&!e&&oe()}});function s(e){if(y||k<=0||k===1/0||!G.hasSubscribers())return;K();let n=t();if(!n.enabled)return;let r=F.buildKey(e),i=(b?H===r&&n.lastFetchedAt:n.queryCache[r]?.lastFetchedAt)||null,a=i?k-(Date.now()-i):k;V=setTimeout(()=>{t().enabled&&u.fetch(e,nr,!0)},a)}function l(e){let n=t(),r=n.status;switch(e){case`isIdle`:return r===U.Idle;case`isLoading`:return r===U.Loading;case`isError`:case`isInitialLoad`:case`isSuccess`:case void 0:{let t=n.queryKey,i=b?void 0:n.queryCache[t],a=b?r===U.Error:typeof i?.errorInfo?.lastFailedAt==`number`;if(e===`isError`)return a;let o=((b?H===t&&n.lastFetchedAt:i?.lastFetchedAt)||null)!==null,s=!o&&!a&&n.enabled;if(e===`isInitialLoad`)return s;let c=o&&!a;return e===`isSuccess`?c:{isError:a,isIdle:r===U.Idle,isLoading:r===U.Loading,isInitialLoad:s,isSuccess:c}}}}let u={...a(o,t,n),...W,async fetch(n,r,i=!1,a=0){let l=!!r?.skipStoreUpdates,v=t();if(!l&&(!v.enabled&&!r?.force||i&&!G.hasSubscribers()))return null;let y=v.error,x=v.queryKey,C=v.status===U.Loading,w=F.complete(n),O=F.buildKey(w);if(C&&B?.promise&&B.key===O)return N&&console.log(`[πŸ”„ Using Active Fetch πŸ”„] for params:`,JSON.stringify(w)),B.promise;let ee=r?.staleTime??k,P=typeof r?.updateQueryKey==`boolean`?r.updateQueryKey:i?S:!1,I=(i||x===O||P)&&!l,L=B!==null;if(g&&I&&oe(),!r?.force){let t=v.lastFetchedAt,n=b?void 0:v.queryCache[O],r=n?.lastFetchedAt,i=n?.errorInfo,a=(b?H===O&&t:r)||null;if(!(!a||Date.now()-a>=ee)&&(!i||!i.retryAllowed||l))return I&&!V&&k!==0&&k!==1/0&&s(w),P&&e(e=>e.queryKey===O?e:{queryKey:O}),N&&console.log(`[πŸ’Ύ Returning Cached Data πŸ’Ύ] for params:`,JSON.stringify(w)),n?.data??null}let R=I?{key:O}:null,z=r?.cacheTime??(te?_(w):_);R&&(K(),P&&!L&&v.lastFetchedAt===null&&x!==O?e({error:null,queryKey:O,status:U.Loading}):(y||!C)&&e({error:null,status:U.Loading}),B=R);async function re(){let v=c?.storageKey||O;try{N&&(!i&&n&&ne.some(e=>!(e in n))?console.log(`[πŸ”„ Fetching with Partial Params πŸ”„]
7
+ `,`- Provided params:`,`${JSON.stringify(n)}\n`,`- Filled in params:`,`${JSON.stringify(Object.fromEntries(Object.keys(w).filter(e=>!(e in n)).map(e=>[e,w[e]])))}`):console.log(`[πŸ”„ Fetching πŸ”„] for params:`,JSON.stringify(w)));let t=await(g&&I?ce(w):d(w,null)),a=Date.now();N&&console.log(`[βœ… Fetch Successful βœ…] for params:`,JSON.stringify(w));let c;try{c=mr(t,w,h)}catch(e){throw pr(v,`transform`,e)}if(l)return N&&console.log(`[πŸ₯· Successful Parallel Fetch πŸ₯·] for params:`,JSON.stringify(w)),r.skipStoreUpdates===`withCache`&&e(e=>{if(!m)return b?e:{queryCache:{...e.queryCache,[O]:{cacheTime:z,data:c,errorInfo:null,lastFetchedAt:a}}};let t=e,n=b?void 0:t.queryCache[O];try{m({data:c,params:w,queryKey:O,set:e=>{t=typeof e==`function`?{...t,...e(t)}:{...t,...e}}})}catch(e){throw pr(v,`setData`,e)}return!b&&Object.is(n,t.queryCache[O])&&(t={...t,queryCache:{...t.queryCache,[O]:{cacheTime:z,data:null,errorInfo:null,lastFetchedAt:a}}}),t}),c;if((m?o:e)(e=>{let t=R&&B===R?{...e,error:null,lastFetchedAt:a,queryKey:P?O:e.queryKey,status:U.Success}:{...e};if(!m&&!b)N&&console.log(`[πŸ’Ύ Setting Cache πŸ’Ύ] for params:`,JSON.stringify(w),`| Has previous data?:`,!!t.queryCache[O]?.data),t.queryCache={...t.queryCache,[O]:{cacheTime:z,data:c,errorInfo:null,lastFetchedAt:a}};else if(m){N&&console.log(`[πŸ’Ύ Setting Data πŸ’Ύ] for params:`,JSON.stringify(w));let e=b?void 0:t.queryCache[O];try{m({data:c,params:w,queryKey:O,set:e=>{t=typeof e==`function`?{...t,...e(t)}:{...t,...e}}})}catch(e){throw pr(v,`setData`,e)}!b&&Object.is(e,t.queryCache[O])&&(t.queryCache={...t.queryCache,[O]:{cacheTime:z,data:null,errorInfo:null,lastFetchedAt:a}})}return b||_===1/0?t:dr(S,O,t)}),R&&B===R&&(H=O,s(w)),p)try{p({data:c,fetch:u.fetch,params:w,set:o})}catch(e){T.error(pr(v,`onFetched callback`,e))}return c??null}catch(n){if(n===A)return N&&console.log(`[❌ Fetch Aborted ❌] for params:`,JSON.stringify(w)),null;let o=!i&&r?.throwOnError===!0,s=M(n);if(s instanceof j&&T.error(s),!I){if(o)throw s;return null}let c=b?void 0:t().queryCache[O],l,d;if(typeof E==`function`){l={error:s,params:w,queryKey:O,retryCount:a};try{d=E(l)}catch(e){T.error(pr(v,`retry callback`,e)),d=!1}}else d=E!==!1&&a<E;let p;if(d&&B===R&&t().enabled&&G.hasSubscribers())if(D===void 0)p=se(a);else if(typeof D==`number`)p=D;else{l??(l={error:s,params:w,queryKey:O,retryCount:a});try{p=D(l)}catch(e){T.error(pr(v,`retryDelay callback`,e)),d=!1}}if(p!==void 0&&(K(),V=setTimeout(()=>{t().enabled&&u.fetch(w,nr,!0,a+1)},p)),e(e=>{let t={...e};return B===R&&(t.error=s,P&&(t.queryKey=O),t.status=U.Error),b||(t.queryCache={...e.queryCache,[O]:{cacheTime:c?.cacheTime??z,data:c?.data??null,lastFetchedAt:c?.lastFetchedAt??null,errorInfo:{error:s,lastFailedAt:Date.now(),retryAllowed:d,retryCount:a}}}),t}),f)try{f({error:s,params:w,queryKey:O,retryCount:a,willRetry:p!==void 0})}catch(e){T.error(pr(v,`onError callback`,e))}if(o)throw s;return null}finally{B===R&&(B=null)}}return R?(R.promise=re(),R.promise):re()},getCacheEntry(e){if(b)return null;let n=t(),r=e?typeof e==`string`?e:F.buildKey(F.complete(e)):n.queryKey;return n.queryCache[r]??null},getData(e){if(b)return null;let n=t().getCacheEntry(e);return!n||n.data===null?null:S?n.data:n.lastFetchedAt&&Date.now()-n.lastFetchedAt>=n.cacheTime?null:n.data},getStatus:l,isDataExpired(e){let n=t(),r=n.queryKey,i=b?void 0:n.queryCache[r],a=n.lastFetchedAt,o=(b?H===r&&a:i?.lastFetchedAt)||null;if(!o)return!0;let s=e??i?.cacheTime;return s===void 0||Date.now()-o>=s},isStale(e){let n=t(),r=n.queryKey,i=(b?H===r&&n.lastFetchedAt:n.queryCache[r]?.lastFetchedAt)||null;if(!i)return!0;let a=e??k;return Date.now()-i>=a},reset(t=!1){for(let e of I)e();I=[],F=Wn(void 0,q,ne),L=null,R=null,oe(),K(),ye?.cancel(),B=null,H=null,t&&e(W)}},v=n.subscribe;return n.subscribe=(...e)=>{let t=P?void 0:G.subscribe(),n=e.length===1?v(e[0]):v(e[0],e[1],e[2]);return e=>{t?.(e),n(e)}},rt(n,e=>t=>{let n=P?void 0:G.subscribe(),r=e(t);return e=>{n?.(e),r(e)}}),u}let q=c?.storageKey?Kt(le,s(c,{partialize:ur(S,c.partialize)})):o&&!(`storageKey`in o)?Kt(le,o):Kt(le),ue=q.getState(),de=ue.error,fe=ue.enabled,he=ue.queryKey,ge=ue.fetch;he&&!de&&(H=he),P=!0,F=Wn(w,q,ne),typeof x==`function`&&(L=Kn(x,q)),typeof e.staleTime==`function`&&(R=Kn(e.staleTime,q),k=R.initialValue);let _e=In(e=>{ge(e,void 0,!0)},or);function ve(){if(S)_e(void 0);else{let e=F.get();q.setState({queryKey:F.buildKey(e)}),_e(e)}}let ye=i||!C?void 0:bt(ve,typeof C==`number`?C:C.delay,typeof C==`number`?{leading:!1,maxWait:C,trailing:!0}:C);function be(){if(K(),ye){let e=q.getState();S&&B?.key===e.queryKey&&e.lastFetchedAt===null?ve():ye();return}ve()}if(I.push(F.subscribe((e,t,n)=>{N&&console.log(`[πŸŒ€ Param Change πŸŒ€] -`,e,`- [Old]:`,`${t?.toString()},`,`[New]:`,n?.toString()),be()})),R){let e=R.initialValue;N&&console.log(`[πŸŒ€ StaleTime Subscription πŸŒ€] Initial value:`,e),I.push(R.subscribe(t=>{t!==e&&(N&&console.log(`[πŸŒ€ StaleTime Change πŸŒ€] - [Old]:`,`${e},`,`[New]:`,t),e=t,k=t,K(),ge(void 0,void 0,!0))}))}let J;if(L){let e=L.initialValue;fe!==e&&((J??(J={})).enabled=e),N&&console.log(`[πŸŒ€ Enabled Subscription πŸŒ€] Initial value:`,e),I.push(L.subscribe(t=>{t!==e&&(N&&console.log(`[πŸŒ€ Enabled Change πŸŒ€] - [Old]:`,`${e},`,`[New]:`,t),e=t,q.setState({enabled:t}))}))}else fe!==W.enabled&&((J??(J={})).enabled=W.enabled);let xe=F.buildKey();return xe!==he&&((J??(J={})).queryKey=xe),J&&q.setState(J),P=!1,me(q,pe.QueryStore)}function lr(e){return typeof e?.storageKey==`string`}function ur(e,t){return n=>{let r={...n},i=o();for(let e in r)O(r,e)&&e in tr&&(tr[e]&&(i[e]=r[e]),delete r[e]);return{...t?t(r):wt(r),...dr(e,null,i)}}}function dr(e,t,n){if(!n.queryCache)return n;let r=Date.now(),i=o(),a=!1;for(let o in n.queryCache){if(!O(n.queryCache,o))continue;let s=n.queryCache[o];s&&(r-(s.lastFetchedAt??s.errorInfo.lastFailedAt)<s.cacheTime||o===t||e&&o===n.queryKey)?i[o]=s:a=!0}return a?{...n,queryCache:i}:n}function fr(){return Object.create(null)}function pr(e,t,n){return new j(`[createQueryStore: ${e}]: ${t} failed`,n)}function mr(e,t,n){return n?n(e,t):e}const hr=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});function gr(e,t,n){let r=typeof t==`function`,i=r?t:void 0,a=r?n:t,o=new Set,s,c;function l(e,t){let n=e.getState(),r=t.getState();if(c)for(let e of c)u(e,t,n,r);if(s)for(let e of s)d(e,t,n,r);o.size&&Ke();for(let e of o)f(e,t,n,r)}function u(e,t,n,r){e.unsubscribe(),e.unsubscribe=_r(t,e.listener),!Object.is(r,n)&&(Ge(),e.listener(r,n))}function d(e,t,n,r){f(e,t,n,r)&&Ge()}function f(e,t,n,r){e.unsubscribe();let i=e.args;if(i.length===1){let a=i[0];e.unsubscribe=t.subscribe(a);let o=!Object.is(r,n);return o&&a(r,n),o}let a=i[0],o=i[1],s=i[2];s?.fireImmediately&&(s={...s,fireImmediately:!1});let c=a(n),l=a(r);return e.unsubscribe=t.subscribe(a,o,s),(s?.equalityFn??Object.is)(c,l)?!1:(o(l,c),!0)}function p(e,t){l(t,e),he(t)}let m=jn(e,{debugMode:a?.debugMode??!1,lockDependencies:a?.lockDependencies??!0}),h;function g(){return h??(h=m.subscribe(p)),m.getState()}function _(...e){let t=g(),n={args:e,unsubscribe:e.length===1?t.subscribe(e[0]):t.subscribe(e[0],e[1],e[2])},r=e[2]?.isCascadeParticipant??!1;return r?(s??(s=new Set)).add(n):o.add(n),()=>{n.unsubscribe(),r?s?.delete(n)&&s.size===0&&(s=void 0):o.delete(n)}}function v(e){let t={listener:e,unsubscribe:_r(g(),e)};return(c??(c=new Set)).add(t),e=>{t.unsubscribe(e),c?.delete(t)&&c.size===0&&(c=void 0)}}return Object.assign({[Q]:v,[pe.VirtualStore]:!0,destroy:()=>{h?.(),h=void 0,m.destroy()},getInitialState:()=>g().getInitialState(),getState:()=>g().getState(),persist:vr(g),setState:yr(g),subscribe:_},i?.(g))}function _r(e,t){return nt(e)?e[Q](t):e.subscribe(a,t,hr)}function vr(e){return{clearStorage:()=>e().persist?.clearStorage(),getOptions:()=>e().persist?.getOptions()??{},hasHydrated:()=>e().persist?.hasHydrated()??!0,hydrationPromise:()=>e().persist?.hydrationPromise?.()??Promise.resolve(),onFinishHydration:t=>e().persist?.onFinishHydration(t)??c,onHydrate:t=>e().persist?.onHydrate(t)??c,rehydrate:()=>e().persist?.rehydrate(),setOptions:t=>e().persist?.setOptions(t)}}function yr(e){return function(...t){return t[1]===!0?e().setState(t[0],!0):e().setState(t[0])}}function br(e,t){let n=Kt(e,t);return x(n,n.getState,n.getInitialState)}function xr(e,t=Object.is){let n=jn(e,t);return x(n,n.getSnapshot,void 0)}function Sr(e,t,n){let r=cr(e,t,n);return x(r,r.getState,r.getInitialState)}function Cr(e,t,n){let r=gr(e,t,n);return x(r,r.getState,r.getInitialState)}const wr=Symbol();function Tr(t){let n=(0,e.useRef)(wr);return n.current===wr&&(n.current=t()),n}const Er=Object.freeze({debugMode:!1,enabled:!0,equalityFn:Object.is,fireImmediately:!1});function Dr(t,n,r,i=Er){let a=Tr(()=>jr(n,r,i)),o=Nr(i);return Pr(a,n,r,i),(0,e.useLayoutEffect)(()=>{if(o)return kr(t,a),()=>Ar(a)},[o,t]),a}const Or=Object.freeze({fireImmediately:!1,forceResubscribe:!1});function kr(e,t,n=Or){let i=t.current;if(i.isActive){if(!n.forceResubscribe)return;i.unsubscribe()}let a=Mr(i.options),o=a.equalityFn??Object.is,s=i.selector(e.getState()),l=c;function u(t){if(!i.isActive)return;let n=i.selector(t);if(o(s,n))return;let r=s;s=n,i.react(n,r,e.getState,i.unsubscribe)}if(i.isActive=!0,i.resubscribe=(n=Or)=>kr(e,t,n),i.refresh=()=>u(e.getState()),i.unsubscribe=()=>{i.isActive&&(i.isActive=!1,i.refresh=c,l())},l=e.subscribe(u),!i.isActive){l();return}r&&a.debugMode&&console.log(`[πŸ“‘ useListen πŸ“‘] Attached listener`),(n.fireImmediately||a.fireImmediately)&&i.react(s,s,e.getState,i.unsubscribe)}function Ar(e){let t=e.current;t.resubscribe=c,t.unsubscribe(),t.unsubscribe=c,t.isActive=!1,!(!r||typeof t.options==`function`)&&t.options?.debugMode&&console.log(`[πŸ—‘οΈ useListen πŸ—‘οΈ] Detached listener`)}function jr(e,t,n){return{selector:e,react:t,isActive:!1,options:n,refresh:c,resubscribe:c,unsubscribe:c}}function Mr(e){return typeof e==`function`?{equalityFn:e}:e??Er}function Nr(e){return typeof e==`function`?Er.enabled:e?.enabled??Er.enabled}function Pr(e,t,n,r){let i=e.current;i.selector=t,i.react=n,i.options=r}const Fr=Symbol();function Ir(t){let n=(0,e.useRef)(Fr);return n.current===Fr&&(n.current=t()),n.current}exports.QueryStatuses=U,exports.StoresError=j,exports.applyStateUpdate=ce,exports.configureStores=R,exports.createBaseStore=br,exports.createDerivedStore=xr,exports.createQueryStore=Sr,exports.createStoreActions=we,exports.createVirtualStore=Cr,exports.deepEqual=Oe,exports.defaultRetryDelay=se,exports.destroyStore=he,exports.destroyStores=ge,exports.getQueryKey=Bn,exports.getStoreName=_e,exports.hasGetSnapshot=be,exports.identity=a,exports.isDerivedStore=xe,exports.isPersistedStore=Se,exports.isQueryStore=J,exports.isVirtualStore=Ce,exports.nullObject=o,exports.parseQueryKey=Vn,exports.queryParam=Rn,exports.replacer=de,exports.reviver=fe,exports.shallowEqual=ke,exports.time=W,exports.useListen=Dr,exports.useStableValue=Ir;
@@ -3,5 +3,5 @@ import{createRequire as e}from"node:module";import{useDebugValue as t,useLayoutE
3
3
  Persisted stores require a storage backend. Either:
4
4
  - Install MMKV (the default): yarn add react-native-mmkv
5
5
  - Or provide a custom adapter via configureStores()
6
- `+(e instanceof Error?`\n${e.message}`:``))}return A(t),t}return{clearAll:()=>n().clearAll(),contains:e=>n().contains(e),delete:e=>n().delete(e),get:e=>n().get(e),getAllKeys:()=>n().getAllKeys(),set:(e,t)=>n().set(e,t)}}function k(e){let{createMMKV:t,MMKV:n}=s(`react-native-mmkv`);if(typeof t==`function`)return t({id:e});if(typeof n==`function`)return new n({id:e});throw Error(`[stores]: react-native-mmkv module does not export MMKV/createMMKV.`)}function A(e){if(!e||typeof e.get!=`function`||typeof e.set!=`function`||typeof e.delete!=`function`||typeof e.clearAll!=`function`)throw Error(`[stores]: Storage instance does not conform to expected interface`)}let j={debug:(e,t)=>{l&&console.debug(e,t)},error:(e,t)=>{l&&!u&&console.error(e,t)},info:(e,t)=>{l&&console.info(e,t)},warn:(e,t)=>{l&&console.warn(e,t)}};function ee(e){j=e}const M=Object.prototype.hasOwnProperty;function N(e,t){return M.call(e,t)}function P(e){let t=e.charCodeAt(0);if(t<48||t>57)return!1;let n=Number(e);return Number.isInteger(n)&&n<4294967295&&String(n)===e}function F(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function I(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var L=class extends Error{constructor(e,t){super(e),this.name=`StoresError`,t!==void 0&&Object.defineProperty(this,"cause",{configurable:!0,value:t,writable:!0})}};function te(e){return e instanceof Error?e:Error(String(e))}var R=class{destroy(){}publish(){}},z=class{constructor(){this.sessionId=`noop`}register(e){return new R}};let B;function V(){return B||(B=new z),B}let H,U,ne=!1;function re(e){l&&se(),e.logger&&ee(e.logger),H??(H=G(e)),U??(U=oe(e))}function W(){if(H)return H}function ie(){return U??(U=oe(void 0))}function ae(){ne=!0}function G(e){if(e?.queryStoreDefaults)return{queryStoreDefaults:e.queryStoreDefaults}}function oe(e){return{storage:e?.storage??O(e?.storageKeyPrefix??`stores:`),syncEngine:e?.syncEngine??V()}}function se(){if(ne)throw Error(`[stores]: configureStores() called after first store creation. Call it earlier before creating any stores.`)}const K={Error:`error`,Idle:`idle`,Loading:`loading`,Success:`success`},q={ms:e=>{"worklet";return e},seconds:e=>{"worklet";return e*1e3},minutes:e=>{"worklet";return e*6e4},hours:e=>{"worklet";return e*36e5},days:e=>{"worklet";return e*864e5},weeks:e=>{"worklet";return e*6048e5},infinity:1/0,zero:0};let ce;function le(){return ce??(ce=ue())}function ue(){let e=W()?.queryStoreDefaults;return{abortInterruptedFetches:e?.abortInterruptedFetches??!0,cacheTime:e?.cacheTime??q.days(7),debugMode:e?.debugMode??!1,disableAutoRefetching:e?.disableAutoRefetching??!1,keepPreviousData:e?.keepPreviousData??!1,minStaleTime:e?.minStaleTime??!1,onError:e?.onError,paramChangeThrottle:e?.paramChangeThrottle??!1,retry:e?.retry??5,retryDelay:e?.retryDelay,staleTime:e?.staleTime??q.minutes(2),suppressStaleTimeWarning:e?.suppressStaleTimeWarning??!1}}function de(e,t){let n=t?.baseDelay??q.seconds(5),r=t?.maxDelay??q.minutes(5);return Math.min(n*2**e,r)}function fe(e,t){return t[1]===!0?e(t[0],!0):e(t[0])}function pe(e,t,n){if(n===!0)return me(t)?t(e):t;let r=me(t)?t(e):t;return Object.is(r,e)?e:!I(e)||!I(r)?r:{...e,...r}}function me(e){return typeof e==`function`}function he(e){return typeof e==`object`&&!!e&&`__type`in e&&e.__type===`Map`}function ge(e){return typeof e==`object`&&!!e&&`__type`in e&&e.__type===`Set`}function _e(e,t){return t instanceof Map?{__type:`Map`,entries:Array.from(t.entries())}:t instanceof Set?{__type:`Set`,values:Array.from(t)}:t}function ve(e,t){return he(t)?new Map(t.entries):ge(t)?new Set(t.values):t}const ye=Object.freeze({QueryStore:Symbol(`queryStore`),VirtualStore:Symbol(`virtualStore`)});function be(e,t){return Object.assign(e,{[t]:!0})}function J(e,t){Ee(e)?e.getState().reset(t?.clearQueryCache):we(e)&&e.destroy()}function xe(e,t){for(let n of Array.isArray(e)?e:Object.values(e))!n||t?.skipDestroy?.(n)||J(n,t)}function Se(e){let t=Ce(e);return Oe(e)?e.persist.getOptions().name??t:t}function Ce(e){return typeof e==`function`?e.name:``}function we(e){return`destroy`in e}function Te(e){return`getSnapshot`in e}function Ee(e){return ye.QueryStore in e}function De(e){return`flushUpdates`in e}function Oe(e){return!(`persist`in e)||!e.persist?!1:typeof e.persist.getOptions().name==`string`}function ke(e){return ye.VirtualStore in e}function Ae(e,t){let n=je(e);return t?Object.assign(n,t):n}function je(e){let t=e.getState(),n=f(),r=n;if(l&&!(typeof t==`object`&&t))throw Error(`[createStoreActions]: State is not an object`);if(ke(e))for(let n in t)Ne(t,n)&&(r[n]=Me(e,n));else for(let e in t)Ne(t,e)&&(r[e]=t[e]);return n}function Me(e,t){return function(...n){let r=e.getState()[t];if(typeof r==`function`)return r(...n);throw Error(`[createVirtualStoreAction]: Method ${String(t)} is not a function`)}}function Ne(e,t){return typeof e[t]==`function`}function Pe(e,t){"worklet";if(typeof e!=`object`||!e||e===void 0||typeof t!=`object`||!t||t===void 0)return e===t;if(Object.is(e,t))return!0;let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let r of n)if(!(r in t)||!Pe(e[r],t[r]))return!1;return!0}function Fe(e,t){"worklet";if(typeof e!=`object`||!e||e===void 0||typeof t!=`object`||!t||t===void 0)return e===t;if(Object.is(e,t))return!0;let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let r of n)if(!Object.is(e[r],t[r]))return!1;return!0}function Ie(e,t){let n=Object.prototype.hasOwnProperty;function r(e,t){for(let n of e.keys())if(Ie(n,t))return n}let i,a,o;if(e===t)return!0;if(e&&t&&(i=e.constructor)===t.constructor){if(i===Date)return e.getTime()===t.getTime();if(i===RegExp)return e.toString()===t.toString();if(i===Array){if((a=e.length)===t.length)for(;a--&&Ie(e[a],t[a]););return a===-1}if(i===Set){if(e.size!==t.size)return!1;for(let n of e)if(o=n,o&&typeof o==`object`&&(o=r(t,o),!o)||!t.has(o))return!1;return!0}if(i===Map){if(e.size!==t.size)return!1;for(let n of e)if(o=n[0],o&&typeof o==`object`&&(o=r(t,o),!o)||!Ie(n[1],t.get(o)))return!1;return!0}if(i===ArrayBuffer)e=new Uint8Array(e),t=new Uint8Array(t);else if(i===DataView){if((a=e.byteLength)===t.byteLength)for(;a--&&e.getInt8(a)===t.getInt8(a););return a===-1}if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(t)){let n=e,r=t;if((a=n.byteLength)===r.byteLength)for(;a--&&n[a]===r[a];);return a===-1}if(!i||typeof e==`object`){a=0;for(let r in e)if(n.call(e,r)&&++a&&!n.call(t,r)||!(r in t)||!Ie(e[r],t[r]))return!1;return Object.keys(t).length===a}}return e!==e&&t!==t}function Le(e,t,n){if(t===0)return n;if(t===1){if(e===n)return null;let t=new Set;return t.add(e),t.add(n),t}return e.add(n),e.size===t?null:e}function Re(e,t,n){if(t===0)return null;if(t===1)return e===n?void 0:null;if(!e.delete(n))return null;if(t!==2)return e;for(let t of e)return t}function ze(e,t,n,r,i){if(t!==0){if(t===1){n(e,r,i);return}for(let t of e)n(t,r,i)}}function Be(e,t){t>1&&e.clear()}const Ve=o;let Y=!1,He=!1,Ue=!1,X,We,Ge=0;const Ke=new Map;let qe=0,Je=null,Z=1/0;function Ye(){return Y}function Xe(){return Je}function Ze(){Y||(Y=!0,!Ue&&(Ue=!0,queueMicrotask(()=>{Ue=!1,Qe()})))}function Qe(){if(Y){if(He){nt();return}He=!0;try{Ve(nt)}finally{ot()}}}function $e(){if(Y){if(He){Je===null&&rt();return}He=!0;try{rt()}catch(e){throw ot(),e}finally{He=!1,Je=null}}}function et(e){if(Y){if(We){We.push(e);return}if(!X){X=e;return}We=[X,e],X=void 0}}function tt(e,t){if(!Y)return;let n=t<0?0:t|0,r=Ke.get(n);r||(r=[],Ke.set(n,r)),r.push(e),qe+=1,n<Z&&(Z=n)}function nt(){for(;qe>0||st();)rt(),at()}function rt(){for(;qe>0;){let e=Z,t=Ke.get(e);if(!t){Z=1/0;for(let e of Ke.keys())e<Z&&(Z=e);continue}Ke.delete(e),qe-=t.length,it(),Je=e;for(let e=0;e<t.length;e++)t[e]();Je=null}}function it(){Z=1/0;for(let e of Ke.keys())e<Z&&(Z=e)}function at(){for(;;){let e=X;if(e){X=void 0,e();continue}let t=We;if(!t)return;for(;Ge<t.length;)t[Ge++]();We=void 0,Ge=0;return}}function ot(){Y=!1,He=!1,Je=null,X=void 0,We=void 0,Ge=0,Ke.clear(),qe=0,Z=1/0}function st(){return!!X||!!We}const Q=Symbol(`stores.subscribeCascadeState`);function ct(e){return Q in e}function lt(e,t){ct(e)&&(e[Q]=t(e[Q]))}const ut=Symbol(),dt=Symbol();function ft(e){let t,n,r,i=0;function a(e,a,o){let s=pe(t,e,a);if(Object.is(s,t))return o===ut?dt:void 0;let c=t;if(t=s,ze(r,i,h,t,c),n){Qe();for(let e of n)e(t,c)}}function o(){return t}function s(){return u}function c(e,t,n){return t?g(e,t,n):d(e)}let l={[Q]:p,getInitialState:s,getState:o,setState:a,subscribe:c},u=t=pt(e)?e(a,o,l):e;return l;function d(e){return(n??(n=new Set)).add(e),()=>{n?.delete(e),n?.size===0&&(n=void 0)}}function f(e){let t=Le(r,i,e);return t!==null&&(r=t,i+=1),()=>m(e)}function p(e){function t(t,n){Ze(),e(t,n)}return f(t)}function m(e){let t=Re(r,i,e);t!==null&&(r=t,--i)}function g(e,n,r){let i=r?.equalityFn??Object.is,a=r?.isCascadeParticipant??!1,o=e(t);function s(t){let r=e(t);if(i(o,r))return;let s=o;o=r,a&&Ze(),n(r,s)}return r?.fireImmediately&&n(o,o),a?f(s):d(s)}}function pt(e){return typeof e==`function`}function mt(e){return!!e&&typeof e==`object`&&`then`in e&&typeof e.then==`function`}const ht=Object.freeze({migrated:!1,state:void 0});function gt(e,t,n){return(r,i,a)=>{let o=vt(t),s,c=!1,l=0,u,d,f;function p(e){return o.storage.setItem(o.name,e,o.version)}function m(e,t){return(t===!0?r(e,t,ut):r(e,!1,ut))===dt?n?s??(s=Promise.resolve()):void 0:p(i())}a.setState=m;let h=e(m,i,a);a.getInitialState=()=>h;function g(){let e=x(),t=o.onRehydrateStorage?.(i()??h);try{let n=o.storage.getItem(o.name);return mt(n)?n.then(n=>_(e,n,t)).catch(n=>C(e,t,n)):_(e,n,t)}catch(n){C(e,t,n)}}return Object.assign(a,{persist:b()}),o.skipHydration||g(),u??h;function _(e,t,n){let r=_t(o,t);return mt(r)?r.then(t=>v(e,t,n)).catch(t=>C(e,n,t)):v(e,r,n)}function v(e,t,n){let r=y(e,t);if(mt(r))return r.then(()=>S(e,n));S(e,n)}function y(e,t){if(e!==l)return;let n=o.merge(t.state,i()??h);if(u=n,r(n,!0),t.migrated)return p(i())}function b(){return{clearStorage:()=>{o.storage.removeItem(o.name)},getOptions:()=>o,hasHydrated:()=>c,onFinishHydration:e=>(f??(f=new Set),f.add(e),()=>{f?.delete(e),f?.size===0&&(f=void 0)}),onHydrate:e=>(d??(d=new Set),d.add(e),()=>{d?.delete(e),d?.size===0&&(d=void 0)}),rehydrate:g,setOptions:e=>{o=vt({...o,...e,storage:e.storage??o.storage})}}}function x(){let e=++l;return c=!1,d?.forEach(e=>e(i()??h)),e}function S(e,t){if(e!==l)return;t?.(u,void 0);let n=i();u=n,c=!0,f?.forEach(e=>e(n))}function C(e,t,n){e===l&&t?.(void 0,n)}}}function _t(e,t){if(!t)return ht;if(typeof t.version!=`number`||t.version===e.version)return{migrated:!1,state:t.state};if(!e.migrate)return console.error(`State loaded from storage couldn't be migrated since no migrate function was provided`),ht;let n=e.migrate(t.state,t.version);return mt(n)?n.then(e=>({migrated:!0,state:e})):{migrated:!0,state:n}}function vt(e){return{...e,merge:e.merge??yt,skipHydration:e.skipHydration??!1}}function yt(e,t){return e===void 0?t:{...t,...e}}function bt(){let e=!1,t,n,r=new Promise((e,r)=>{t=e,n=r});function i(){e||!t||(e=!0,t(),t=void 0,n=void 0)}function a(r){e||!n||(e=!0,n(r),n=void 0,t=void 0)}function o(){return e}return{complete:i,isHydrated:o,fail:a,promise:r}}function xt(e){let t,n=!1,r,i;return{hydrationPromise:()=>n?t?.promise??r??(r=Promise.resolve()):(t||(t=bt()),t.promise),stateCreator:(r,a,o)=>{let s;function c(...e){return n?fe(r,e):(t||(t=bt()),s||(s=[]),s.push(e),t.promise)}return i=()=>{if(s?.length){for(let e of s)fe(o.setState,e);s=void 0}},e(c,a,o)},wrapOnRehydrateStorage:(e,r)=>a=>{let o=e?.(a);return(e,a)=>{n=!0,r?.onHydrationComplete?.(),i&&i(),r?.onHydrationFlushEnd?.(),a?t?.fail(te(a)):t?.complete(),o?.(e,a)}}}}function St(e){let t,n=null;function r(...r){return t=r,n||(n=new Promise(r=>{queueMicrotask(async()=>{try{await e(...t)}finally{n=null,r()}})})),n}return r}const Ct=Math.max,wt=Math.min;function Tt(e,t=0,n={}){let r,i,a,o,s,c,l=0,u=!1,d=!1,f=!0;if(typeof e!=`function`)throw TypeError(`Expected a function`);t=Dt(t)||0,Ot(n)&&(u=!!n.leading,d=`maxWait`in n,a=d?Ct(Dt(n.maxWait)||0,t):void 0,f=`trailing`in n?!!n.trailing:f);function p(t){let n=r,a=i;return r=i=void 0,l=t,o=n?e.apply(a,n):e.apply(a),o}function m(e){return l=e,s=setTimeout(_,t),u?p(e):o}function h(e){let n=e-(c??0),r=e-l,i=t-n;return d&&a!==void 0?wt(i,a-r):i}function g(e){let n=e-(c??0),r=e-l;return c===void 0||n>=t||n<0||d&&a!==void 0&&r>=a}function _(){let e=Et();if(g(e))return v(e);s=setTimeout(_,h(e))}function v(e){return s=void 0,f&&r?p(e):(r=i=void 0,o)}function y(){s!==void 0&&clearTimeout(s),l=0,r=c=i=s=void 0}function b(){return s===void 0?o:v(Et())}function x(...e){let n=Et(),a=g(n);if(r=e,i=this,c=n,a){if(s===void 0)return m(c);if(d)return clearTimeout(s),s=setTimeout(_,t),p(c)}return s===void 0&&(s=setTimeout(_,t)),o}return x.cancel=y,x.flush=b,x}function Et(){return typeof performance<`u`&&typeof performance.now==`function`?performance.now():Date.now()}function Dt(e){if(typeof e==`number`)return e;if(typeof e==`symbol`||e===void 0)return NaN;if(typeof e==`object`&&e){let t=typeof e.valueOf==`function`?e.valueOf():e;e=typeof t==`object`?t+``:t}return typeof e==`string`?(e=e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,``),/^0b[01]+$/i.test(e)?parseInt(e.slice(2),2):/^0o[0-7]+$/i.test(e)?parseInt(e.slice(2),8):/^[-+]0x[0-9a-f]+$/i.test(e)?NaN:+e):e===0?e:+e}function Ot(e){let t=typeof e;return e!==null&&(t===`object`||t===`function`)}function kt(e){if(!F(e))return e;let t=f(),n=Object.keys(e);for(let r=0;r<n.length;r++){let i=n[r],a=e[i];typeof a!=`function`&&(t[i]=a)}return t}function At(e,t){try{return JSON.stringify(e,t?_e:void 0)}catch(e){throw j.error(new L(`[createBaseStore]: Failed to serialize store data`,e)),e}}function jt(e,t){try{return JSON.parse(e,t?ve:void 0)}catch(e){throw j.error(new L(`[createBaseStore]: Failed to deserialize persisted store data`,e)),e}}const Mt=u?0:c?q.seconds(3):q.seconds(5);function Nt(e,t,n){let r=t??e.storage??ie().storage,i=(e.sync?void 0:e.persistThrottleMs??Mt)||void 0,a=e.version??0;return r.async?{async:!0,persistStorage:Ft(r,e,i,n),version:a}:{async:!1,persistStorage:Pt(r,e,i,n),version:a}}function Pt(e,t,n,r){let i=!t.deserializer&&!t.serializer&&!e.deserializer&&!e.serializer,a=typeof t.sync==`object`&&(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata)===!0,o=t.partialize??kt,s=t.deserializer??e.deserializer??It(i),c=t.serializer??e.serializer??Lt(i);function l(t,n,i){try{if(Ht(r))return;let s={state:o(n),version:i},l=zt(r,a,s),u=c(s);try{e.set(t,u),Bt(r,l)}catch(e){j.error(new L(`[createBaseStore]: Failed to persist store data`,e))}}catch(e){j.error(new L(`[createBaseStore]: Failed to persist store data`,e))}}let u=n===void 0?l:Tt(l,n,{leading:!1,maxWait:n,trailing:!0});return{getItem:t=>{let n=e.get(t);return n===void 0?null:s(n)},setItem:(e,t,n)=>{r?.getIsApplyingRemote()||u(e,t,n)},removeItem:t=>{try{e.delete(t)}catch(e){j.error(new L(`[createBaseStore]: Failed to delete persisted store data`,e))}}}}function Ft(e,t,n,r){let i=!t.deserializer&&!t.serializer&&!e.deserializer&&!e.serializer,a=typeof t.sync==`object`&&(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata)===!0,o=t.partialize??kt,s=t.deserializer??e.deserializer??It(i),c=t.serializer??e.serializer??Lt(i);async function l(t,n,i){try{if(Ht(r))return;let s={state:o(n),version:i},l=zt(r,a,s),u=c(s);try{await e.set(t,u),Bt(r,l)}catch(e){j.error(new L(`[createBaseStore]: Failed to persist store data`,e))}}catch(e){j.error(new L(`[createBaseStore]: Failed to serialize persisted store data`,e))}}let u=n===void 0?St(l):Tt(l,n,{leading:!1,maxWait:n,trailing:!0});return{getItem:async t=>{let n=await e.get(t);return n===void 0?null:s(n)},setItem:async(e,t,n)=>{if(!r?.getIsApplyingRemote())return await u(e,t,n)},removeItem:async t=>{try{await e.delete(t)}catch(e){j.error(new L(`[createBaseStore]: Failed to delete persisted store data`,e))}}}}function It(e){return t=>{if(typeof t!=`string`)throw new L(`[createBaseStore]: Received non-string serialized state without a custom deserializer. Provide a deserializer on the store or storage adapter.`);return jt(t,e)}}function Lt(e){return t=>At(t,e)}const Rt=Object.freeze({shouldClear:!1});function zt(e,t,n){if(!t||!e)return Rt;let r=e.getFieldTimestampSnapshot();return Vt(e,n),n.syncMetadata?r&&Object.keys(r).length>0?(n.syncMetadata.fields=r,{fieldSnapshot:r,shouldClear:!0}):(delete n.syncMetadata.fields,{fieldSnapshot:r,shouldClear:!1}):{fieldSnapshot:r,shouldClear:!1}}function Bt(e,t){!e||!t.shouldClear||!t.fieldSnapshot||!Object.keys(t.fieldSnapshot).length||e.clearFieldTimestamps(t.fieldSnapshot)}function Vt(e,t){let n=e.getSessionId(),r=e.getTimestamp();n!==void 0&&r!==void 0&&(t.syncMetadata={origin:n,timestamp:r})}function Ht(e){return e?!!e.getIsApplyingRemote():!1}function Ut(e,t,n){let r=t.engine??ie().syncEngine;return(i,a,o)=>{let s=new Map,c=[],l=[],u=null,d=!1,p=!1,m=0,h=null,g=[],_=Promise.resolve(),v=!n?.isAsync;function y(){let e=Date.now(),t=e>m?e:m+1;return m=t,t}function b(e,t){if(!(!n||!r.sessionId)&&(n.setSessionId(r.sessionId),n.setTimestamp(e),t.length>0)){let r=f();for(let n of t)r[String(n)]=e;n.mergeFieldTimestamps(r)}}function x(e,t,n,i=!1){let a=r.sessionId;for(let t of e)s.set(t,[n,a]);!u||!p?l.push({keys:e,replace:i,timestamp:n,values:t}):u.publish?.({replace:i,sessionId:a,timestamp:n,values:t})}function S(){if(!(!u||!l.length)){for(let e of l){let t=r.sessionId;for(let n of e.keys)s.set(n,[e.timestamp,t]);b(e.timestamp,e.keys),u.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values})}l.length=0}}function C(e,t){if(d||!h)return t?i(e,t):i(e);let n=y(),r,a,o=t?i(s,!0):i(s);if(!r||!a)return o;function s(i){let o=pe(i,e,t);for(let e of g)Object.is(o[e],i[e])||((r??(r=[])).push(e),(a??(a=f()))[e]=o[e]);return r&&b(n,r),o}return mt(o)?o.finally(x.bind(void 0,r,a,n,t)):(x(r,a,n,t),o)}let w=o.setState;o.setState=C;let T=e(C,a,o);if(g=t.fields??Kt(T),!g.length)return T;h=new Set(g);async function E(e){m=Math.max(m,e.timestamp);let r=f(),i=a(),o=e.timestamp,c;if(e.replace)for(let t of g)N(e.values,t)||Gt(s.get(t),o,e.sessionId)&&(c??(c=[])).push(t);for(let n of g){if(!Yt(e.values,n)||!h?.has(n)||!Gt(s.get(n),o,e.sessionId))continue;let a=t.merge?.[n];if(a){let t=e.values[n],c=i[n];if(t!==void 0){let l=a(t,c,i,e.values),u=c===void 0?t:c;if(!Jt(l,u)){j.error(new L(`[sync] Merge function for field "${String(n)}" returned ${qt(l)} but expected ${qt(u)}`));return}r[n]=l,s.set(n,[o,e.sessionId])}}else r[n]=e.values[n],s.set(n,[o,e.sessionId])}if(!(!(Object.keys(r).length>0)&&!c?.length)){d=!0,n?.setIsApplyingRemote(!0);try{if(e.replace){let e={...i},t=!1;if(c?.length){t=!0;for(let t of c)delete e[t],s.delete(t)}for(let n in r){if(!N(r,n))continue;let i=r[n];if(i===void 0)continue;Object.is(e[n],i)||(t=!0);let a=e;a[n]=i}if(!t)return;await(n?.setWithoutPersist??w)(e,!0)}else await(n?.setWithoutPersist??w)(r)}finally{d=!1,n?.setIsApplyingRemote(!1)}}}function D(e){n?.isAsync?_=_.then(()=>E(e)):E(e)}function O(){if(!c.length)return;let e=c.slice();c.length=0;for(let t of e)D(t)}if(u=r.register({apply:e=>{if(!v){c.push(e);return}D(e)},fields:g,getState:a,key:t.key}),u?.onFirstSubscribe||u?.onLastUnsubscribe){let e=u,t=0,n=o.subscribe;function r(n){return t++===0&&e.onFirstSubscribe?.(),r=>{n(r),--t,t||queueMicrotask(()=>{t||e.onLastUnsubscribe?.()})}}o.subscribe=(...e)=>r(e.length===1?n(e[0]):n(e[0],e[1],e[2])),lt(o,e=>t=>r(e(t)))}function k(){p=!0,S()}function A(){v=!0,O()}return n?.isAsync?(n.onHydrationComplete=k,n.onHydrationFlushEnd=A):u.onHydrated?(u.onHydrated(k),A()):(k(),A()),T}}function Wt(e){let t,n,r,i=!1;function a(e){if(!(!e||!r)){for(let t of Object.entries(e)){let e=t[0],n=t[1];r[e]===n&&delete r[e]}Object.keys(r).length||(r=void 0)}}function o(){if(r)return{...r}}function s(e){if(!r){r={...e};return}for(let t of Object.entries(e)){let e=t[0],n=t[1],i=r[e];(i===void 0||n>i)&&(r[e]=n)}}return{isAsync:e,clearFieldTimestamps:a,getFieldTimestampSnapshot:o,getIsApplyingRemote:()=>i,getSessionId:()=>t,getTimestamp:()=>n,mergeFieldTimestamps:s,onHydrationComplete:void 0,onHydrationFlushEnd:void 0,setIsApplyingRemote:e=>i=e,setSessionId:e=>t=e,setTimestamp:e=>n=e,setWithoutPersist:void 0}}function Gt(e,t,n){if(!e)return!0;let r=e[0],i=e[1];return t<r?!1:t>r?!0:n>i}function Kt(e){let t=[];for(let n of Object.keys(e))Xt(e,n)&&t.push(n);return t}function qt(e){if(e===null)return`null`;let t=typeof e;return t===`object`?Object.prototype.toString.call(e):t}function Jt(e,t){if(!l)return!0;if(e===null||t===null)return e===t;let n=typeof e;return n===typeof t?n===`object`?Object.prototype.toString.call(e)===Object.prototype.toString.call(t):!0:!1}function Yt(e,t){return N(e,t)}function Xt(e,t){return typeof e[t]!=`function`}function Zt(e,t){if(ae(),!t)return ft(e);let n=t.storageKey,r=typeof n==`string`,i=r?t.storage??ie().storage:void 0,a=Qt(t.sync,n),o=!i||!a?void 0:Wt(i.async??!1),s=a?Ut(e,a,o):e;if(!r)return ft(s);let c=Nt(t,i,o),l=c.async?xt(s):void 0,u=l?l.wrapOnRehydrateStorage(t.onRehydrateStorage,o):t.onRehydrateStorage,d=ft(gt(l?(e,t,n)=>(o&&(o.setWithoutPersist=n.setState),l.stateCreator(e,t,n)):s,{merge:t.merge,migrate:t.migrate,name:n,onRehydrateStorage:u,storage:c.persistStorage,version:c.version},c.async));return l?Object.assign(d,{persist:Object.assign(d.persist,{hydrationPromise:l.hydrationPromise})}):d}function Qt(e,t){if(!e)return null;let n=typeof e==`object`,r=n?e.key??t:e===!0?t:e;if(!r)throw new L(`[createBaseStore]: sync requires a key to be specified either directly or via storageKey`);return n?{...e,key:r}:{key:r}}function $t(e,t,n=`s`){return t===1?e:`${e}${n}`}const en=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});var tn=class{constructor(e){this.invalidate=e,this.stateDependencyRevisionStamp=0,this.stateDependencyRevision=0}beginRebuild(e){this.clearSelectors(e),this.stateDependencyRevision+=1}addSelector(e){let t=this.selectorUnsubscribes;if(!t){this.selectorUnsubscribes=e;return}if(typeof t==`function`){this.selectorUnsubscribes=[t,e];return}t.push(e)}retainState(e){let t=this.stateDependencies;if(t){let n=t.get(e);if(n){n.revision=this.stateDependencyRevision;return}t.set(e,this.createStateDependency(e));return}let n=this.stateDependencyStore;if(!n){this.stateDependencyStore=e,this.stateDependencyRevisionStamp=this.stateDependencyRevision,this.stateDependencyUnsubscribe=this.subscribeState(e);return}if(n===e){this.stateDependencyRevisionStamp=this.stateDependencyRevision;return}let r=this.stateDependencyUnsubscribe;this.stateDependencyStore=void 0,this.stateDependencyUnsubscribe=void 0,this.stateDependencies=new Map,r&&this.stateDependencies.set(n,{revision:this.stateDependencyRevisionStamp,unsubscribe:r}),this.stateDependencies.set(e,this.createStateDependency(e))}finishRebuild(e){this.stateDependencyStore&&this.stateDependencyRevisionStamp!==this.stateDependencyRevision&&(this.stateDependencyUnsubscribe?.(e),this.stateDependencyStore=void 0,this.stateDependencyUnsubscribe=void 0);let t=this.stateDependencies;if(t){for(let n of t){let r=n[1];r.revision!==this.stateDependencyRevision&&(r.unsubscribe(e),t.delete(n[0]))}if(!t.size){this.stateDependencies=void 0;return}if(t.size===1){for(let e of t){this.stateDependencyStore=e[0],this.stateDependencyRevisionStamp=e[1].revision,this.stateDependencyUnsubscribe=e[1].unsubscribe;break}this.stateDependencies=void 0}}}clear(e){this.clearSelectors(e),this.stateDependencyUnsubscribe?.(e),this.stateDependencyStore=void 0,this.stateDependencyUnsubscribe=void 0;let t=this.stateDependencies;if(t){for(let n of t)n[1].unsubscribe(e);this.stateDependencies=void 0}}get size(){let e=this.selectorUnsubscribes;return(typeof e==`function`?1:e?.length??0)+ +!!this.stateDependencyStore+(this.stateDependencies?.size??0)}clearSelectors(e){let t=this.selectorUnsubscribes;if(this.selectorUnsubscribes=void 0,t){if(typeof t==`function`){t(e);return}for(let n=0;n<t.length;n++)t[n](e)}}createStateDependency(e){return{revision:this.stateDependencyRevision,unsubscribe:this.subscribeState(e)}}subscribeState(e){return ct(e)?e[Q](this.invalidate):e.subscribe(d,this.invalidate,en)}},nn=class{constructor(){this.watcherCount=0,this.ordinaryWatcherCount=0,this.cascadeParticipantCount=0,this.cascadeStateListenerCount=0}addWatcher(e){let t=Le(this.watchers,this.watcherCount,e);return t===null?!1:(this.watchers=t,this.watcherCount+=1,sn(e)?this.cascadeParticipantCount+=1:this.ordinaryWatcherCount+=1,!0)}deleteWatcher(e){let t=Re(this.watchers,this.watcherCount,e);return t===null?!1:(this.watchers=t,--this.watcherCount,sn(e)?--this.cascadeParticipantCount:--this.ordinaryWatcherCount,!0)}addCascadeStateListener(e){let t=Le(this.cascadeStateListeners,this.cascadeStateListenerCount,e);return t===null?!1:(this.cascadeStateListeners=t,this.cascadeParticipantCount+=1,this.cascadeStateListenerCount+=1,!0)}deleteCascadeStateListener(e){let t=Re(this.cascadeStateListeners,this.cascadeStateListenerCount,e);return t===null?!1:(this.cascadeStateListeners=t,--this.cascadeParticipantCount,--this.cascadeStateListenerCount,!0)}notifyCascade(e,t){ze(this.cascadeStateListeners,this.cascadeStateListenerCount,h,e,t),this.cascadeParticipantCount!==this.cascadeStateListenerCount&&ze(this.watchers,this.watcherCount,rn,e,t)}notifyOrdinary(e,t){ze(this.watchers,this.watcherCount,an,e,t)}clear(){this.watchers=Be(this.watchers,this.watcherCount),this.cascadeStateListeners=Be(this.cascadeStateListeners,this.cascadeStateListenerCount),this.watcherCount=0,this.ordinaryWatcherCount=0,this.cascadeParticipantCount=0,this.cascadeStateListenerCount=0}};function rn(e,t,n){typeof e==`function`||!e.isCascadeParticipant||on(e,t)}function an(e,t,n){if(typeof e==`function`){e(t,n);return}e.isCascadeParticipant||on(e,t)}function on(e,t){let n=e.selector(t);if(e.equalityFn(e.currentSlice,n))return;let r=e.currentSlice;e.currentSlice=n,e.listener(n,r)}function sn(e){return typeof e!=`function`&&e.isCascadeParticipant}const cn=Symbol(`stores.deriveProxy.unwrap`);function ln(e,t,n,r){let i=n.get(e);if(vn(i))return i;let a=un(t,e,r);return n.set(e,a),a}function un(e,t,n,r=[]){return!e||typeof e!=`object`?(n(t,r,!0),e):dn(e,r,t,n,new WeakSet,new WeakMap)}function dn(e,t,n,r,i,a){let o=Array.isArray(e);return new Proxy(e,{get(s,c,l){if(c===cn)return r(n,t,!0),s;if(i.has(s))return Reflect.get(s,c,l);if(c===`__proto__`||typeof c==`symbol`)return c===Symbol.iterator&&(r(n,t,!0),i.add(s)),Reflect.get(s,c,l);if(o&&P(c))return r(n,t,!0),i.add(s),Reflect.get(s,c,l);let u=Reflect.get(s,c,s),d=String(c),f=t.concat(d);if(typeof u==`function`)return N(s,c)?function(...e){return r(n,f,!0,{args:e.length?e:void 0}),Reflect.apply(u,s,e)}:(r(n,t,!0),u.bind(e));let p=!!u&&typeof u==`object`;return r(n,f,!p),p?(a.has(u)||a.set(u,dn(u,f,n,r,i,a)),a.get(u)):u},getOwnPropertyDescriptor(e,a){return r(n,t,!0),i.add(e),Reflect.getOwnPropertyDescriptor(e,a)},has(e,i){return r(n,t,!0),Reflect.has(e,i)},ownKeys(e){return r(n,t,!0),i.add(e),Reflect.ownKeys(e)}})}function fn(e,t){return!e||typeof e!=`object`?e:gn(e)||(Array.isArray(e)?pn(e,t):F(e)&&mn(e,t),e)}function pn(e,t){let n=_n(e,t);if(n)for(let t=0;t<e.length;t++)hn(e,String(t),n)}function mn(e,t){let n=_n(e,t);if(n)for(let t of Reflect.ownKeys(e))hn(e,t,n)}function hn(e,t,n){let r=Reflect.getOwnPropertyDescriptor(e,t);if(!r||!(`value`in r))return;let i=fn(r.value,n);i!==r.value&&(r.value=i,Reflect.defineProperty(e,t,r))}function gn(e){let t=Reflect.get(e,cn);return t&&typeof t==`object`?t:void 0}function _n(e,t){let n=t??new WeakSet;return n.has(e)?null:(n.add(e),n)}function vn(e){return e!==void 0}const yn=Object.freeze([]);function bn(){let e,t,n;return{buildProxySubscriptions(r,i,a){let o=[],s=t,c=e;if(s&&c)Cn(s,c,[],0,o,a);else if(n)for(let e of n)Cn(e[1],e[0],[],0,o,a);Dn(o,r,i)},reset(){e=void 0,t=void 0,n=void 0},trackPath(r,i,a,o){let s=t;if(s){let i=e;if(i!==r)if(!i)e=r;else{let a=n??(n=new Map);a.set(i,s),s=xn(),a.set(r,s),e=void 0,t=void 0}}else{let i=n;i?(s=i.get(r),s||(s=xn(),i.set(r,s))):(s=xn(),e=r,t=s)}Sn(s,i,a,o)}}}function xn(){return f()}function Sn(e,t,n,r){let i=e;for(let e=0;e<t.length;e++){let n=t[e],r=i.children,a;if(r)a=r[n],a||(a=r[n]=xn());else if(a=i.child,!a)a=xn(),i.child=a,i.childKey=n;else if(i.childKey!==n){let e=i.childKey;if(e===void 0)i.childKey=n;else{let t=xn();t[e]=a,a=t[n]=xn(),i.child=void 0,i.childKey=void 0,i.children=t}}i=a}n&&(i.isLeaf=!0),r&&wn(i,r)}function Cn(e,t,n,r,i,a=2){let o=e.child;if(o){let s=e.childKey;if(e.isLeaf){if(En(e,t,n,i),!o.invocation||s===void 0)return}else if(s===void 0){En(e,t,n,i);return}n.push(s),Cn(o,t,n,r+1,i,a),n.pop();return}let s=e.children;if(!s){En(e,t,n,i);return}if(e.isLeaf||r>=a){En(e,t,n,i);for(let e in s){let o=s[e];o.invocation&&(n.push(e),Cn(o,t,n,r+1,i,a),n.pop())}return}for(let e in s)n.push(e),Cn(s[e],t,n,r+1,i,a),n.pop()}function wn(e,t){let n=e.invocation;if(!n){e.invocation=t;return}if(Tn(n,t))return;let r=e.extraInvocations;if(!r){e.extraInvocations=[t];return}for(let e=0;e<r.length;e++)if(Tn(r[e],t))return;r.push(t)}function Tn(e,t){let n=e.args,r=t.args,i=n?.length??0;if(i!==(r?.length??0))return!1;if(!n||!r)return!0;for(let e=0;e<i;e++)if(!Object.is(n[e],r[e]))return!1;return!0}function En(e,t,n,r){let i=n.slice(),a=e.invocation;if(!a){r.push({store:t,path:i});return}r.push({store:t,path:i,invocation:a});let o=e.extraInvocations;if(o)for(let e=0;e<o.length;e++)r.push({store:t,path:i,invocation:o[e]})}function Dn(e,t,n){for(let n of e){let e=n.invocation?kn(n.path,n.invocation):On(n.path);t(n.store,e,n.path)}n&&jn(e)}function On(e){return e.length?t=>An(t,e):d}function kn(e,t){let n=e.slice(0,-1),r=e[e.length-1];return e=>{let i=An(e,n),a=i&&typeof i==`object`?Reflect.get(i,r):void 0;return typeof a==`function`?Reflect.apply(a,i,t.args??yn):void 0}}function An(e,t){let n=e;for(let e=0;e<t.length;e++){if(!n||typeof n!=`object`)return n;n=Reflect.get(n,t[e])}return n}function jn(e){let t=e.length;console.log(`[πŸ“‘ ${t} ${$t(`Proxy Subscription`,t)} πŸ“‘]:`,JSON.stringify(e.map(e=>{let t=Mn(e.store),n=e.path.join(`.`);if(!e.invocation)return n?`$(${t}).${n}`:`$(${t})`;let r=e.invocation.args?.length??0;return`$(${t}).${n}${r?`(${r}_${$t(`arg`,r)})`:`()`}`}),null,2))}function Mn(e){return`name`in e&&typeof e.name==`string`?e.name:`store`}const Nn=Symbol(),Pn=Symbol(),Fn=Symbol(`stores.derivedStore.readDependencyState`);function In(e,t=Object.is){let n,r=!1,i,a=!1,o=!1;typeof t==`function`?i=t:(n=t.debounce,r=l?t.debugMode??!1:!1,i=t.equalityFn??Object.is,a=t.keepAlive??!1,o=t.lockDependencies??!1);let s=new nn,c=new tn(A),u=+!!a,f,p,m=Nn,h=!1,g=!1,_=!0,v=!0,y=null,b=Pn;function x(e,t,n){if(!v)return(t??d)(zn(e));if(!u)return(t??d)(e.getState());if(!t){let t=zn(e);return!t||typeof t!=`object`?(c.retainState(e),t):(f||(f=new WeakMap),p||(p=bn()),ln(e,t,f,p.trackPath))}let r=n?{equalityFn:n,isCascadeParticipant:!0}:en;return c.addSelector(e.subscribe(t,A,r)),t(zn(e))}function S(){if(!_&&$(m))return m;_=!1,v&&c.beginRebuild(!0);let t=!0,n=m,a=$(n);g=!0;try{let o=e(x),s=p?fn(o):o;a&&i(n,s)?(r&&console.log(`[πŸ₯· Derive Complete πŸ₯·]: No change detected`),t=!1,m=n):m=s}finally{g=!1,v&&c.finishRebuild(!0)}let s=r&&(!a||r===`verbose`&&v);if(s){a?r===`verbose`&&console.log(`[πŸŒ€ Rebuilding Subscriptions πŸŒ€]: Created…`):console.log(`[πŸŒ€ Initial Derive Complete πŸŒ€]: Created…`);let e=c.size;console.log(`[🎯 ${e} ${$t(`Selector Subscription`,e)} 🎯]`)}return p&&v&&(p.buildProxySubscriptions((e,t)=>{c.addSelector(e.subscribe(t,A,en))},s),f=void 0,o?p=void 0:p.reset()),t&&a&&C(m,n),o&&(v=!1),m}function C(e,t){let n=s.cascadeParticipantCount,i=n>0&&s.ordinaryWatcherCount>0,a=s.ordinaryWatcherCount>0&&(i||Xe()!==null||Ye());if(i&&Ze(),r){let e=s.ordinaryWatcherCount+n;console.log(`[πŸ“» Derive Complete πŸ“»]: Notifying ${e} ${$t(`watcher`,e)}`)}if(n&&s.notifyCascade(e,t),s.ordinaryWatcherCount){if(a){b===Pn?(b=t,et(w)):$(b)||(b=t);return}s.notifyOrdinary(e,t)}}function w(){u&&_&&!s.cascadeParticipantCount&&S();let e=b;b=Pn,s.ordinaryWatcherCount&&$(m)&&e!==Pn&&$(e)&&s.notifyOrdinary(m,e)}let T=n?Tt(D,typeof n==`number`?n:n.delay,typeof n==`number`?{leading:!1,maxWait:n,trailing:!0}:n):void 0,E=T??(()=>{h||(h=!0,queueMicrotask(D))});function D(){if(h=!1,!u){a||I();return}_&&S()}function O(e){if(e!==void 0&&(e||T&&_)){queueMicrotask(O);return}!u&&!a&&I()}function k(){let e=y;e===Xe()&&(D(),y===e&&(y=null))}function A(){if(!g){if(!T){if(s.cascadeParticipantCount){_=!0,Ze();let e=Xe(),t=e===null?0:e+1;if(y!==null&&t<=y)return;y=t,tt(k,t);return}if(_)return;if(_=!0,Ye()){b===Pn&&(b=Nn,et(w));return}}_||(_=!0,y=null,E())}}function j(e){u+=1;try{return e()}finally{--u}}function ee(){return _||!$(m)?u?S():j(S):(h&&u&&D(),m)}function M(){return Ye()&&Xe()===null&&$e(),_||!$(m)?u?S():e(x):m}function N(...e){if(e.length===1){let t=e[0];return s.addWatcher(t)&&(u+=1),$(m)||M(),()=>{s.deleteWatcher(t)&&(--u,u||O(!1))}}let[t,n,r]=e,i=r?.equalityFn??Object.is,a=r?.isCascadeParticipant??!1,o=t(u?M():j(M)),c={currentSlice:o,equalityFn:i,isCascadeParticipant:a,listener:n,selector:t};return s.addWatcher(c),u+=1,r?.fireImmediately&&n(o,o),()=>{s.deleteWatcher(c)&&(--u,u||O(a))}}function P(e){return u?M():j(M),s.addCascadeStateListener(e)&&(u+=1),()=>{s.deleteCascadeStateListener(e)&&(--u,u||O(!0))}}function F(){u&&(T?T.flush():_&&S())}function I(){T?.cancel(),c.clear(),s.clear(),u=0,p=void 0,f=void 0,v=!0,h=!1,g=!1,_=!0,m=Nn,b=Pn,y=null}function L(){return _||h||!$(m)?u?S():j(S):m}return{[Fn]:L,[Q]:P,destroy:I,flushUpdates:F,getSnapshot:ee,getState:M,subscribe:N,getInitialState:Ln,setState:Rn}}function Ln(){throw Error(`[createDerivedStore]: getInitialState() is not available on derived stores.`)}function Rn(){throw Error(`[createDerivedStore]: setState() is not available on derived stores.`)}function zn(e){let t=e[Fn];return t?t():e.getState()}function $(e){return e!==Nn}var Bn=class{constructor(e){this.count=0,this.lastSubscriptionTime=null,this.fetchThrottleMs=null,this.onSubscribe=null,this.onLastUnsubscribe=null,e&&(this.fetchThrottleMs=q.seconds(5))}init({onSubscribe:e,onLastUnsubscribe:t}){this.onSubscribe=e,this.onLastUnsubscribe=t}hasSubscribers(){return this.count>0}subscribe(){let e=this.count===0,t=this.fetchThrottleMs!==null,n=t&&this.lastSubscriptionTime!==null&&!e&&Date.now()-this.lastSubscriptionTime<=this.fetchThrottleMs;return this.count+=1,this.onSubscribe?.(e,n),t&&(this.lastSubscriptionTime=Date.now()),e=>{let t=this.count===1;this.count=Math.max(this.count-1,0),t&&(this.onLastUnsubscribe?.(e),this.lastSubscriptionTime=null)}}};function Vn(e,t=queueMicrotask){let n=!1,r;function i(){n=!1,e(...r)}function a(...e){r=e,!n&&(n=!0,t(i))}return a}const Hn=Symbol(`stores.queryParamConfig`);function Un(e,t){return{[Hn]:!0,key:t.key,value:e}}function Wn(e){return!!e&&typeof e==`object`&&Hn in e}function Gn(e){return JSON.stringify(qn(e))}function Kn(e){return JSON.parse(e)}function qn(e){return typeof e!=`object`||!e?e:Object.keys(e).sort().reduce((t,n)=>{let r=e[n];return t[n]=F(r)?qn(r):r,t},f())}const Jn=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});function Yn(e,t,n){let r=f(),i=null,a=!1;if(e)for(let n in e){if(!N(e,n))continue;let o=Xn(r,e[n],n,t);o&&((i??(i=f()))[n]=o,o.key!==void 0&&(a=!0))}return{buildKey(e=r){return Gn(a?tr(i,e):e)},complete(e){return e?ir(e,n)?e:{...r,...e}:$n(r)},get(){return $n(r)},subscribe(e){return er(i,r,e)}}}function Xn(e,t,n,r){return Wn(t)?Qn(e,t.value,n,r,t.key):Qn(e,t,n,r)}function Zn(e,t){let n=[],r,i;function a(e,t,a){return t?(n.push(n=>e.subscribe(t,n,nr(a))),t(rr(e))):(r??(r=bn()),i??(i=new WeakMap),ln(e,rr(e),i,r.trackPath))}function o(e,t=d){return t(rr(e))}let s=e(a,t),c=r?fn(s):s;return r&&(r.buildProxySubscriptions((e,t)=>{n.push(n=>e.subscribe(t,n,Jn))},!1),r=void 0),i=void 0,{initialValue:c,subscribe(r){let i=()=>r(e(o,t)),a=n.map(e=>e(i));return e=>{for(let t of a)t(e)}}}}function Qn(e,t,n,r,i){if(ar(t)){let a=Zn(t,r);return e[n]=a.initialValue,i===void 0?{tracked:a}:{key:i,tracked:a}}return e[n]=t,i===void 0?null:{key:i}}function $n(e){let t=f();for(let n in e)N(e,n)&&(t[n]=e[n]);return t}function er(e,t,n){if(!e)return m;let r;for(let i in e){let a=e[i]?.tracked;a&&(r??(r=[])).push(a.subscribe(e=>{let r=t[i];Ie(r,e)||(t[i]=e,n(i,r,e))}))}return r?e=>{for(let t of r)t(e)}:m}function tr(e,t){let n=f();for(let r in t){if(!N(t,r))continue;let i=e?.[r];if(i?.key===!1)continue;let a=t[r];n[r]=i?.key?i.key(a):a}return n}function nr(e){return e?{equalityFn:e,isCascadeParticipant:!0}:Jn}function rr(e){return Te(e)?e.getSnapshot():e.getState()}function ir(e,t){for(let n of t)if(!(n in e))return!1;return!0}function ar(e){return typeof e==`function`}const or={error:!0,lastFetchedAt:!0,queryCache:!0,queryKey:!0,status:!0,enabled:!1,fetch:!1,getCacheEntry:!1,getData:!1,getStatus:!1,isDataExpired:!1,isStale:!1,reset:!1},sr=Object.freeze({force:!0}),cr=Object.freeze({once:!0}),lr=new Set;let ur=!1;function dr(e){lr.add(e),!ur&&(ur=!0,queueMicrotask(()=>{ur=!1,Ve(fr)}))}function fr(){for(let e of lr)lr.delete(e),e()}function pr(e,t,n){ae();let r=typeof t==`function`?t:_r,i=typeof t==`object`?t:n,a=mr(i)?i:void 0,o=le(),s=o.minStaleTime,{fetcher:c,onError:d=o.onError,onFetched:f,setData:m,transform:h,abortInterruptedFetches:g=o.abortInterruptedFetches,cacheTime:_=o.cacheTime,debugMode:v=o.debugMode,disableAutoRefetching:y=o.disableAutoRefetching,disableCache:b=!1,enabled:x=!0,keepPreviousData:S=o.keepPreviousData,paramChangeThrottle:C=o.paramChangeThrottle,params:w,retry:T=o.retry,retryDelay:E=o.retryDelay,staleTime:D=o.staleTime,suppressStaleTimeWarning:O=o.suppressStaleTimeWarning}=e,k=typeof D==`function`?o.staleTime:D;l&&s!==!1&&!y&&!O&&k<s&&console.warn(`[createQueryStore${a?.storageKey?`: ${a.storageKey}`:``}] ❌ Stale times under ${s/1e3} seconds are not recommended. Provided staleTime: ${k/1e3} seconds`);let A=Error(`[createQueryStore: AbortError] Fetch interrupted`),ee=typeof _==`function`,M=l&&v,N=e.params?Object.keys(e.params):[],P=!1,F,I=[],R=null,z=null,B=null,V=null,H=null,U=null,ne=null,re={enabled:typeof x==`function`?!1:x,error:null,lastFetchedAt:null,queryCache:{},queryKey:``,status:K.Idle},W=new Bn(y);function ie(){B&&(V=null,B.abort(),B=null)}function G(){H&&(clearTimeout(H),H=null)}async function oe(e){let t=new AbortController;B=t;try{return await new Promise((n,r)=>{t.signal.addEventListener(`abort`,()=>r(A),cr),Promise.resolve(c(e,t)).then(n,r)})}finally{B===t&&(B=null)}}function se(e,t,n){let i=n.setState;function o(e,t){e!==t&&ne!==t&&(ne=t,t&&W.hasSubscribers()?queueMicrotask(()=>p.fetch(void 0,void 0,!0)):(H||g)&&(g&&ie(),G()))}function s(e){let t=typeof e==`function`;if(t||e.enabled!==void 0){let n,r=i(r=>{let i=t?e(r):e,a=i.enabled===void 0?r.enabled:i.enabled;return a!==r.enabled&&(n=()=>o(r.enabled,a)),i});return n?.(),r}else return i(e)}n.setState=s,W.init({onSubscribe:(n,r)=>{let i=t();if(i.enabled)if(n){let t=F.get(),n=F.buildKey(t);i.queryKey!==n&&e({queryKey:n}),i.isStale()?p.fetch(t,void 0,!0):l(t)}else y&&!r&&p.fetch(void 0,void 0,!0)},onLastUnsubscribe:e=>{G(),g&&!e&&ie()}});function l(e){if(y||k<=0||k===1/0||!W.hasSubscribers())return;G();let n=t();if(!n.enabled)return;let r=F.buildKey(e),i=(b?U===r&&n.lastFetchedAt:n.queryCache[r]?.lastFetchedAt)||null,a=i?k-(Date.now()-i):k;H=setTimeout(()=>{t().enabled&&p.fetch(e,sr,!0)},a)}function u(e){let n=t(),r=n.status;switch(e){case`isIdle`:return r===K.Idle;case`isLoading`:return r===K.Loading;case`isError`:case`isInitialLoad`:case`isSuccess`:case void 0:{let t=n.queryKey,i=b?void 0:n.queryCache[t],a=b?r===K.Error:typeof i?.errorInfo?.lastFailedAt==`number`;if(e===`isError`)return a;let o=((b?U===t&&n.lastFetchedAt:i?.lastFetchedAt)||null)!==null,s=!o&&!a&&n.enabled;if(e===`isInitialLoad`)return s;let c=o&&!a;return e===`isSuccess`?c:{isError:a,isIdle:r===K.Idle,isLoading:r===K.Loading,isInitialLoad:s,isSuccess:c}}}}let p={...r(s,t,n),...re,async fetch(n,r,i=!1,o=0){let u=!!r?.skipStoreUpdates,v=t();if(!u&&(!v.enabled&&!r?.force||i&&!W.hasSubscribers()))return null;let y=v.error,x=v.queryKey,C=v.status===K.Loading,w=F.complete(n),D=F.buildKey(w);if(C&&V?.promise&&V.key===D)return M&&console.log(`[πŸ”„ Using Active Fetch πŸ”„] for params:`,JSON.stringify(w)),V.promise;let O=r?.staleTime??k,P=typeof r?.updateQueryKey==`boolean`?r.updateQueryKey:i?S:!1,I=(i||x===D||P)&&!u,R=V!==null;if(g&&I&&ie(),!r?.force){let t=v.lastFetchedAt,n=b?void 0:v.queryCache[D],r=n?.lastFetchedAt,i=n?.errorInfo,a=(b?U===D&&t:r)||null;if(!(!a||Date.now()-a>=O)&&(!i||!i.retryAllowed||u))return I&&!H&&k!==0&&k!==1/0&&l(w),P&&e(e=>e.queryKey===D?e:{queryKey:D}),M&&console.log(`[πŸ’Ύ Returning Cached Data πŸ’Ύ] for params:`,JSON.stringify(w)),n?.data??null}let z=I?{key:D}:null,B=r?.cacheTime??(ee?_(w):_);z&&(G(),P&&!R&&v.lastFetchedAt===null&&x!==D?e({error:null,queryKey:D,status:K.Loading}):(y||!C)&&e({error:null,status:K.Loading}),V=z);async function ne(){let v=a?.storageKey||D;try{M&&(!i&&n&&N.some(e=>!(e in n))?console.log(`[πŸ”„ Fetching with Partial Params πŸ”„]
7
- `,`- Provided params:`,`${JSON.stringify(n)}\n`,`- Filled in params:`,`${JSON.stringify(Object.fromEntries(Object.keys(w).filter(e=>!(e in n)).map(e=>[e,w[e]])))}`):console.log(`[πŸ”„ Fetching πŸ”„] for params:`,JSON.stringify(w)));let t=await(g&&I?oe(w):c(w,null)),a=Date.now();M&&console.log(`[βœ… Fetch Successful βœ…] for params:`,JSON.stringify(w));let o;try{o=yr(t,w,h)}catch(e){throw vr(v,`transform`,e)}if(u)return M&&console.log(`[πŸ₯· Successful Parallel Fetch πŸ₯·] for params:`,JSON.stringify(w)),r.skipStoreUpdates===`withCache`&&e(e=>{if(!m)return b?e:{queryCache:{...e.queryCache,[D]:{cacheTime:B,data:o,errorInfo:null,lastFetchedAt:a}}};let t=e,n=b?void 0:t.queryCache[D];try{m({data:o,params:w,queryKey:D,set:e=>{t=typeof e==`function`?{...t,...e(t)}:{...t,...e}}})}catch(e){throw vr(v,`setData`,e)}return!b&&Object.is(n,t.queryCache[D])&&(t={...t,queryCache:{...t.queryCache,[D]:{cacheTime:B,data:null,errorInfo:null,lastFetchedAt:a}}}),t}),o;if((m?s:e)(e=>{let t={...e,error:null,lastFetchedAt:a,queryKey:P?D:e.queryKey,status:K.Success};if(!m&&!b)M&&console.log(`[πŸ’Ύ Setting Cache πŸ’Ύ] for params:`,JSON.stringify(w),`| Has previous data?:`,!!t.queryCache[D]?.data),t.queryCache={...t.queryCache,[D]:{cacheTime:B,data:o,errorInfo:null,lastFetchedAt:a}};else if(m){M&&console.log(`[πŸ’Ύ Setting Data πŸ’Ύ] for params:`,JSON.stringify(w));let e=b?void 0:t.queryCache[D];try{m({data:o,params:w,queryKey:D,set:e=>{t=typeof e==`function`?{...t,...e(t)}:{...t,...e}}})}catch(e){throw vr(v,`setData`,e)}!b&&Object.is(e,t.queryCache[D])&&(t.queryCache={...t.queryCache,[D]:{cacheTime:B,data:null,errorInfo:null,lastFetchedAt:a}})}return b||_===1/0?t:gr(S,D,t)}),I&&(U=D,l(w)),f)try{f({data:o,fetch:p.fetch,params:w,set:s})}catch(e){j.error(vr(v,`onFetched callback`,e))}return o??null}catch(n){if(n===A)return M&&console.log(`[❌ Fetch Aborted ❌] for params:`,JSON.stringify(w)),null;let a=!i&&r?.throwOnError===!0,s=te(n);if(s instanceof L&&j.error(s),!I){if(a)throw s;return null}let c=b?void 0:t().queryCache[D],l,u;if(typeof T==`function`){l={error:s,params:w,queryKey:D,retryCount:o};try{u=T(l)}catch(e){j.error(vr(v,`retry callback`,e)),u=!1}}else u=T!==!1&&o<T;let f;if(u&&t().enabled&&W.hasSubscribers())if(E===void 0)f=de(o);else if(typeof E==`number`)f=E;else{l??(l={error:s,params:w,queryKey:D,retryCount:o});try{f=E(l)}catch(e){j.error(vr(v,`retryDelay callback`,e)),u=!1}}let m=f!==void 0;if(f!==void 0&&(G(),H=setTimeout(()=>{t().enabled&&p.fetch(w,sr,!0,o+1)},f)),e(b?e=>({error:s,queryKey:P?D:e.queryKey,status:K.Error}):e=>({error:s,queryCache:{...e.queryCache,[D]:{cacheTime:c?.cacheTime??B,data:c?.data??null,lastFetchedAt:c?.lastFetchedAt??null,errorInfo:{error:s,lastFailedAt:Date.now(),retryAllowed:u,retryCount:o}}},queryKey:P?D:e.queryKey,status:K.Error})),d)try{d({error:s,params:w,queryKey:D,retryCount:o,willRetry:m})}catch(e){j.error(vr(v,`onError callback`,e))}if(a)throw s;return null}finally{V===z&&(V=null)}}return z?(z.promise=ne(),z.promise):ne()},getCacheEntry(e){if(b)return null;let n=t(),r=e?typeof e==`string`?e:F.buildKey(F.complete(e)):n.queryKey;return n.queryCache[r]??null},getData(e){if(b)return null;let n=t().getCacheEntry(e);return!n||n.data===null?null:S?n.data:n.lastFetchedAt&&Date.now()-n.lastFetchedAt>=n.cacheTime?null:n.data},getStatus:u,isDataExpired(e){let n=t(),r=n.queryKey,i=b?void 0:n.queryCache[r],a=n.lastFetchedAt,o=(b?U===r&&a:i?.lastFetchedAt)||null;if(!o)return!0;let s=e??i?.cacheTime;return s===void 0||Date.now()-o>=s},isStale(e){let n=t(),r=n.queryKey,i=(b?U===r&&n.lastFetchedAt:n.queryCache[r]?.lastFetchedAt)||null;if(!i)return!0;let a=e??k;return Date.now()-i>=a},reset(t=!1){for(let e of I)e();I=[],F=Yn(void 0,q,N),R=null,z=null,ie(),G(),_e?.cancel(),V=null,U=null,t&&e(re)}},v=n.subscribe;return n.subscribe=(...e)=>{let t=P?void 0:W.subscribe(),n=e.length===1?v(e[0]):v(e[0],e[1],e[2]);return e=>{t?.(e),n(e)}},lt(n,e=>t=>{let n=P?void 0:W.subscribe(),r=e(t);return e=>{n?.(e),r(e)}}),p}let q=a?.storageKey?Zt(se,p(a,{partialize:hr(S,a.partialize)})):i&&!(`storageKey`in i)?Zt(se,i):Zt(se),ce=q.getState(),ue=ce.error,fe=ce.enabled,pe=ce.queryKey,me=ce.fetch;pe&&!ue&&(U=pe),P=!0,F=Yn(w,q,N),typeof x==`function`&&(R=Zn(x,q)),typeof e.staleTime==`function`&&(z=Zn(e.staleTime,q),k=z.initialValue);let he=Vn(e=>{me(e,void 0,!0)},dr);function ge(){if(S)he(void 0);else{let e=F.get();q.setState({queryKey:F.buildKey(e)}),he(e)}}let _e=u||!C?void 0:Tt(ge,typeof C==`number`?C:C.delay,typeof C==`number`?{leading:!1,maxWait:C,trailing:!0}:C);function ve(){if(G(),_e){let e=q.getState();S&&V?.key===e.queryKey&&e.lastFetchedAt===null?ge():_e();return}ge()}if(I.push(F.subscribe((e,t,n)=>{M&&console.log(`[πŸŒ€ Param Change πŸŒ€] -`,e,`- [Old]:`,`${t?.toString()},`,`[New]:`,n?.toString()),ve()})),z){let e=z.initialValue;M&&console.log(`[πŸŒ€ StaleTime Subscription πŸŒ€] Initial value:`,e),I.push(z.subscribe(t=>{t!==e&&(M&&console.log(`[πŸŒ€ StaleTime Change πŸŒ€] - [Old]:`,`${e},`,`[New]:`,t),e=t,k=t,G(),me(void 0,void 0,!0))}))}let J;if(R){let e=R.initialValue;fe!==e&&((J??(J={})).enabled=e),M&&console.log(`[πŸŒ€ Enabled Subscription πŸŒ€] Initial value:`,e),I.push(R.subscribe(t=>{t!==e&&(M&&console.log(`[πŸŒ€ Enabled Change πŸŒ€] - [Old]:`,`${e},`,`[New]:`,t),e=t,q.setState({enabled:t}))}))}else fe!==re.enabled&&((J??(J={})).enabled=re.enabled);let xe=F.buildKey();return xe!==pe&&((J??(J={})).queryKey=xe),J&&q.setState(J),P=!1,be(q,ye.QueryStore)}function mr(e){return typeof e?.storageKey==`string`}function hr(e,t){return n=>{let r={...n},i=f();for(let e in r)N(r,e)&&e in or&&(or[e]&&(i[e]=r[e]),delete r[e]);return{...t?t(r):kt(r),...gr(e,null,i)}}}function gr(e,t,n){if(!n.queryCache)return n;let r=Date.now(),i=t??(e&&n.queryKey||null),a=f(),o=!1;for(let e in n.queryCache){if(!N(n.queryCache,e))continue;let t=n.queryCache[e];t&&(r-(t.lastFetchedAt??t.errorInfo.lastFailedAt)<t.cacheTime||e===i)?a[e]=t:o=!0}return o?{...n,queryCache:a}:n}function _r(){return Object.create(null)}function vr(e,t,n){return new L(`[createQueryStore: ${e}]: ${t} failed`,n)}function yr(e,t,n){return n?n(e,t):e}const br=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});function xr(e,t,n){let r=typeof t==`function`,i=r?t:void 0,a=r?n:t,o=new Set,s,c;function l(e,t){let n=e.getState(),r=t.getState();if(c)for(let e of c)u(e,t,n,r);if(s)for(let e of s)d(e,t,n,r);o.size&&Qe();for(let e of o)f(e,t,n,r)}function u(e,t,n,r){e.unsubscribe(),e.unsubscribe=Sr(t,e.listener),!Object.is(r,n)&&(Ze(),e.listener(r,n))}function d(e,t,n,r){f(e,t,n,r)&&Ze()}function f(e,t,n,r){e.unsubscribe();let i=e.args;if(i.length===1){let a=i[0];e.unsubscribe=t.subscribe(a);let o=!Object.is(r,n);return o&&a(r,n),o}let a=i[0],o=i[1],s=i[2];s?.fireImmediately&&(s={...s,fireImmediately:!1});let c=a(n),l=a(r);return e.unsubscribe=t.subscribe(a,o,s),(s?.equalityFn??Object.is)(c,l)?!1:(o(l,c),!0)}function p(e,t){l(t,e),J(t)}let m=In(e,{debugMode:a?.debugMode??!1,lockDependencies:a?.lockDependencies??!0}),h;function g(){return h??(h=m.subscribe(p)),m.getState()}function _(...e){let t=g(),n={args:e,unsubscribe:e.length===1?t.subscribe(e[0]):t.subscribe(e[0],e[1],e[2])},r=e[2]?.isCascadeParticipant??!1;return r?(s??(s=new Set)).add(n):o.add(n),()=>{n.unsubscribe(),r?s?.delete(n)&&s.size===0&&(s=void 0):o.delete(n)}}function v(e){let t={listener:e,unsubscribe:Sr(g(),e)};return(c??(c=new Set)).add(t),e=>{t.unsubscribe(e),c?.delete(t)&&c.size===0&&(c=void 0)}}return Object.assign({[Q]:v,[ye.VirtualStore]:!0,destroy:()=>{h?.(),h=void 0,m.destroy()},getInitialState:()=>g().getInitialState(),getState:()=>g().getState(),persist:Cr(g),setState:wr(g),subscribe:_},i?.(g))}function Sr(e,t){return ct(e)?e[Q](t):e.subscribe(d,t,br)}function Cr(e){return{clearStorage:()=>e().persist?.clearStorage(),getOptions:()=>e().persist?.getOptions()??{},hasHydrated:()=>e().persist?.hasHydrated()??!0,hydrationPromise:()=>e().persist?.hydrationPromise?.()??Promise.resolve(),onFinishHydration:t=>e().persist?.onFinishHydration(t)??m,onHydrate:t=>e().persist?.onHydrate(t)??m,rehydrate:()=>e().persist?.rehydrate(),setOptions:t=>e().persist?.setOptions(t)}}function wr(e){return function(...t){return t[1]===!0?e().setState(t[0],!0):e().setState(t[0])}}function Tr(e,t){let n=Zt(e,t);return D(n,n.getState,n.getInitialState)}function Er(e,t=Object.is){let n=In(e,t);return D(n,n.getSnapshot,void 0)}function Dr(e,t,n){let r=pr(e,t,n);return D(r,r.getState,r.getInitialState)}function Or(e,t,n){let r=xr(e,t,n);return D(r,r.getState,r.getInitialState)}const kr=Symbol();function Ar(e){let t=r(kr);return t.current===kr&&(t.current=e()),t}const jr=Object.freeze({debugMode:!1,enabled:!0,equalityFn:Object.is,fireImmediately:!1});function Mr(e,t,r,i=jr){let a=Ar(()=>Ir(t,r,i)),o=Rr(i);return zr(a,t,r,i),n(()=>{if(o)return Pr(e,a),()=>Fr(a)},[o,e]),a}const Nr=Object.freeze({fireImmediately:!1,forceResubscribe:!1});function Pr(e,t,n=Nr){if(t.current.isActive){if(!n?.forceResubscribe)return;t.current.unsubscribe()}t.current.options.debugMode&&console.log(`[πŸ“‘ useListen πŸ“‘] Attaching listener`),t.current.isActive=!0,t.current.resubscribe=(n=Nr)=>Pr(e,t,n);let r=e.subscribe(e=>t.current.selector(e),(n,i)=>t.current.react(n,i,e.getState,()=>{r(),t.current.isActive=!1}),n.fireImmediately?{...t.current.options,fireImmediately:!0}:t.current.options);t.current.unsubscribe=()=>{t.current.isActive&&(r(),t.current.isActive=!1)}}function Fr(e){e.current.options.debugMode&&console.log(`[πŸ—‘οΈ useListen πŸ—‘οΈ] Detaching listener`),e.current.resubscribe=m,e.current.unsubscribe(),e.current.unsubscribe=m,e.current.isActive=!1}function Ir(e,t,n){return{selector:e,react:t,isActive:!1,options:Lr(n),resubscribe:m,unsubscribe:m}}function Lr(e){return typeof e==`function`?{equalityFn:e}:e??jr}function Rr(e){return typeof e==`function`?jr.enabled:e?.enabled??jr.enabled}function zr(e,t,n,r){e.current.selector=t,e.current.react=n,typeof r==`function`?e.current.options.equalityFn=r:r&&(e.current.options=r??jr)}const Br=Symbol();function Vr(e){let t=r(Br);return t.current===Br&&(t.current=e()),t.current}export{K as QueryStatuses,L as StoresError,pe as applyStateUpdate,re as configureStores,Tr as createBaseStore,Er as createDerivedStore,Dr as createQueryStore,Ae as createStoreActions,Or as createVirtualStore,Pe as deepEqual,de as defaultRetryDelay,J as destroyStore,xe as destroyStores,Gn as getQueryKey,Se as getStoreName,Te as hasGetSnapshot,d as identity,De as isDerivedStore,Oe as isPersistedStore,Ee as isQueryStore,ke as isVirtualStore,f as nullObject,Kn as parseQueryKey,Un as queryParam,_e as replacer,ve as reviver,Fe as shallowEqual,q as time,Mr as useListen,Vr as useStableValue};
6
+ `+(e instanceof Error?`\n${e.message}`:``))}return A(t),t}return{clearAll:()=>n().clearAll(),contains:e=>n().contains(e),delete:e=>n().delete(e),get:e=>n().get(e),getAllKeys:()=>n().getAllKeys(),set:(e,t)=>n().set(e,t)}}function k(e){let{createMMKV:t,MMKV:n}=s(`react-native-mmkv`);if(typeof t==`function`)return t({id:e});if(typeof n==`function`)return new n({id:e});throw Error(`[stores]: react-native-mmkv module does not export MMKV/createMMKV.`)}function A(e){if(!e||typeof e.get!=`function`||typeof e.set!=`function`||typeof e.delete!=`function`||typeof e.clearAll!=`function`)throw Error(`[stores]: Storage instance does not conform to expected interface`)}let j={debug:(e,t)=>{l&&console.debug(e,t)},error:(e,t)=>{l&&!u&&console.error(e,t)},info:(e,t)=>{l&&console.info(e,t)},warn:(e,t)=>{l&&console.warn(e,t)}};function ee(e){j=e}const M=Object.prototype.hasOwnProperty;function N(e,t){return M.call(e,t)}function P(e){let t=e.charCodeAt(0);if(t<48||t>57)return!1;let n=Number(e);return Number.isInteger(n)&&n<4294967295&&String(n)===e}function F(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function I(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var L=class extends Error{constructor(e,t){super(e),this.name=`StoresError`,t!==void 0&&Object.defineProperty(this,"cause",{configurable:!0,value:t,writable:!0})}};function te(e){return e instanceof Error?e:Error(String(e))}var R=class{destroy(){}publish(){}},z=class{constructor(){this.sessionId=`noop`}register(e){return new R}};let B;function V(){return B||(B=new z),B}let H,U,ne=!1;function re(e){l&&se(),e.logger&&ee(e.logger),H??(H=G(e)),U??(U=oe(e))}function W(){if(H)return H}function ie(){return U??(U=oe(void 0))}function ae(){ne=!0}function G(e){if(e?.queryStoreDefaults)return{queryStoreDefaults:e.queryStoreDefaults}}function oe(e){return{storage:e?.storage??O(e?.storageKeyPrefix??`stores:`),syncEngine:e?.syncEngine??V()}}function se(){if(ne)throw Error(`[stores]: configureStores() called after first store creation. Call it earlier before creating any stores.`)}const K={Error:`error`,Idle:`idle`,Loading:`loading`,Success:`success`},q={ms:e=>{"worklet";return e},seconds:e=>{"worklet";return e*1e3},minutes:e=>{"worklet";return e*6e4},hours:e=>{"worklet";return e*36e5},days:e=>{"worklet";return e*864e5},weeks:e=>{"worklet";return e*6048e5},infinity:1/0,zero:0};let ce;function le(){return ce??(ce=ue())}function ue(){let e=W()?.queryStoreDefaults;return{abortInterruptedFetches:e?.abortInterruptedFetches??!0,cacheTime:e?.cacheTime??q.days(7),debugMode:e?.debugMode??!1,disableAutoRefetching:e?.disableAutoRefetching??!1,keepPreviousData:e?.keepPreviousData??!1,minStaleTime:e?.minStaleTime??!1,onError:e?.onError,paramChangeThrottle:e?.paramChangeThrottle??!1,retry:e?.retry??5,retryDelay:e?.retryDelay,staleTime:e?.staleTime??q.minutes(2),suppressStaleTimeWarning:e?.suppressStaleTimeWarning??!1}}function de(e,t){let n=t?.baseDelay??q.seconds(5),r=t?.maxDelay??q.minutes(5);return Math.min(n*2**e,r)}function fe(e,t){return t[1]===!0?e(t[0],!0):e(t[0])}function pe(e,t,n){if(n===!0)return me(t)?t(e):t;let r=me(t)?t(e):t;return Object.is(r,e)?e:!I(e)||!I(r)?r:{...e,...r}}function me(e){return typeof e==`function`}function he(e){return typeof e==`object`&&!!e&&`__type`in e&&e.__type===`Map`}function ge(e){return typeof e==`object`&&!!e&&`__type`in e&&e.__type===`Set`}function _e(e,t){return t instanceof Map?{__type:`Map`,entries:Array.from(t.entries())}:t instanceof Set?{__type:`Set`,values:Array.from(t)}:t}function ve(e,t){return he(t)?new Map(t.entries):ge(t)?new Set(t.values):t}const ye=Object.freeze({QueryStore:Symbol(`queryStore`),VirtualStore:Symbol(`virtualStore`)});function be(e,t){return Object.assign(e,{[t]:!0})}function J(e,t){Ee(e)?e.getState().reset(t?.clearQueryCache):we(e)&&e.destroy()}function xe(e,t){for(let n of Array.isArray(e)?e:Object.values(e))!n||t?.skipDestroy?.(n)||J(n,t)}function Se(e){let t=Ce(e);return Oe(e)?e.persist.getOptions().name??t:t}function Ce(e){return typeof e==`function`?e.name:``}function we(e){return`destroy`in e}function Te(e){return`getSnapshot`in e}function Ee(e){return ye.QueryStore in e}function De(e){return`flushUpdates`in e}function Oe(e){return!(`persist`in e)||!e.persist?!1:typeof e.persist.getOptions().name==`string`}function ke(e){return ye.VirtualStore in e}function Ae(e,t){let n=je(e);return t?Object.assign(n,t):n}function je(e){let t=e.getState(),n=f(),r=n;if(l&&!(typeof t==`object`&&t))throw Error(`[createStoreActions]: State is not an object`);if(ke(e))for(let n in t)Ne(t,n)&&(r[n]=Me(e,n));else for(let e in t)Ne(t,e)&&(r[e]=t[e]);return n}function Me(e,t){return function(...n){let r=e.getState()[t];if(typeof r==`function`)return r(...n);throw Error(`[createVirtualStoreAction]: Method ${String(t)} is not a function`)}}function Ne(e,t){return typeof e[t]==`function`}function Pe(e,t){"worklet";if(typeof e!=`object`||!e||e===void 0||typeof t!=`object`||!t||t===void 0)return e===t;if(Object.is(e,t))return!0;let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let r of n)if(!(r in t)||!Pe(e[r],t[r]))return!1;return!0}function Fe(e,t){"worklet";if(typeof e!=`object`||!e||e===void 0||typeof t!=`object`||!t||t===void 0)return e===t;if(Object.is(e,t))return!0;let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let r of n)if(!Object.is(e[r],t[r]))return!1;return!0}function Ie(e,t){let n=Object.prototype.hasOwnProperty;function r(e,t){for(let n of e.keys())if(Ie(n,t))return n}let i,a,o;if(e===t)return!0;if(e&&t&&(i=e.constructor)===t.constructor){if(i===Date)return e.getTime()===t.getTime();if(i===RegExp)return e.toString()===t.toString();if(i===Array){if((a=e.length)===t.length)for(;a--&&Ie(e[a],t[a]););return a===-1}if(i===Set){if(e.size!==t.size)return!1;for(let n of e)if(o=n,o&&typeof o==`object`&&(o=r(t,o),!o)||!t.has(o))return!1;return!0}if(i===Map){if(e.size!==t.size)return!1;for(let n of e)if(o=n[0],o&&typeof o==`object`&&(o=r(t,o),!o)||!Ie(n[1],t.get(o)))return!1;return!0}if(i===ArrayBuffer)e=new Uint8Array(e),t=new Uint8Array(t);else if(i===DataView){if((a=e.byteLength)===t.byteLength)for(;a--&&e.getInt8(a)===t.getInt8(a););return a===-1}if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(t)){let n=e,r=t;if((a=n.byteLength)===r.byteLength)for(;a--&&n[a]===r[a];);return a===-1}if(!i||typeof e==`object`){a=0;for(let r in e)if(n.call(e,r)&&++a&&!n.call(t,r)||!(r in t)||!Ie(e[r],t[r]))return!1;return Object.keys(t).length===a}}return e!==e&&t!==t}function Le(e,t,n){if(t===0)return n;if(t===1){if(e===n)return null;let t=new Set;return t.add(e),t.add(n),t}return e.add(n),e.size===t?null:e}function Re(e,t,n){if(t===0)return null;if(t===1)return e===n?void 0:null;if(!e.delete(n))return null;if(t!==2)return e;for(let t of e)return t}function ze(e,t,n,r,i){if(t!==0){if(t===1){n(e,r,i);return}for(let t of e)n(t,r,i)}}function Be(e,t){t>1&&e.clear()}const Ve=o;let Y=!1,He=!1,Ue=!1,X,We,Ge=0;const Ke=new Map;let qe=0,Je=null,Z=1/0;function Ye(){return Y}function Xe(){return Je}function Ze(){Y||(Y=!0,!Ue&&(Ue=!0,queueMicrotask(()=>{Ue=!1,Qe()})))}function Qe(){if(Y){if(He){nt();return}He=!0;try{Ve(nt)}finally{ot()}}}function $e(){if(Y){if(He){Je===null&&rt();return}He=!0;try{rt()}catch(e){throw ot(),e}finally{He=!1,Je=null}}}function et(e){if(Y){if(We){We.push(e);return}if(!X){X=e;return}We=[X,e],X=void 0}}function tt(e,t){if(!Y)return;let n=t<0?0:t|0,r=Ke.get(n);r||(r=[],Ke.set(n,r)),r.push(e),qe+=1,n<Z&&(Z=n)}function nt(){for(;qe>0||st();)rt(),at()}function rt(){for(;qe>0;){let e=Z,t=Ke.get(e);if(!t){Z=1/0;for(let e of Ke.keys())e<Z&&(Z=e);continue}Ke.delete(e),qe-=t.length,it(),Je=e;for(let e=0;e<t.length;e++)t[e]();Je=null}}function it(){Z=1/0;for(let e of Ke.keys())e<Z&&(Z=e)}function at(){for(;;){let e=X;if(e){X=void 0,e();continue}let t=We;if(!t)return;for(;Ge<t.length;)t[Ge++]();We=void 0,Ge=0;return}}function ot(){Y=!1,He=!1,Je=null,X=void 0,We=void 0,Ge=0,Ke.clear(),qe=0,Z=1/0}function st(){return!!X||!!We}const Q=Symbol(`stores.subscribeCascadeState`);function ct(e){return Q in e}function lt(e,t){ct(e)&&(e[Q]=t(e[Q]))}const ut=Symbol(),dt=Symbol();function ft(e){let t,n,r,i=0;function a(e,a,o){let s=pe(t,e,a);if(Object.is(s,t))return o===ut?dt:void 0;let c=t;if(t=s,ze(r,i,h,t,c),n){Qe();for(let e of n)e(t,c)}}function o(){return t}function s(){return u}function c(e,t,n){return t?g(e,t,n):d(e)}let l={[Q]:p,getInitialState:s,getState:o,setState:a,subscribe:c},u=t=pt(e)?e(a,o,l):e;return l;function d(e){return(n??(n=new Set)).add(e),()=>{n?.delete(e),n?.size===0&&(n=void 0)}}function f(e){let t=Le(r,i,e);return t!==null&&(r=t,i+=1),()=>m(e)}function p(e){function t(t,n){Ze(),e(t,n)}return f(t)}function m(e){let t=Re(r,i,e);t!==null&&(r=t,--i)}function g(e,n,r){let i=r?.equalityFn??Object.is,a=r?.isCascadeParticipant??!1,o=e(t);function s(t){let r=e(t);if(i(o,r))return;let s=o;o=r,a&&Ze(),n(r,s)}return r?.fireImmediately&&n(o,o),a?f(s):d(s)}}function pt(e){return typeof e==`function`}function mt(e){return!!e&&typeof e==`object`&&`then`in e&&typeof e.then==`function`}const ht=Object.freeze({migrated:!1,state:void 0});function gt(e,t,n){return(r,i,a)=>{let o=vt(t),s,c=!1,l=0,u,d,f;function p(e){return o.storage.setItem(o.name,e,o.version)}function m(e,t){return(t===!0?r(e,t,ut):r(e,!1,ut))===dt?n?s??(s=Promise.resolve()):void 0:p(i())}a.setState=m;let h=e(m,i,a);a.getInitialState=()=>h;function g(){let e=x(),t=o.onRehydrateStorage?.(i()??h);try{let n=o.storage.getItem(o.name);return mt(n)?n.then(n=>_(e,n,t)).catch(n=>C(e,t,n)):_(e,n,t)}catch(n){C(e,t,n)}}return Object.assign(a,{persist:b()}),o.skipHydration||g(),u??h;function _(e,t,n){let r=_t(o,t);return mt(r)?r.then(t=>v(e,t,n)).catch(t=>C(e,n,t)):v(e,r,n)}function v(e,t,n){let r=y(e,t);if(mt(r))return r.then(()=>S(e,n));S(e,n)}function y(e,t){if(e!==l)return;let n=o.merge(t.state,i()??h);if(u=n,r(n,!0),t.migrated)return p(i())}function b(){return{clearStorage:()=>{o.storage.removeItem(o.name)},getOptions:()=>o,hasHydrated:()=>c,onFinishHydration:e=>(f??(f=new Set),f.add(e),()=>{f?.delete(e),f?.size===0&&(f=void 0)}),onHydrate:e=>(d??(d=new Set),d.add(e),()=>{d?.delete(e),d?.size===0&&(d=void 0)}),rehydrate:g,setOptions:e=>{o=vt({...o,...e,storage:e.storage??o.storage})}}}function x(){let e=++l;return c=!1,d?.forEach(e=>e(i()??h)),e}function S(e,t){if(e!==l)return;t?.(u,void 0);let n=i();u=n,c=!0,f?.forEach(e=>e(n))}function C(e,t,n){e===l&&t?.(void 0,n)}}}function _t(e,t){if(!t)return ht;if(typeof t.version!=`number`||t.version===e.version)return{migrated:!1,state:t.state};if(!e.migrate)return console.error(`State loaded from storage couldn't be migrated since no migrate function was provided`),ht;let n=e.migrate(t.state,t.version);return mt(n)?n.then(e=>({migrated:!0,state:e})):{migrated:!0,state:n}}function vt(e){return{...e,merge:e.merge??yt,skipHydration:e.skipHydration??!1}}function yt(e,t){return e===void 0?t:{...t,...e}}function bt(){let e=!1,t,n,r=new Promise((e,r)=>{t=e,n=r});function i(){e||!t||(e=!0,t(),t=void 0,n=void 0)}function a(r){e||!n||(e=!0,n(r),n=void 0,t=void 0)}function o(){return e}return{complete:i,isHydrated:o,fail:a,promise:r}}function xt(e){let t,n=!1,r,i;return{hydrationPromise:()=>n?t?.promise??r??(r=Promise.resolve()):(t||(t=bt()),t.promise),stateCreator:(t,r,a)=>{let o;function s(...e){return n?fe(t,e):new Promise((t,n)=>{(o??(o=[])).push(()=>{try{t(fe(a.setState,e))}catch(e){n(e)}})})}return i=()=>{if(!o?.length)return;let e=o;o=void 0;for(let t of e)t()},e(s,r,a)},wrapOnRehydrateStorage:(e,r)=>a=>{let o=e?.(a);return(e,a)=>{let s=n;n=!0,r?.onHydrationComplete?.(),i&&i(),r?.onHydrationFlushEnd?.(),a?(!t&&!s&&(t=bt(),t.promise.catch(m)),t?.fail(te(a))):t?.complete(),o?.(e,a)}}}}const St=Promise.resolve();function Ct(e){let t,n,r,i=null,a=St;function o(){return i=null,e(t,n,r)}function s(e,s,c){return t=e,n=s,r=c,i||(i=a.then(o),a=i.catch(m)),i}return s}const wt=Math.max,Tt=Math.min;function Et(e,t=0,n={}){let r,i,a,o,s,c,l=0,u=!1,d=!1,f=!0;if(typeof e!=`function`)throw TypeError(`Expected a function`);t=Ot(t)||0,kt(n)&&(u=!!n.leading,d=`maxWait`in n,a=d?wt(Ot(n.maxWait)||0,t):void 0,f=`trailing`in n?!!n.trailing:f);function p(t){let n=r,a=i;return r=i=void 0,l=t,o=n?e.apply(a,n):e.apply(a),o}function m(e){return l=e,s=setTimeout(_,t),u?p(e):o}function h(e){let n=e-(c??0),r=e-l,i=t-n;return d&&a!==void 0?Tt(i,a-r):i}function g(e){let n=e-(c??0),r=e-l;return c===void 0||n>=t||n<0||d&&a!==void 0&&r>=a}function _(){let e=Dt();if(g(e))return v(e);s=setTimeout(_,h(e))}function v(e){return s=void 0,f&&r?p(e):(r=i=void 0,o)}function y(){s!==void 0&&clearTimeout(s),l=0,r=c=i=s=void 0}function b(){return s===void 0?o:v(Dt())}function x(...e){let n=Dt(),a=g(n);if(r=e,i=this,c=n,a){if(s===void 0)return m(c);if(d)return clearTimeout(s),s=setTimeout(_,t),p(c)}return s===void 0&&(s=setTimeout(_,t)),o}return x.cancel=y,x.flush=b,x}function Dt(){return typeof performance<`u`&&typeof performance.now==`function`?performance.now():Date.now()}function Ot(e){if(typeof e==`number`)return e;if(typeof e==`symbol`||e===void 0)return NaN;if(typeof e==`object`&&e){let t=typeof e.valueOf==`function`?e.valueOf():e;e=typeof t==`object`?t+``:t}return typeof e==`string`?(e=e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,``),/^0b[01]+$/i.test(e)?parseInt(e.slice(2),2):/^0o[0-7]+$/i.test(e)?parseInt(e.slice(2),8):/^[-+]0x[0-9a-f]+$/i.test(e)?NaN:+e):e===0?e:+e}function kt(e){let t=typeof e;return e!==null&&(t===`object`||t===`function`)}function At(e){if(!F(e))return e;let t=f(),n=Object.keys(e);for(let r=0;r<n.length;r++){let i=n[r],a=e[i];typeof a!=`function`&&(t[i]=a)}return t}function jt(e,t){try{return JSON.stringify(e,t?_e:void 0)}catch(e){throw j.error(new L(`[createBaseStore]: Failed to serialize store data`,e)),e}}function Mt(e,t){try{return JSON.parse(e,t?ve:void 0)}catch(e){throw j.error(new L(`[createBaseStore]: Failed to deserialize persisted store data`,e)),e}}const Nt=u?0:c?q.seconds(3):q.seconds(5);function Pt(e,t,n){let r=t??e.storage??ie().storage,i=e.version??0;return r.async?{async:!0,persistStorage:It(r,e,n),version:i}:{async:!1,persistStorage:Ft(r,e,(e.sync?void 0:e.persistThrottleMs??Nt)||void 0,n),version:i}}function Ft(e,t,n,r){let i=!t.deserializer&&!t.serializer&&!e.deserializer&&!e.serializer,a=typeof t.sync==`object`&&(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata)===!0,o=t.partialize??At,s=t.deserializer??e.deserializer??Lt(i),c=t.serializer??e.serializer??Rt(i);function l(t,n,i){try{if(Ut(r))return;let s={state:o(n),version:i},l=Bt(r,a,s),u=c(s);try{e.set(t,u),Vt(r,l)}catch(e){j.error(new L(`[createBaseStore]: Failed to persist store data`,e))}}catch(e){j.error(new L(`[createBaseStore]: Failed to persist store data`,e))}}let u=n===void 0?l:Et(l,n,{leading:!1,maxWait:n,trailing:!0});return{getItem:t=>{let n=e.get(t);return n===void 0?null:s(n)},setItem:(e,t,n)=>{r?.getIsApplyingRemote()||u(e,t,n)},removeItem:t=>{try{e.delete(t)}catch(e){j.error(new L(`[createBaseStore]: Failed to delete persisted store data`,e))}}}}function It(e,t,n){let r=!t.deserializer&&!t.serializer&&!e.deserializer&&!e.serializer,i=typeof t.sync==`object`&&(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata)===!0,a=t.partialize??At,o=t.deserializer??e.deserializer??Lt(r),s=t.serializer??e.serializer??Rt(r);async function c(t,r,o){try{if(Ut(n))return;let c={state:a(r),version:o},l=Bt(n,i,c),u=s(c);try{await e.set(t,u),Vt(n,l)}catch(e){j.error(new L(`[createBaseStore]: Failed to persist store data`,e))}}catch(e){j.error(new L(`[createBaseStore]: Failed to serialize persisted store data`,e))}}let l=Ct(c);return{getItem:async t=>{let n=await e.get(t);return n===void 0?null:o(n)},setItem:(e,t,r)=>n?.getIsApplyingRemote()?Promise.resolve():l(e,t,r),removeItem:async t=>{try{await e.delete(t)}catch(e){j.error(new L(`[createBaseStore]: Failed to delete persisted store data`,e))}}}}function Lt(e){return t=>{if(typeof t!=`string`)throw new L(`[createBaseStore]: Received non-string serialized state without a custom deserializer. Provide a deserializer on the store or storage adapter.`);return Mt(t,e)}}function Rt(e){return t=>jt(t,e)}const zt=Object.freeze({shouldClear:!1});function Bt(e,t,n){if(!t||!e)return zt;let r=e.getFieldTimestampSnapshot();return Ht(e,n),n.syncMetadata?r&&Object.keys(r).length>0?(n.syncMetadata.fields=r,{fieldSnapshot:r,shouldClear:!0}):(delete n.syncMetadata.fields,{fieldSnapshot:r,shouldClear:!1}):{fieldSnapshot:r,shouldClear:!1}}function Vt(e,t){!e||!t.shouldClear||!t.fieldSnapshot||!Object.keys(t.fieldSnapshot).length||e.clearFieldTimestamps(t.fieldSnapshot)}function Ht(e,t){let n=e.getSessionId(),r=e.getTimestamp();n!==void 0&&r!==void 0&&(t.syncMetadata={origin:n,timestamp:r})}function Ut(e){return e?!!e.getIsApplyingRemote():!1}function Wt(e,t,n){let r=t.engine??ie().syncEngine;return(i,a,o)=>{let s=new Map,c=[],l=[],u=null,d=!1,p=!1,m=0,h=null,g=[],_=Promise.resolve(),v=!n?.isAsync;function y(){let e=Date.now(),t=e>m?e:m+1;return m=t,t}function b(e,t){if(!(!n||!r.sessionId)&&(n.setSessionId(r.sessionId),n.setTimestamp(e),t.length>0)){let r=f();for(let n of t)r[String(n)]=e;n.mergeFieldTimestamps(r)}}function x(e,t,n,i=!1){let a=r.sessionId;for(let t of e)s.set(t,[n,a]);!u||!p?l.push({keys:e,replace:i,timestamp:n,values:t}):u.publish?.({replace:i,sessionId:a,timestamp:n,values:t})}function S(){if(!(!u||!l.length)){for(let e of l){let t=r.sessionId;for(let n of e.keys)s.set(n,[e.timestamp,t]);b(e.timestamp,e.keys),u.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values})}l.length=0}}function C(e,t){if(d||!h)return t?i(e,t):i(e);let n=y(),r,a,o=t?i(s,!0):i(s);if(!r||!a)return o;function s(i){let o=pe(i,e,t);for(let e of g)Object.is(o[e],i[e])||((r??(r=[])).push(e),(a??(a=f()))[e]=o[e]);return r&&b(n,r),o}return mt(o)?o.finally(x.bind(void 0,r,a,n,t)):(x(r,a,n,t),o)}let w=o.setState;o.setState=C;let T=e(C,a,o);if(g=t.fields??qt(T),!g.length)return T;h=new Set(g);async function E(e){m=Math.max(m,e.timestamp);let r=f(),i=a(),o=e.timestamp,c;if(e.replace)for(let t of g)N(e.values,t)||Kt(s.get(t),o,e.sessionId)&&(c??(c=[])).push(t);for(let n of g){if(!Xt(e.values,n)||!h?.has(n)||!Kt(s.get(n),o,e.sessionId))continue;let a=t.merge?.[n];if(a){let t=e.values[n],c=i[n];if(t!==void 0){let l=a(t,c,i,e.values),u=c===void 0?t:c;if(!Yt(l,u)){j.error(new L(`[sync] Merge function for field "${String(n)}" returned ${Jt(l)} but expected ${Jt(u)}`));return}r[n]=l,s.set(n,[o,e.sessionId])}}else r[n]=e.values[n],s.set(n,[o,e.sessionId])}if(!(!(Object.keys(r).length>0)&&!c?.length)){d=!0,n?.setIsApplyingRemote(!0);try{if(e.replace){let e={...i},t=!1;if(c?.length){t=!0;for(let t of c)delete e[t],s.delete(t)}for(let n in r){if(!N(r,n))continue;let i=r[n];if(i===void 0)continue;Object.is(e[n],i)||(t=!0);let a=e;a[n]=i}if(!t)return;await(n?.setWithoutPersist??w)(e,!0)}else await(n?.setWithoutPersist??w)(r)}finally{d=!1,n?.setIsApplyingRemote(!1)}}}function D(e){n?.isAsync?_=_.then(()=>E(e)):E(e)}function O(){if(!c.length)return;let e=c.slice();c.length=0;for(let t of e)D(t)}if(u=r.register({apply:e=>{if(!v){c.push(e);return}D(e)},fields:g,getState:a,key:t.key}),u?.onFirstSubscribe||u?.onLastUnsubscribe){let e=u,t=0,n=o.subscribe;function r(n){return t++===0&&e.onFirstSubscribe?.(),r=>{n(r),--t,t||queueMicrotask(()=>{t||e.onLastUnsubscribe?.()})}}o.subscribe=(...e)=>r(e.length===1?n(e[0]):n(e[0],e[1],e[2])),lt(o,e=>t=>r(e(t)))}function k(){p=!0,S()}function A(){v=!0,O()}return n?.isAsync?(n.onHydrationComplete=k,n.onHydrationFlushEnd=A):u.onHydrated?(u.onHydrated(k),A()):(k(),A()),T}}function Gt(e){let t,n,r,i=!1;function a(e){if(!(!e||!r)){for(let t of Object.entries(e)){let e=t[0],n=t[1];r[e]===n&&delete r[e]}Object.keys(r).length||(r=void 0)}}function o(){if(r)return{...r}}function s(e){if(!r){r={...e};return}for(let t of Object.entries(e)){let e=t[0],n=t[1],i=r[e];(i===void 0||n>i)&&(r[e]=n)}}return{isAsync:e,clearFieldTimestamps:a,getFieldTimestampSnapshot:o,getIsApplyingRemote:()=>i,getSessionId:()=>t,getTimestamp:()=>n,mergeFieldTimestamps:s,onHydrationComplete:void 0,onHydrationFlushEnd:void 0,setIsApplyingRemote:e=>i=e,setSessionId:e=>t=e,setTimestamp:e=>n=e,setWithoutPersist:void 0}}function Kt(e,t,n){if(!e)return!0;let r=e[0],i=e[1];return t<r?!1:t>r?!0:n>i}function qt(e){let t=[];for(let n of Object.keys(e))Zt(e,n)&&t.push(n);return t}function Jt(e){if(e===null)return`null`;let t=typeof e;return t===`object`?Object.prototype.toString.call(e):t}function Yt(e,t){if(!l)return!0;if(e===null||t===null)return e===t;let n=typeof e;return n===typeof t?n===`object`?Object.prototype.toString.call(e)===Object.prototype.toString.call(t):!0:!1}function Xt(e,t){return N(e,t)}function Zt(e,t){return typeof e[t]!=`function`}function Qt(e,t){if(ae(),!t)return ft(e);let n=t.storageKey,r=typeof n==`string`,i=r?t.storage??ie().storage:void 0,a=$t(t.sync,n),o=!i||!a?void 0:Gt(i.async??!1),s=a?Wt(e,a,o):e;if(!r)return ft(s);let c=Pt(t,i,o),l=c.async?xt(s):void 0,u=l?l.wrapOnRehydrateStorage(t.onRehydrateStorage,o):t.onRehydrateStorage,d=ft(gt(l?(e,t,n)=>(o&&(o.setWithoutPersist=n.setState),l.stateCreator(e,t,n)):s,{merge:t.merge,migrate:t.migrate,name:n,onRehydrateStorage:u,storage:c.persistStorage,version:c.version},c.async));return l?Object.assign(d,{persist:Object.assign(d.persist,{hydrationPromise:l.hydrationPromise})}):d}function $t(e,t){if(!e)return null;let n=typeof e==`object`,r=n?e.key??t:e===!0?t:e;if(!r)throw new L(`[createBaseStore]: sync requires a key to be specified either directly or via storageKey`);return n?{...e,key:r}:{key:r}}function en(e,t,n=`s`){return t===1?e:`${e}${n}`}const tn=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});var nn=class{constructor(e){this.invalidate=e,this.stateDependencyRevisionStamp=0,this.stateDependencyRevision=0}beginRebuild(e){this.clearSelectors(e),this.stateDependencyRevision+=1}addSelector(e){let t=this.selectorUnsubscribes;if(!t){this.selectorUnsubscribes=e;return}if(typeof t==`function`){this.selectorUnsubscribes=[t,e];return}t.push(e)}retainState(e){let t=this.stateDependencies;if(t){let n=t.get(e);if(n){n.revision=this.stateDependencyRevision;return}t.set(e,this.createStateDependency(e));return}let n=this.stateDependencyStore;if(!n){this.stateDependencyStore=e,this.stateDependencyRevisionStamp=this.stateDependencyRevision,this.stateDependencyUnsubscribe=this.subscribeState(e);return}if(n===e){this.stateDependencyRevisionStamp=this.stateDependencyRevision;return}let r=this.stateDependencyUnsubscribe;this.stateDependencyStore=void 0,this.stateDependencyUnsubscribe=void 0,this.stateDependencies=new Map,r&&this.stateDependencies.set(n,{revision:this.stateDependencyRevisionStamp,unsubscribe:r}),this.stateDependencies.set(e,this.createStateDependency(e))}finishRebuild(e){this.stateDependencyStore&&this.stateDependencyRevisionStamp!==this.stateDependencyRevision&&(this.stateDependencyUnsubscribe?.(e),this.stateDependencyStore=void 0,this.stateDependencyUnsubscribe=void 0);let t=this.stateDependencies;if(t){for(let n of t){let r=n[1];r.revision!==this.stateDependencyRevision&&(r.unsubscribe(e),t.delete(n[0]))}if(!t.size){this.stateDependencies=void 0;return}if(t.size===1){for(let e of t){this.stateDependencyStore=e[0],this.stateDependencyRevisionStamp=e[1].revision,this.stateDependencyUnsubscribe=e[1].unsubscribe;break}this.stateDependencies=void 0}}}clear(e){this.clearSelectors(e),this.stateDependencyUnsubscribe?.(e),this.stateDependencyStore=void 0,this.stateDependencyUnsubscribe=void 0;let t=this.stateDependencies;if(t){for(let n of t)n[1].unsubscribe(e);this.stateDependencies=void 0}}get size(){let e=this.selectorUnsubscribes;return(typeof e==`function`?1:e?.length??0)+ +!!this.stateDependencyStore+(this.stateDependencies?.size??0)}clearSelectors(e){let t=this.selectorUnsubscribes;if(this.selectorUnsubscribes=void 0,t){if(typeof t==`function`){t(e);return}for(let n=0;n<t.length;n++)t[n](e)}}createStateDependency(e){return{revision:this.stateDependencyRevision,unsubscribe:this.subscribeState(e)}}subscribeState(e){return ct(e)?e[Q](this.invalidate):e.subscribe(d,this.invalidate,tn)}},rn=class{constructor(){this.watcherCount=0,this.ordinaryWatcherCount=0,this.cascadeParticipantCount=0,this.cascadeStateListenerCount=0}addWatcher(e){let t=Le(this.watchers,this.watcherCount,e);return t===null?!1:(this.watchers=t,this.watcherCount+=1,cn(e)?this.cascadeParticipantCount+=1:this.ordinaryWatcherCount+=1,!0)}deleteWatcher(e){let t=Re(this.watchers,this.watcherCount,e);return t===null?!1:(this.watchers=t,--this.watcherCount,cn(e)?--this.cascadeParticipantCount:--this.ordinaryWatcherCount,!0)}addCascadeStateListener(e){let t=Le(this.cascadeStateListeners,this.cascadeStateListenerCount,e);return t===null?!1:(this.cascadeStateListeners=t,this.cascadeParticipantCount+=1,this.cascadeStateListenerCount+=1,!0)}deleteCascadeStateListener(e){let t=Re(this.cascadeStateListeners,this.cascadeStateListenerCount,e);return t===null?!1:(this.cascadeStateListeners=t,--this.cascadeParticipantCount,--this.cascadeStateListenerCount,!0)}notifyCascade(e,t){ze(this.cascadeStateListeners,this.cascadeStateListenerCount,h,e,t),this.cascadeParticipantCount!==this.cascadeStateListenerCount&&ze(this.watchers,this.watcherCount,an,e,t)}notifyOrdinary(e,t){ze(this.watchers,this.watcherCount,on,e,t)}clear(){this.watchers=Be(this.watchers,this.watcherCount),this.cascadeStateListeners=Be(this.cascadeStateListeners,this.cascadeStateListenerCount),this.watcherCount=0,this.ordinaryWatcherCount=0,this.cascadeParticipantCount=0,this.cascadeStateListenerCount=0}};function an(e,t,n){typeof e==`function`||!e.isCascadeParticipant||sn(e,t)}function on(e,t,n){if(typeof e==`function`){e(t,n);return}e.isCascadeParticipant||sn(e,t)}function sn(e,t){let n=e.selector(t);if(e.equalityFn(e.currentSlice,n))return;let r=e.currentSlice;e.currentSlice=n,e.listener(n,r)}function cn(e){return typeof e!=`function`&&e.isCascadeParticipant}const ln=Symbol(`stores.deriveProxy.unwrap`);function un(e,t,n,r){let i=n.get(e);if(yn(i))return i;let a=dn(t,e,r);return n.set(e,a),a}function dn(e,t,n,r=[]){return!e||typeof e!=`object`?(n(t,r,!0),e):fn(e,r,t,n,new WeakSet,new WeakMap)}function fn(e,t,n,r,i,a){let o=Array.isArray(e);return new Proxy(e,{get(s,c,l){if(c===ln)return r(n,t,!0),s;if(i.has(s))return Reflect.get(s,c,l);if(c===`__proto__`||typeof c==`symbol`)return c===Symbol.iterator&&(r(n,t,!0),i.add(s)),Reflect.get(s,c,l);if(o&&P(c))return r(n,t,!0),i.add(s),Reflect.get(s,c,l);let u=Reflect.get(s,c,s),d=String(c),f=t.concat(d);if(typeof u==`function`)return N(s,c)?function(...e){return r(n,f,!0,{args:e.length?e:void 0}),Reflect.apply(u,s,e)}:(r(n,t,!0),u.bind(e));let p=!!u&&typeof u==`object`;return r(n,f,!p),p?(a.has(u)||a.set(u,fn(u,f,n,r,i,a)),a.get(u)):u},getOwnPropertyDescriptor(e,a){return r(n,t,!0),i.add(e),Reflect.getOwnPropertyDescriptor(e,a)},has(e,i){return r(n,t,!0),Reflect.has(e,i)},ownKeys(e){return r(n,t,!0),i.add(e),Reflect.ownKeys(e)}})}function pn(e,t){return!e||typeof e!=`object`?e:_n(e)||(Array.isArray(e)?mn(e,t):F(e)&&hn(e,t),e)}function mn(e,t){let n=vn(e,t);if(n)for(let t=0;t<e.length;t++)gn(e,String(t),n)}function hn(e,t){let n=vn(e,t);if(n)for(let t of Reflect.ownKeys(e))gn(e,t,n)}function gn(e,t,n){let r=Reflect.getOwnPropertyDescriptor(e,t);if(!r||!(`value`in r))return;let i=pn(r.value,n);i!==r.value&&(r.value=i,Reflect.defineProperty(e,t,r))}function _n(e){let t=Reflect.get(e,ln);return t&&typeof t==`object`?t:void 0}function vn(e,t){let n=t??new WeakSet;return n.has(e)?null:(n.add(e),n)}function yn(e){return e!==void 0}const bn=Object.freeze([]);function xn(){let e,t,n;return{buildProxySubscriptions(r,i,a){let o=[],s=t,c=e;if(s&&c)wn(s,c,[],0,o,a);else if(n)for(let e of n)wn(e[1],e[0],[],0,o,a);On(o,r,i)},reset(){e=void 0,t=void 0,n=void 0},trackPath(r,i,a,o){let s=t;if(s){let i=e;if(i!==r)if(!i)e=r;else{let a=n??(n=new Map);a.set(i,s),s=Sn(),a.set(r,s),e=void 0,t=void 0}}else{let i=n;i?(s=i.get(r),s||(s=Sn(),i.set(r,s))):(s=Sn(),e=r,t=s)}Cn(s,i,a,o)}}}function Sn(){return f()}function Cn(e,t,n,r){let i=e;for(let e=0;e<t.length;e++){let n=t[e],r=i.children,a;if(r)a=r[n],a||(a=r[n]=Sn());else if(a=i.child,!a)a=Sn(),i.child=a,i.childKey=n;else if(i.childKey!==n){let e=i.childKey;if(e===void 0)i.childKey=n;else{let t=Sn();t[e]=a,a=t[n]=Sn(),i.child=void 0,i.childKey=void 0,i.children=t}}i=a}n&&(i.isLeaf=!0),r&&Tn(i,r)}function wn(e,t,n,r,i,a=2){let o=e.child;if(o){let s=e.childKey;if(e.isLeaf){if(Dn(e,t,n,i),!o.invocation||s===void 0)return}else if(s===void 0){Dn(e,t,n,i);return}n.push(s),wn(o,t,n,r+1,i,a),n.pop();return}let s=e.children;if(!s){Dn(e,t,n,i);return}if(e.isLeaf||r>=a){Dn(e,t,n,i);for(let e in s){let o=s[e];o.invocation&&(n.push(e),wn(o,t,n,r+1,i,a),n.pop())}return}for(let e in s)n.push(e),wn(s[e],t,n,r+1,i,a),n.pop()}function Tn(e,t){let n=e.invocation;if(!n){e.invocation=t;return}if(En(n,t))return;let r=e.extraInvocations;if(!r){e.extraInvocations=[t];return}for(let e=0;e<r.length;e++)if(En(r[e],t))return;r.push(t)}function En(e,t){let n=e.args,r=t.args,i=n?.length??0;if(i!==(r?.length??0))return!1;if(!n||!r)return!0;for(let e=0;e<i;e++)if(!Object.is(n[e],r[e]))return!1;return!0}function Dn(e,t,n,r){let i=n.slice(),a=e.invocation;if(!a){r.push({store:t,path:i});return}r.push({store:t,path:i,invocation:a});let o=e.extraInvocations;if(o)for(let e=0;e<o.length;e++)r.push({store:t,path:i,invocation:o[e]})}function On(e,t,n){for(let n of e){let e=n.invocation?An(n.path,n.invocation):kn(n.path);t(n.store,e,n.path)}n&&Mn(e)}function kn(e){return e.length?t=>jn(t,e):d}function An(e,t){let n=e.slice(0,-1),r=e[e.length-1];return e=>{let i=jn(e,n),a=i&&typeof i==`object`?Reflect.get(i,r):void 0;return typeof a==`function`?Reflect.apply(a,i,t.args??bn):void 0}}function jn(e,t){let n=e;for(let e=0;e<t.length;e++){if(!n||typeof n!=`object`)return n;n=Reflect.get(n,t[e])}return n}function Mn(e){let t=e.length;console.log(`[πŸ“‘ ${t} ${en(`Proxy Subscription`,t)} πŸ“‘]:`,JSON.stringify(e.map(e=>{let t=Nn(e.store),n=e.path.join(`.`);if(!e.invocation)return n?`$(${t}).${n}`:`$(${t})`;let r=e.invocation.args?.length??0;return`$(${t}).${n}${r?`(${r}_${en(`arg`,r)})`:`()`}`}),null,2))}function Nn(e){return`name`in e&&typeof e.name==`string`?e.name:`store`}const Pn=Symbol(),Fn=Symbol(),In=Symbol(`stores.derivedStore.readDependencyState`);function Ln(e,t=Object.is){let n,r=!1,i,a=!1,o=!1;typeof t==`function`?i=t:(n=t.debounce,r=l?t.debugMode??!1:!1,i=t.equalityFn??Object.is,a=t.keepAlive??!1,o=t.lockDependencies??!1);let s=new rn,c=new nn(A),u=+!!a,f,p,m=Pn,h=!1,g=!1,_=!0,v=!0,y=null,b=Fn;function x(e,t,n){if(!v)return(t??d)(Bn(e));if(!u)return(t??d)(e.getState());if(!t){let t=Bn(e);return!t||typeof t!=`object`?(c.retainState(e),t):(f||(f=new WeakMap),p||(p=xn()),un(e,t,f,p.trackPath))}let r=n?{equalityFn:n,isCascadeParticipant:!0}:tn;return c.addSelector(e.subscribe(t,A,r)),t(Bn(e))}function S(){if(!_&&$(m))return m;_=!1,v&&c.beginRebuild(!0);let t=!0,n=m,a=$(n);g=!0;try{let o=e(x),s=p?pn(o):o;a&&i(n,s)?(r&&console.log(`[πŸ₯· Derive Complete πŸ₯·]: No change detected`),t=!1,m=n):m=s}finally{g=!1,v&&c.finishRebuild(!0)}let s=r&&(!a||r===`verbose`&&v);if(s){a?r===`verbose`&&console.log(`[πŸŒ€ Rebuilding Subscriptions πŸŒ€]: Created…`):console.log(`[πŸŒ€ Initial Derive Complete πŸŒ€]: Created…`);let e=c.size;console.log(`[🎯 ${e} ${en(`Selector Subscription`,e)} 🎯]`)}return p&&v&&(p.buildProxySubscriptions((e,t)=>{c.addSelector(e.subscribe(t,A,tn))},s),f=void 0,o?p=void 0:p.reset()),t&&a&&C(m,n),o&&(v=!1),m}function C(e,t){let n=s.cascadeParticipantCount,i=n>0&&s.ordinaryWatcherCount>0,a=s.ordinaryWatcherCount>0&&(i||Xe()!==null||Ye());if(i&&Ze(),r){let e=s.ordinaryWatcherCount+n;console.log(`[πŸ“» Derive Complete πŸ“»]: Notifying ${e} ${en(`watcher`,e)}`)}if(n&&s.notifyCascade(e,t),s.ordinaryWatcherCount){if(a){b===Fn?(b=t,et(w)):$(b)||(b=t);return}s.notifyOrdinary(e,t)}}function w(){u&&_&&!s.cascadeParticipantCount&&S();let e=b;b=Fn,s.ordinaryWatcherCount&&$(m)&&e!==Fn&&$(e)&&s.notifyOrdinary(m,e)}let T=n?Et(D,typeof n==`number`?n:n.delay,typeof n==`number`?{leading:!1,maxWait:n,trailing:!0}:n):void 0,E=T??(()=>{h||(h=!0,queueMicrotask(D))});function D(){if(h=!1,!u){a||I();return}_&&S()}function O(e){if(e!==void 0&&(e||T&&_)){queueMicrotask(O);return}!u&&!a&&I()}function k(){let e=y;e===Xe()&&(D(),y===e&&(y=null))}function A(){if(!g){if(!T){if(s.cascadeParticipantCount){_=!0,Ze();let e=Xe(),t=e===null?0:e+1;if(y!==null&&t<=y)return;y=t,tt(k,t);return}if(_)return;if(_=!0,Ye()){b===Fn&&(b=Pn,et(w));return}}_||(_=!0,y=null,E())}}function j(e){u+=1;try{return e()}finally{--u,u||queueMicrotask(O)}}function ee(){return _||!$(m)?u?S():j(S):(h&&u&&D(),m)}function M(){return Ye()&&Xe()===null&&$e(),_||!$(m)?u?S():e(x):m}function N(...e){if(e.length===1){let t=e[0];return s.addWatcher(t)&&(u+=1),$(m)||M(),()=>{s.deleteWatcher(t)&&(--u,u||O(!1))}}let[t,n,r]=e,i=r?.equalityFn??Object.is,a=r?.isCascadeParticipant??!1,o=t(u?M():j(M)),c={currentSlice:o,equalityFn:i,isCascadeParticipant:a,listener:n,selector:t};return s.addWatcher(c),u+=1,r?.fireImmediately&&n(o,o),()=>{s.deleteWatcher(c)&&(--u,u||O(a))}}function P(e){return u?M():j(M),s.addCascadeStateListener(e)&&(u+=1),()=>{s.deleteCascadeStateListener(e)&&(--u,u||O(!0))}}function F(){u&&(T?T.flush():_&&S())}function I(){T?.cancel(),c.clear(),s.clear(),u=0,p=void 0,f=void 0,v=!0,h=!1,g=!1,_=!0,m=Pn,b=Fn,y=null}function L(){return _||h||!$(m)?u?S():j(S):m}return{[In]:L,[Q]:P,destroy:I,flushUpdates:F,getSnapshot:ee,getState:M,subscribe:N,getInitialState:Rn,setState:zn}}function Rn(){throw Error(`[createDerivedStore]: getInitialState() is not available on derived stores.`)}function zn(){throw Error(`[createDerivedStore]: setState() is not available on derived stores.`)}function Bn(e){let t=e[In];return t?t():e.getState()}function $(e){return e!==Pn}var Vn=class{constructor(e){this.count=0,this.lastSubscriptionTime=null,this.fetchThrottleMs=null,this.onSubscribe=null,this.onLastUnsubscribe=null,e&&(this.fetchThrottleMs=q.seconds(5))}init({onSubscribe:e,onLastUnsubscribe:t}){this.onSubscribe=e,this.onLastUnsubscribe=t}hasSubscribers(){return this.count>0}subscribe(){let e=this.count===0,t=this.fetchThrottleMs!==null,n=t&&this.lastSubscriptionTime!==null&&!e&&Date.now()-this.lastSubscriptionTime<=this.fetchThrottleMs;return this.count+=1,this.onSubscribe?.(e,n),t&&(this.lastSubscriptionTime=Date.now()),e=>{let t=this.count===1;this.count=Math.max(this.count-1,0),t&&(this.onLastUnsubscribe?.(e),this.lastSubscriptionTime=null)}}};function Hn(e,t=queueMicrotask){let n=!1,r;function i(){n=!1,e(...r)}function a(...e){r=e,!n&&(n=!0,t(i))}return a}const Un=Symbol(`stores.queryParamConfig`);function Wn(e,t){return{[Un]:!0,key:t.key,value:e}}function Gn(e){return!!e&&typeof e==`object`&&Un in e}function Kn(e){return JSON.stringify(Jn(e))}function qn(e){return JSON.parse(e)}function Jn(e){return typeof e!=`object`||!e?e:Object.keys(e).sort().reduce((t,n)=>{let r=e[n];return t[n]=F(r)?Jn(r):r,t},f())}const Yn=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});function Xn(e,t,n){let r=f(),i=null,a=!1;if(e)for(let n in e){if(!N(e,n))continue;let o=Zn(r,e[n],n,t);o&&((i??(i=f()))[n]=o,o.key!==void 0&&(a=!0))}return{buildKey(e=r){return Kn(a?nr(i,e):e)},complete(e){return e?ar(e,n)?e:{...r,...e}:er(r)},get(){return er(r)},subscribe(e){return tr(i,r,e)}}}function Zn(e,t,n,r){return Gn(t)?$n(e,t.value,n,r,t.key):$n(e,t,n,r)}function Qn(e,t){let n=[],r,i;function a(e,t,a){return t?(n.push(n=>e.subscribe(t,n,rr(a))),t(ir(e))):(r??(r=xn()),i??(i=new WeakMap),un(e,ir(e),i,r.trackPath))}function o(e,t=d){return t(ir(e))}let s=e(a,t),c=r?pn(s):s;return r&&(r.buildProxySubscriptions((e,t)=>{n.push(n=>e.subscribe(t,n,Yn))},!1),r=void 0),i=void 0,{initialValue:c,subscribe(r){let i=()=>r(e(o,t)),a=n.map(e=>e(i));return e=>{for(let t of a)t(e)}}}}function $n(e,t,n,r,i){if(or(t)){let a=Qn(t,r);return e[n]=a.initialValue,i===void 0?{tracked:a}:{key:i,tracked:a}}return e[n]=t,i===void 0?null:{key:i}}function er(e){let t=f();for(let n in e)N(e,n)&&(t[n]=e[n]);return t}function tr(e,t,n){if(!e)return m;let r;for(let i in e){let a=e[i]?.tracked;a&&(r??(r=[])).push(a.subscribe(e=>{let r=t[i];Ie(r,e)||(t[i]=e,n(i,r,e))}))}return r?e=>{for(let t of r)t(e)}:m}function nr(e,t){let n=f();for(let r in t){if(!N(t,r))continue;let i=e?.[r];if(i?.key===!1)continue;let a=t[r];n[r]=i?.key?i.key(a):a}return n}function rr(e){return e?{equalityFn:e,isCascadeParticipant:!0}:Yn}function ir(e){return Te(e)?e.getSnapshot():e.getState()}function ar(e,t){for(let n of t)if(!(n in e))return!1;return!0}function or(e){return typeof e==`function`}const sr={error:!0,lastFetchedAt:!0,queryCache:!0,queryKey:!0,status:!0,enabled:!1,fetch:!1,getCacheEntry:!1,getData:!1,getStatus:!1,isDataExpired:!1,isStale:!1,reset:!1},cr=Object.freeze({force:!0}),lr=Object.freeze({once:!0}),ur=new Set;let dr=!1;function fr(e){ur.add(e),!dr&&(dr=!0,queueMicrotask(()=>{dr=!1,Ve(pr)}))}function pr(){for(let e of ur)ur.delete(e),e()}function mr(e,t,n){ae();let r=typeof t==`function`?t:vr,i=typeof t==`object`?t:n,a=hr(i)?i:void 0,o=le(),s=o.minStaleTime,{fetcher:c,onError:d=o.onError,onFetched:f,setData:m,transform:h,abortInterruptedFetches:g=o.abortInterruptedFetches,cacheTime:_=o.cacheTime,debugMode:v=o.debugMode,disableAutoRefetching:y=o.disableAutoRefetching,disableCache:b=!1,enabled:x=!0,keepPreviousData:S=o.keepPreviousData,paramChangeThrottle:C=o.paramChangeThrottle,params:w,retry:T=o.retry,retryDelay:E=o.retryDelay,staleTime:D=o.staleTime,suppressStaleTimeWarning:O=o.suppressStaleTimeWarning}=e,k=typeof D==`function`?o.staleTime:D;l&&s!==!1&&!y&&!O&&k<s&&console.warn(`[createQueryStore${a?.storageKey?`: ${a.storageKey}`:``}] ❌ Stale times under ${s/1e3} seconds are not recommended. Provided staleTime: ${k/1e3} seconds`);let A=Error(`[createQueryStore: AbortError] Fetch interrupted`),ee=typeof _==`function`,M=l&&v,N=e.params?Object.keys(e.params):[],P=!1,F,I=[],R=null,z=null,B=null,V=null,H=null,U=null,ne=null,re={enabled:typeof x==`function`?!1:x,error:null,lastFetchedAt:null,queryCache:{},queryKey:``,status:K.Idle},W=new Vn(y);function ie(){B&&(V=null,B.abort(),B=null)}function G(){H&&(clearTimeout(H),H=null)}async function oe(e){let t=new AbortController;B=t;try{return await new Promise((n,r)=>{t.signal.addEventListener(`abort`,()=>r(A),lr),Promise.resolve(c(e,t)).then(n,r)})}finally{B===t&&(B=null)}}function se(e,t,n){let i=n.setState;function o(e,t){e!==t&&ne!==t&&(ne=t,t&&W.hasSubscribers()?queueMicrotask(()=>p.fetch(void 0,void 0,!0)):(H||g)&&(g&&ie(),G()))}function s(e){let t=typeof e==`function`;if(t||e.enabled!==void 0){let n,r=i(r=>{let i=t?e(r):e,a=i.enabled===void 0?r.enabled:i.enabled;return a!==r.enabled&&(n=()=>o(r.enabled,a)),i});return n?.(),r}else return i(e)}n.setState=s,W.init({onSubscribe:(n,r)=>{let i=t();if(i.enabled)if(n){let t=F.get(),n=F.buildKey(t);i.queryKey!==n&&e({queryKey:n}),i.isStale()?p.fetch(t,void 0,!0):l(t)}else y&&!r&&p.fetch(void 0,void 0,!0)},onLastUnsubscribe:e=>{G(),g&&!e&&ie()}});function l(e){if(y||k<=0||k===1/0||!W.hasSubscribers())return;G();let n=t();if(!n.enabled)return;let r=F.buildKey(e),i=(b?U===r&&n.lastFetchedAt:n.queryCache[r]?.lastFetchedAt)||null,a=i?k-(Date.now()-i):k;H=setTimeout(()=>{t().enabled&&p.fetch(e,cr,!0)},a)}function u(e){let n=t(),r=n.status;switch(e){case`isIdle`:return r===K.Idle;case`isLoading`:return r===K.Loading;case`isError`:case`isInitialLoad`:case`isSuccess`:case void 0:{let t=n.queryKey,i=b?void 0:n.queryCache[t],a=b?r===K.Error:typeof i?.errorInfo?.lastFailedAt==`number`;if(e===`isError`)return a;let o=((b?U===t&&n.lastFetchedAt:i?.lastFetchedAt)||null)!==null,s=!o&&!a&&n.enabled;if(e===`isInitialLoad`)return s;let c=o&&!a;return e===`isSuccess`?c:{isError:a,isIdle:r===K.Idle,isLoading:r===K.Loading,isInitialLoad:s,isSuccess:c}}}}let p={...r(s,t,n),...re,async fetch(n,r,i=!1,o=0){let u=!!r?.skipStoreUpdates,v=t();if(!u&&(!v.enabled&&!r?.force||i&&!W.hasSubscribers()))return null;let y=v.error,x=v.queryKey,C=v.status===K.Loading,w=F.complete(n),D=F.buildKey(w);if(C&&V?.promise&&V.key===D)return M&&console.log(`[πŸ”„ Using Active Fetch πŸ”„] for params:`,JSON.stringify(w)),V.promise;let O=r?.staleTime??k,P=typeof r?.updateQueryKey==`boolean`?r.updateQueryKey:i?S:!1,I=(i||x===D||P)&&!u,R=V!==null;if(g&&I&&ie(),!r?.force){let t=v.lastFetchedAt,n=b?void 0:v.queryCache[D],r=n?.lastFetchedAt,i=n?.errorInfo,a=(b?U===D&&t:r)||null;if(!(!a||Date.now()-a>=O)&&(!i||!i.retryAllowed||u))return I&&!H&&k!==0&&k!==1/0&&l(w),P&&e(e=>e.queryKey===D?e:{queryKey:D}),M&&console.log(`[πŸ’Ύ Returning Cached Data πŸ’Ύ] for params:`,JSON.stringify(w)),n?.data??null}let z=I?{key:D}:null,B=r?.cacheTime??(ee?_(w):_);z&&(G(),P&&!R&&v.lastFetchedAt===null&&x!==D?e({error:null,queryKey:D,status:K.Loading}):(y||!C)&&e({error:null,status:K.Loading}),V=z);async function ne(){let v=a?.storageKey||D;try{M&&(!i&&n&&N.some(e=>!(e in n))?console.log(`[πŸ”„ Fetching with Partial Params πŸ”„]
7
+ `,`- Provided params:`,`${JSON.stringify(n)}\n`,`- Filled in params:`,`${JSON.stringify(Object.fromEntries(Object.keys(w).filter(e=>!(e in n)).map(e=>[e,w[e]])))}`):console.log(`[πŸ”„ Fetching πŸ”„] for params:`,JSON.stringify(w)));let t=await(g&&I?oe(w):c(w,null)),a=Date.now();M&&console.log(`[βœ… Fetch Successful βœ…] for params:`,JSON.stringify(w));let o;try{o=br(t,w,h)}catch(e){throw yr(v,`transform`,e)}if(u)return M&&console.log(`[πŸ₯· Successful Parallel Fetch πŸ₯·] for params:`,JSON.stringify(w)),r.skipStoreUpdates===`withCache`&&e(e=>{if(!m)return b?e:{queryCache:{...e.queryCache,[D]:{cacheTime:B,data:o,errorInfo:null,lastFetchedAt:a}}};let t=e,n=b?void 0:t.queryCache[D];try{m({data:o,params:w,queryKey:D,set:e=>{t=typeof e==`function`?{...t,...e(t)}:{...t,...e}}})}catch(e){throw yr(v,`setData`,e)}return!b&&Object.is(n,t.queryCache[D])&&(t={...t,queryCache:{...t.queryCache,[D]:{cacheTime:B,data:null,errorInfo:null,lastFetchedAt:a}}}),t}),o;if((m?s:e)(e=>{let t=z&&V===z?{...e,error:null,lastFetchedAt:a,queryKey:P?D:e.queryKey,status:K.Success}:{...e};if(!m&&!b)M&&console.log(`[πŸ’Ύ Setting Cache πŸ’Ύ] for params:`,JSON.stringify(w),`| Has previous data?:`,!!t.queryCache[D]?.data),t.queryCache={...t.queryCache,[D]:{cacheTime:B,data:o,errorInfo:null,lastFetchedAt:a}};else if(m){M&&console.log(`[πŸ’Ύ Setting Data πŸ’Ύ] for params:`,JSON.stringify(w));let e=b?void 0:t.queryCache[D];try{m({data:o,params:w,queryKey:D,set:e=>{t=typeof e==`function`?{...t,...e(t)}:{...t,...e}}})}catch(e){throw yr(v,`setData`,e)}!b&&Object.is(e,t.queryCache[D])&&(t.queryCache={...t.queryCache,[D]:{cacheTime:B,data:null,errorInfo:null,lastFetchedAt:a}})}return b||_===1/0?t:_r(S,D,t)}),z&&V===z&&(U=D,l(w)),f)try{f({data:o,fetch:p.fetch,params:w,set:s})}catch(e){j.error(yr(v,`onFetched callback`,e))}return o??null}catch(n){if(n===A)return M&&console.log(`[❌ Fetch Aborted ❌] for params:`,JSON.stringify(w)),null;let a=!i&&r?.throwOnError===!0,s=te(n);if(s instanceof L&&j.error(s),!I){if(a)throw s;return null}let c=b?void 0:t().queryCache[D],l,u;if(typeof T==`function`){l={error:s,params:w,queryKey:D,retryCount:o};try{u=T(l)}catch(e){j.error(yr(v,`retry callback`,e)),u=!1}}else u=T!==!1&&o<T;let f;if(u&&V===z&&t().enabled&&W.hasSubscribers())if(E===void 0)f=de(o);else if(typeof E==`number`)f=E;else{l??(l={error:s,params:w,queryKey:D,retryCount:o});try{f=E(l)}catch(e){j.error(yr(v,`retryDelay callback`,e)),u=!1}}if(f!==void 0&&(G(),H=setTimeout(()=>{t().enabled&&p.fetch(w,cr,!0,o+1)},f)),e(e=>{let t={...e};return V===z&&(t.error=s,P&&(t.queryKey=D),t.status=K.Error),b||(t.queryCache={...e.queryCache,[D]:{cacheTime:c?.cacheTime??B,data:c?.data??null,lastFetchedAt:c?.lastFetchedAt??null,errorInfo:{error:s,lastFailedAt:Date.now(),retryAllowed:u,retryCount:o}}}),t}),d)try{d({error:s,params:w,queryKey:D,retryCount:o,willRetry:f!==void 0})}catch(e){j.error(yr(v,`onError callback`,e))}if(a)throw s;return null}finally{V===z&&(V=null)}}return z?(z.promise=ne(),z.promise):ne()},getCacheEntry(e){if(b)return null;let n=t(),r=e?typeof e==`string`?e:F.buildKey(F.complete(e)):n.queryKey;return n.queryCache[r]??null},getData(e){if(b)return null;let n=t().getCacheEntry(e);return!n||n.data===null?null:S?n.data:n.lastFetchedAt&&Date.now()-n.lastFetchedAt>=n.cacheTime?null:n.data},getStatus:u,isDataExpired(e){let n=t(),r=n.queryKey,i=b?void 0:n.queryCache[r],a=n.lastFetchedAt,o=(b?U===r&&a:i?.lastFetchedAt)||null;if(!o)return!0;let s=e??i?.cacheTime;return s===void 0||Date.now()-o>=s},isStale(e){let n=t(),r=n.queryKey,i=(b?U===r&&n.lastFetchedAt:n.queryCache[r]?.lastFetchedAt)||null;if(!i)return!0;let a=e??k;return Date.now()-i>=a},reset(t=!1){for(let e of I)e();I=[],F=Xn(void 0,q,N),R=null,z=null,ie(),G(),_e?.cancel(),V=null,U=null,t&&e(re)}},v=n.subscribe;return n.subscribe=(...e)=>{let t=P?void 0:W.subscribe(),n=e.length===1?v(e[0]):v(e[0],e[1],e[2]);return e=>{t?.(e),n(e)}},lt(n,e=>t=>{let n=P?void 0:W.subscribe(),r=e(t);return e=>{n?.(e),r(e)}}),p}let q=a?.storageKey?Qt(se,p(a,{partialize:gr(S,a.partialize)})):i&&!(`storageKey`in i)?Qt(se,i):Qt(se),ce=q.getState(),ue=ce.error,fe=ce.enabled,pe=ce.queryKey,me=ce.fetch;pe&&!ue&&(U=pe),P=!0,F=Xn(w,q,N),typeof x==`function`&&(R=Qn(x,q)),typeof e.staleTime==`function`&&(z=Qn(e.staleTime,q),k=z.initialValue);let he=Hn(e=>{me(e,void 0,!0)},fr);function ge(){if(S)he(void 0);else{let e=F.get();q.setState({queryKey:F.buildKey(e)}),he(e)}}let _e=u||!C?void 0:Et(ge,typeof C==`number`?C:C.delay,typeof C==`number`?{leading:!1,maxWait:C,trailing:!0}:C);function ve(){if(G(),_e){let e=q.getState();S&&V?.key===e.queryKey&&e.lastFetchedAt===null?ge():_e();return}ge()}if(I.push(F.subscribe((e,t,n)=>{M&&console.log(`[πŸŒ€ Param Change πŸŒ€] -`,e,`- [Old]:`,`${t?.toString()},`,`[New]:`,n?.toString()),ve()})),z){let e=z.initialValue;M&&console.log(`[πŸŒ€ StaleTime Subscription πŸŒ€] Initial value:`,e),I.push(z.subscribe(t=>{t!==e&&(M&&console.log(`[πŸŒ€ StaleTime Change πŸŒ€] - [Old]:`,`${e},`,`[New]:`,t),e=t,k=t,G(),me(void 0,void 0,!0))}))}let J;if(R){let e=R.initialValue;fe!==e&&((J??(J={})).enabled=e),M&&console.log(`[πŸŒ€ Enabled Subscription πŸŒ€] Initial value:`,e),I.push(R.subscribe(t=>{t!==e&&(M&&console.log(`[πŸŒ€ Enabled Change πŸŒ€] - [Old]:`,`${e},`,`[New]:`,t),e=t,q.setState({enabled:t}))}))}else fe!==re.enabled&&((J??(J={})).enabled=re.enabled);let xe=F.buildKey();return xe!==pe&&((J??(J={})).queryKey=xe),J&&q.setState(J),P=!1,be(q,ye.QueryStore)}function hr(e){return typeof e?.storageKey==`string`}function gr(e,t){return n=>{let r={...n},i=f();for(let e in r)N(r,e)&&e in sr&&(sr[e]&&(i[e]=r[e]),delete r[e]);return{...t?t(r):At(r),..._r(e,null,i)}}}function _r(e,t,n){if(!n.queryCache)return n;let r=Date.now(),i=f(),a=!1;for(let o in n.queryCache){if(!N(n.queryCache,o))continue;let s=n.queryCache[o];s&&(r-(s.lastFetchedAt??s.errorInfo.lastFailedAt)<s.cacheTime||o===t||e&&o===n.queryKey)?i[o]=s:a=!0}return a?{...n,queryCache:i}:n}function vr(){return Object.create(null)}function yr(e,t,n){return new L(`[createQueryStore: ${e}]: ${t} failed`,n)}function br(e,t,n){return n?n(e,t):e}const xr=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});function Sr(e,t,n){let r=typeof t==`function`,i=r?t:void 0,a=r?n:t,o=new Set,s,c;function l(e,t){let n=e.getState(),r=t.getState();if(c)for(let e of c)u(e,t,n,r);if(s)for(let e of s)d(e,t,n,r);o.size&&Qe();for(let e of o)f(e,t,n,r)}function u(e,t,n,r){e.unsubscribe(),e.unsubscribe=Cr(t,e.listener),!Object.is(r,n)&&(Ze(),e.listener(r,n))}function d(e,t,n,r){f(e,t,n,r)&&Ze()}function f(e,t,n,r){e.unsubscribe();let i=e.args;if(i.length===1){let a=i[0];e.unsubscribe=t.subscribe(a);let o=!Object.is(r,n);return o&&a(r,n),o}let a=i[0],o=i[1],s=i[2];s?.fireImmediately&&(s={...s,fireImmediately:!1});let c=a(n),l=a(r);return e.unsubscribe=t.subscribe(a,o,s),(s?.equalityFn??Object.is)(c,l)?!1:(o(l,c),!0)}function p(e,t){l(t,e),J(t)}let m=Ln(e,{debugMode:a?.debugMode??!1,lockDependencies:a?.lockDependencies??!0}),h;function g(){return h??(h=m.subscribe(p)),m.getState()}function _(...e){let t=g(),n={args:e,unsubscribe:e.length===1?t.subscribe(e[0]):t.subscribe(e[0],e[1],e[2])},r=e[2]?.isCascadeParticipant??!1;return r?(s??(s=new Set)).add(n):o.add(n),()=>{n.unsubscribe(),r?s?.delete(n)&&s.size===0&&(s=void 0):o.delete(n)}}function v(e){let t={listener:e,unsubscribe:Cr(g(),e)};return(c??(c=new Set)).add(t),e=>{t.unsubscribe(e),c?.delete(t)&&c.size===0&&(c=void 0)}}return Object.assign({[Q]:v,[ye.VirtualStore]:!0,destroy:()=>{h?.(),h=void 0,m.destroy()},getInitialState:()=>g().getInitialState(),getState:()=>g().getState(),persist:wr(g),setState:Tr(g),subscribe:_},i?.(g))}function Cr(e,t){return ct(e)?e[Q](t):e.subscribe(d,t,xr)}function wr(e){return{clearStorage:()=>e().persist?.clearStorage(),getOptions:()=>e().persist?.getOptions()??{},hasHydrated:()=>e().persist?.hasHydrated()??!0,hydrationPromise:()=>e().persist?.hydrationPromise?.()??Promise.resolve(),onFinishHydration:t=>e().persist?.onFinishHydration(t)??m,onHydrate:t=>e().persist?.onHydrate(t)??m,rehydrate:()=>e().persist?.rehydrate(),setOptions:t=>e().persist?.setOptions(t)}}function Tr(e){return function(...t){return t[1]===!0?e().setState(t[0],!0):e().setState(t[0])}}function Er(e,t){let n=Qt(e,t);return D(n,n.getState,n.getInitialState)}function Dr(e,t=Object.is){let n=Ln(e,t);return D(n,n.getSnapshot,void 0)}function Or(e,t,n){let r=mr(e,t,n);return D(r,r.getState,r.getInitialState)}function kr(e,t,n){let r=Sr(e,t,n);return D(r,r.getState,r.getInitialState)}const Ar=Symbol();function jr(e){let t=r(Ar);return t.current===Ar&&(t.current=e()),t}const Mr=Object.freeze({debugMode:!1,enabled:!0,equalityFn:Object.is,fireImmediately:!1});function Nr(e,t,r,i=Mr){let a=jr(()=>Lr(t,r,i)),o=zr(i);return Br(a,t,r,i),n(()=>{if(o)return Fr(e,a),()=>Ir(a)},[o,e]),a}const Pr=Object.freeze({fireImmediately:!1,forceResubscribe:!1});function Fr(e,t,n=Pr){let r=t.current;if(r.isActive){if(!n.forceResubscribe)return;r.unsubscribe()}let i=Rr(r.options),a=i.equalityFn??Object.is,o=r.selector(e.getState()),s=m;function c(t){if(!r.isActive)return;let n=r.selector(t);if(a(o,n))return;let i=o;o=n,r.react(n,i,e.getState,r.unsubscribe)}if(r.isActive=!0,r.resubscribe=(n=Pr)=>Fr(e,t,n),r.refresh=()=>c(e.getState()),r.unsubscribe=()=>{r.isActive&&(r.isActive=!1,r.refresh=m,s())},s=e.subscribe(c),!r.isActive){s();return}l&&i.debugMode&&console.log(`[πŸ“‘ useListen πŸ“‘] Attached listener`),(n.fireImmediately||i.fireImmediately)&&r.react(o,o,e.getState,r.unsubscribe)}function Ir(e){let t=e.current;t.resubscribe=m,t.unsubscribe(),t.unsubscribe=m,t.isActive=!1,!(!l||typeof t.options==`function`)&&t.options?.debugMode&&console.log(`[πŸ—‘οΈ useListen πŸ—‘οΈ] Detached listener`)}function Lr(e,t,n){return{selector:e,react:t,isActive:!1,options:n,refresh:m,resubscribe:m,unsubscribe:m}}function Rr(e){return typeof e==`function`?{equalityFn:e}:e??Mr}function zr(e){return typeof e==`function`?Mr.enabled:e?.enabled??Mr.enabled}function Br(e,t,n,r){let i=e.current;i.selector=t,i.react=n,i.options=r}const Vr=Symbol();function Hr(e){let t=r(Vr);return t.current===Vr&&(t.current=e()),t.current}export{K as QueryStatuses,L as StoresError,pe as applyStateUpdate,re as configureStores,Er as createBaseStore,Dr as createDerivedStore,Or as createQueryStore,Ae as createStoreActions,kr as createVirtualStore,Pe as deepEqual,de as defaultRetryDelay,J as destroyStore,xe as destroyStores,Kn as getQueryKey,Se as getStoreName,Te as hasGetSnapshot,d as identity,De as isDerivedStore,Oe as isPersistedStore,Ee as isQueryStore,ke as isVirtualStore,f as nullObject,qn as parseQueryKey,Wn as queryParam,_e as replacer,ve as reviver,Fe as shallowEqual,q as time,Nr as useListen,Hr as useStableValue};
@@ -498,6 +498,7 @@ type PersistConfig<S, PersistedState extends Partial<S> = Partial<S>, PersistRet
498
498
  partialize?: (state: Readonly<S>) => PersistedState;
499
499
  /**
500
500
  * The throttle rate for the persist operation in milliseconds.
501
+ * Applies to synchronous storage. Async storage batches updates without a timed delay.
501
502
  * @default iOS: time.seconds(3) | Android: time.seconds(5)
502
503
  */
503
504
  persistThrottleMs?: PersistReturn extends Promise<unknown> ? undefined : number;
@@ -507,8 +508,10 @@ type PersistConfig<S, PersistedState extends Partial<S> = Partial<S>, PersistRet
507
508
  */
508
509
  serializer?: (storageValue: StorageValue<PersistedState>) => string;
509
510
  /**
510
- * Custom storage implementation. If async, `setState` will return a Promise that resolves
511
- * when the state is persisted. If sync, `setState` will return void.
511
+ * Custom storage implementation. If async, `setState` returns a Promise that resolves
512
+ * after its batched persistence attempt completes. Storage and serialization failures are
513
+ * logged without rejecting the promise. Unchanged-state updates resolve immediately.
514
+ * If sync, `setState` returns void.
512
515
  */
513
516
  storage?: PersistReturn extends Promise<unknown> ? AsyncStorageInterface : SyncStorageInterface;
514
517
  /**