@storesjs/stores 0.10.0 → 0.11.0

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.
Files changed (48) hide show
  1. package/dist/createBaseStore.d.ts +2 -2
  2. package/dist/createQueryStore.d.ts +7 -13
  3. package/dist/internal/derivedStore/deriveProxy.d.ts +2 -2
  4. package/dist/internal/queryStore/queryParams.d.ts +18 -0
  5. package/dist/internal/runtime.d.ts +0 -1
  6. package/dist/internal/types/internalSubscribeTypes.d.ts +16 -0
  7. package/dist/native/index.js +1 -1
  8. package/dist/native/index.mjs +1 -1
  9. package/dist/queryStore/classes/SubscriptionManager.d.ts +3 -31
  10. package/dist/queryStore/queryKey.d.ts +9 -2
  11. package/dist/queryStore/queryParam.d.ts +37 -0
  12. package/dist/queryStore/types.d.ts +10 -52
  13. package/dist/{vanilla/internal/derivedStore → store}/cascadeScheduler.d.ts +13 -5
  14. package/dist/types/subscribe.d.ts +4 -5
  15. package/dist/types.d.ts +10 -8
  16. package/dist/utils/createMicrotaskScheduler.d.ts +2 -1
  17. package/dist/vanilla/createBaseStore.d.ts +2 -2
  18. package/dist/vanilla/createQueryStore.d.ts +7 -13
  19. package/dist/vanilla/index.js +1 -1
  20. package/dist/vanilla/index.mjs +1 -1
  21. package/dist/vanilla/internal/derivedStore/deriveProxy.d.ts +2 -2
  22. package/dist/vanilla/internal/queryStore/queryParams.d.ts +17 -0
  23. package/dist/vanilla/internal/runtime.d.ts +0 -1
  24. package/dist/vanilla/internal/types/internalSubscribeTypes.d.ts +15 -0
  25. package/dist/vanilla/queryStore/classes/SubscriptionManager.d.ts +3 -31
  26. package/dist/vanilla/queryStore/queryKey.d.ts +9 -2
  27. package/dist/vanilla/queryStore/queryParam.d.ts +36 -0
  28. package/dist/vanilla/queryStore/types.d.ts +10 -52
  29. package/dist/{internal/derivedStore → vanilla/store}/cascadeScheduler.d.ts +12 -6
  30. package/dist/vanilla/types/subscribe.d.ts +4 -5
  31. package/dist/vanilla/types.d.ts +10 -8
  32. package/dist/vanilla/utils/createMicrotaskScheduler.d.ts +2 -1
  33. package/dist/web/chrome.js +1 -1
  34. package/dist/web/chrome.mjs +1 -1
  35. package/dist/web/chunk-FENSEQ3V.mjs +1 -0
  36. package/dist/web/chunk-FPYZVFBM.mjs +1 -0
  37. package/dist/web/chunk-PLDNKWGX.mjs +1 -0
  38. package/dist/web/index.js +1 -1
  39. package/dist/web/index.mjs +1 -1
  40. package/dist/web/internal/runtime.js +1 -1
  41. package/dist/web/internal/runtime.mjs +1 -1
  42. package/package.json +1 -1
  43. package/dist/internal/signal.d.ts +0 -12
  44. package/dist/queryStore/signalTypes.d.ts +0 -14
  45. package/dist/vanilla/internal/signal.d.ts +0 -11
  46. package/dist/vanilla/queryStore/signalTypes.d.ts +0 -13
  47. package/dist/web/chunk-QJLWBD7M.mjs +0 -1
  48. package/dist/web/chunk-V4LHP7LR.mjs +0 -1
@@ -1 +1 @@
1
- import{noop as e}from"./chunk-V4LHP7LR.mjs";import{useLayoutEffect as t,useRef as r,useSyncExternalStore as n,useDebugValue as o}from"react";import{baseStore as u,derivedStore as c,queryStore as i,getQueryKey as s,parseQueryKey as a,virtualStore as l}from"./internal/runtime.mjs";export{QueryStatuses,StoresError,applyStateUpdate,configureStores,createStoreActions,deepEqual,defaultRetryDelay,destroyStore,destroyStores,getStoreName,hasGetSnapshot,identity,isDerivedStore,isPersistedStore,isQueryStore,isVirtualStore,nullObject,replacer,reviver,shallowEqual,time}from"./internal/runtime.mjs";var S=Symbol("empty selection"),m=Object.is;function f(e,t){return r=>(function(e){e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedSource=e.source,e.committedValue=e.value===S?d(e):e.value}(e),t(n=>{e.latestSnapshot=n,e.latestSource=t;const o=e.committedValue;if(o===S||e.committedSource!==t)return void r();const u=e.committedSelector,c=e.committedEqualityFn;if(e.selector===u&&e.equalityFn===c){const t=u(n);if(c===m?m(o,t):c(o,t))return;return e.committedValue=t,e.value=t,e.valueEqualityFn=c,e.valueSelector=u,e.valueSnapshot=n,void r()}if(e.source!==t)return void r();const i=e.value;if(i===S)return;const s=e.selector(n),a=e.equalityFn(i,s);e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedValue=p(e,n,a?i:s),a||r()}))}function d(e){const t=function(e){if(e.latestSource===e.source&&e.latestSnapshot!==S)return e.latestSnapshot;const t=e.getStoreSnapshot();return e.latestSnapshot=t,e.latestSource=e.source,t}(e);return b(e,t)}function b(e,t){const r=e.value;if(r!==S&&m(e.valueSnapshot,t)&&e.valueSelector===e.selector&&e.valueEqualityFn===e.equalityFn)return r;const n=e.selector(t);if(r!==S&&(e.equalityFn===m?m(r,n):e.equalityFn(r,n)))return p(e,t,r);const o=e.committedValue;return o!==S&&o!==r&&e.committedSource===e.source&&(e.equalityFn===m?m(o,n):e.equalityFn(o,n))?p(e,t,o):p(e,t,n)}function p(e,t,r){return e.value=r,e.valueEqualityFn=e.equalityFn,e.valueSelector=e.selector,e.valueSnapshot=t,r}function y(t,u,c,i){return Object.assign(function(s,a){return function(t,u,c,i,s=m){const a=r(null);let l=t,p=u,y=c;if(i){let r=a.current;null===r&&(r=function(t,r,n,o,u){const c={committedEqualityFn:u,committedSelector:o,committedSource:t,committedValue:S,equalityFn:u,getSelectedServerSnapshot:()=>function(e){return b(e,(e.getServerStoreSnapshot??e.getStoreSnapshot)())}(c),getSelectedSnapshot:()=>d(c),getServerStoreSnapshot:n,getStoreSnapshot:r,latestSnapshot:S,latestSource:S,selector:o,selectedSource:t,selectedSubscribe:()=>e,source:t,value:S,valueEqualityFn:u,valueSelector:o,valueSnapshot:S};return c.selectedSubscribe=f(c,t),c}(t,u,c,i,s),a.current=r),function(e,t,r,n,o,u){e.source===t&&e.getStoreSnapshot===r||(e.latestSnapshot=S),e.source=t,e.getStoreSnapshot=r,e.getServerStoreSnapshot=n,e.selector=o,e.equalityFn=u,e.selectedSource!==t&&(e.selectedSource=t,e.selectedSubscribe=f(e,t))}(r,t,u,c,i,s),l=r.selectedSubscribe,p=r.getSelectedSnapshot,y=void 0===c?void 0:r.getSelectedServerSnapshot}const v=n(l,p,y);return o(v),v}(t.subscribe,u,c,s,a??i)},t)}function v(e,t){const r=u(e,t);return y(r,r.getState,r.getInitialState,Object.is)}function g(e,t=Object.is){const r=c(e,t);return y(r,r.getSnapshot)}function h(e,t,r){const n=i(e,t,r);return y(n,n.getState,n.getInitialState,Object.is)}function q(e){return s(e)}function F(e){return a(e)}function j(e,t,r){const n=l(e,t,r);return y(n,n.getState,n.getInitialState)}var E=Symbol(),A=Object.freeze({debugMode:!1,enabled:!0,equalityFn:Object.is,fireImmediately:!1});function O(e,n,o,u=A){const c=function(){const e=r(E);return e.current===E&&(e.current=function(e,t,r){return{selector:e,react:t,isActive:!1,options:L(r),resubscribe:()=>{},unsubscribe:()=>{}}}(n,o,u)),e}(),i=function(e){return"function"==typeof e?A.enabled:e?.enabled??A.enabled}(u);return c.current.react=o,c.current.selector=n,function(e,t){"function"==typeof t?e.current.options.equalityFn=t:t&&(e.current.options=t??A)}(c,u),t(()=>{if(i)return I(e,c),()=>function(e){e.current.options.debugMode&&console.log("[🗑️ useListen 🗑️] Detaching listener"),e.current.resubscribe=()=>{},e.current.unsubscribe(),e.current.unsubscribe=()=>{},e.current.isActive=!1}(c)},[i,e]),c}var V=Object.freeze({fireImmediately:!1,forceResubscribe:!1});function I(e,t,r=V){if(t.current.isActive){if(!r?.forceResubscribe)return;t.current.unsubscribe()}t.current.options.debugMode&&console.log("[📡 useListen 📡] Attaching listener"),t.current.isActive=!0,t.current.resubscribe=(r=V)=>I(e,t,r);const n=e.subscribe(e=>t.current.selector(e),(e,r)=>t.current.react(e,r,()=>{n(),t.current.isActive=!1}),r.fireImmediately?{...t.current.options,fireImmediately:!0}:t.current.options);t.current.unsubscribe=()=>{t.current.isActive&&(n(),t.current.isActive=!1)}}function L(e){return"function"==typeof e?{equalityFn:e}:e??A}var Q=Symbol();function R(e){const t=r(Q);return t.current===Q&&(t.current=e()),t.current}export{v as createBaseStore,g as createDerivedStore,h as createQueryStore,j as createVirtualStore,q as getQueryKey,F as parseQueryKey,O as useListen,R as useStableValue};
1
+ export{getQueryKey,parseQueryKey,queryParam}from"./chunk-PLDNKWGX.mjs";import{noop as e}from"./chunk-FPYZVFBM.mjs";import{useLayoutEffect as t,useRef as r,useSyncExternalStore as n,useDebugValue as o}from"react";import{baseStore as u,derivedStore as c,queryStore as i,virtualStore as s}from"./internal/runtime.mjs";export{QueryStatuses,StoresError,applyStateUpdate,configureStores,createStoreActions,deepEqual,defaultRetryDelay,destroyStore,destroyStores,getStoreName,hasGetSnapshot,identity,isDerivedStore,isPersistedStore,isQueryStore,isVirtualStore,nullObject,replacer,reviver,shallowEqual,time}from"./internal/runtime.mjs";var a=Symbol("empty selection"),l=Object.is;function S(e,t){return r=>(function(e){e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedSource=e.source,e.committedValue=e.value===a?m(e):e.value}(e),t(n=>{e.latestSnapshot=n,e.latestSource=t;const o=e.committedValue;if(o===a||e.committedSource!==t)return void r();const u=e.committedSelector,c=e.committedEqualityFn;if(e.selector===u&&e.equalityFn===c){const t=u(n);if(c===l?l(o,t):c(o,t))return;return e.committedValue=t,e.value=t,e.valueEqualityFn=c,e.valueSelector=u,e.valueSnapshot=n,void r()}if(e.source!==t)return void r();const i=e.value;if(i===a)return;const s=e.selector(n),S=e.equalityFn(i,s);e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedValue=d(e,n,S?i:s),S||r()}))}function m(e){const t=function(e){if(e.latestSource===e.source&&e.latestSnapshot!==a)return e.latestSnapshot;const t=e.getStoreSnapshot();return e.latestSnapshot=t,e.latestSource=e.source,t}(e);return f(e,t)}function f(e,t){const r=e.value;if(r!==a&&l(e.valueSnapshot,t)&&e.valueSelector===e.selector&&e.valueEqualityFn===e.equalityFn)return r;const n=e.selector(t);if(r!==a&&(e.equalityFn===l?l(r,n):e.equalityFn(r,n)))return d(e,t,r);const o=e.committedValue;return o!==a&&o!==r&&e.committedSource===e.source&&(e.equalityFn===l?l(o,n):e.equalityFn(o,n))?d(e,t,o):d(e,t,n)}function d(e,t,r){return e.value=r,e.valueEqualityFn=e.equalityFn,e.valueSelector=e.selector,e.valueSnapshot=t,r}function b(t,u,c,i){return Object.assign(function(s,d){return function(t,u,c,i,s=l){const d=r(null);let b=t,p=u,y=c;if(i){let r=d.current;null===r&&(r=function(t,r,n,o,u){const c={committedEqualityFn:u,committedSelector:o,committedSource:t,committedValue:a,equalityFn:u,getSelectedServerSnapshot:()=>function(e){return f(e,(e.getServerStoreSnapshot??e.getStoreSnapshot)())}(c),getSelectedSnapshot:()=>m(c),getServerStoreSnapshot:n,getStoreSnapshot:r,latestSnapshot:a,latestSource:a,selector:o,selectedSource:t,selectedSubscribe:()=>e,source:t,value:a,valueEqualityFn:u,valueSelector:o,valueSnapshot:a};return c.selectedSubscribe=S(c,t),c}(t,u,c,i,s),d.current=r),function(e,t,r,n,o,u){e.source===t&&e.getStoreSnapshot===r||(e.latestSnapshot=a),e.source=t,e.getStoreSnapshot=r,e.getServerStoreSnapshot=n,e.selector=o,e.equalityFn=u,e.selectedSource!==t&&(e.selectedSource=t,e.selectedSubscribe=S(e,t))}(r,t,u,c,i,s),b=r.selectedSubscribe,p=r.getSelectedSnapshot,y=void 0===c?void 0:r.getSelectedServerSnapshot}const v=n(b,p,y);return o(v),v}(t.subscribe,u,c,s,d??i)},t)}function p(e,t){const r=u(e,t);return b(r,r.getState,r.getInitialState,Object.is)}function y(e,t=Object.is){const r=c(e,t);return b(r,r.getSnapshot)}function v(e,t,r){const n=i(e,t,r);return b(n,n.getState,n.getInitialState,Object.is)}function g(e,t,r){const n=s(e,t,r);return b(n,n.getState,n.getInitialState)}var h=Symbol(),q=Object.freeze({debugMode:!1,enabled:!0,equalityFn:Object.is,fireImmediately:!1});function F(n,o,u,c=q){const i=function(){const t=r(h);return t.current===h&&(t.current=function(t,r,n){return{selector:t,react:r,isActive:!1,options:A(n),resubscribe:e,unsubscribe:e}}(o,u,c)),t}(),s=function(e){return"function"==typeof e?q.enabled:e?.enabled??q.enabled}(c);return i.current.react=u,i.current.selector=o,function(e,t){"function"==typeof t?e.current.options.equalityFn=t:t&&(e.current.options=t??q)}(i,c),t(()=>{if(s)return E(n,i),()=>function(t){t.current.options.debugMode&&console.log("[🗑️ useListen 🗑️] Detaching listener"),t.current.resubscribe=e,t.current.unsubscribe(),t.current.unsubscribe=e,t.current.isActive=!1}(i)},[s,n]),i}var j=Object.freeze({fireImmediately:!1,forceResubscribe:!1});function E(e,t,r=j){if(t.current.isActive){if(!r?.forceResubscribe)return;t.current.unsubscribe()}t.current.options.debugMode&&console.log("[📡 useListen 📡] Attaching listener"),t.current.isActive=!0,t.current.resubscribe=(r=j)=>E(e,t,r);const n=e.subscribe(e=>t.current.selector(e),(e,r)=>t.current.react(e,r,()=>{n(),t.current.isActive=!1}),r.fireImmediately?{...t.current.options,fireImmediately:!0}:t.current.options);t.current.unsubscribe=()=>{t.current.isActive&&(n(),t.current.isActive=!1)}}function A(e){return"function"==typeof e?{equalityFn:e}:e??q}var O=Symbol();function V(e){const t=r(O);return t.current===O&&(t.current=e()),t.current}export{p as createBaseStore,y as createDerivedStore,v as createQueryStore,g as createVirtualStore,F as useListen,V as useStableValue};
@@ -1 +1 @@
1
- var e="undefined"!=typeof window&&"undefined"!=typeof document,t="development"===process.env.NODE_ENV,n="test"===process.env.NODE_ENV;function r(){return"undefined"!=typeof window?window.localStorage:null}function o(e){exports.logger=e}exports.logger={debug:(e,n)=>{t&&console.debug(e,n)},error:(e,r)=>{t&&!n&&console.error(e,r)},info:(e,n)=>{t&&console.info(e,n)},warn:(e,n)=>{t&&console.warn(e,n)}};var s=Object.prototype.hasOwnProperty;function i(e,t){return s.call(e,t)}function a(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}function c(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}var u=Object.freeze(Object.create(null));function l(e){return e}function f(){return Object.create(u)}function d(){}var y=class extends Error{constructor(e,t){super(e),this.name="StoresError",void 0!==t&&Object.defineProperty(this,"cause",{configurable:!0,value:t,writable:!0})}};function p(e){return e instanceof Error?e:new Error(String(e))}var g,h="stores/core/sync-channel",b=`${h}:storage:`,m=class{constructor(e){this.broadcast=e.broadcast,this.origin=e.origin,this.storeKey=e.storeKey,this.teardown=e.teardown}destroy(){this.teardown()}publish(e){const t=f();for(const n of Object.entries(e.values))t[n[0]]=n[1];const n={origin:this.origin,replace:e.replace,sessionId:e.sessionId,storeKey:this.storeKey,timestamp:e.timestamp,values:t};this.broadcast(n)}},S=class{constructor(){this.listeners=new Map,this.origin="undefined"!=typeof crypto&&"randomUUID"in crypto?crypto.randomUUID():`${Math.random().toString(36).slice(2)}:${Date.now().toString(36)}`,this.onChannelMessage=e=>{e.data&&this.dispatch(e.data)},this.onStorageEvent=e=>{if(e.key&&e.newValue&&e.key.startsWith(b))try{const t=JSON.parse(e.newValue);this.dispatch(t)}catch(e){exports.logger.error(new y("[sync] Failed to parse storage event payload",e))}},this.channel="undefined"==typeof BroadcastChannel?null:new BroadcastChannel(h),this.storage=v(),this.channel&&this.channel.addEventListener("message",this.onChannelMessage),e&&window.addEventListener("storage",this.onStorageEvent)}get sessionId(){return this.origin}register(e){const t=t=>{if(t.origin===this.origin||t.storeKey!==e.key)return;const n=f();for(const r of e.fields)i(t.values,r)&&(n[r]=t.values[r]);Object.keys(n).length&&e.apply({replace:t.replace,sessionId:t.sessionId,timestamp:t.timestamp,values:n})};let n=this.listeners.get(e.key);return n||(n=new Set,this.listeners.set(e.key,n)),n.add(t),new m({broadcast:e=>this.broadcast(e),origin:this.origin,storeKey:e.key,teardown:()=>this.removeListener(e.key,t)})}broadcast(e){try{this.channel&&this.channel.postMessage(e),this.writeToStorage(e)}catch(e){exports.logger.error(new y("[sync] Failed to broadcast update",e))}}dispatch(e){if(!e.storeKey)return;const t=this.listeners.get(e.storeKey);if(t&&t.size)for(const n of t)n(e)}removeListener(e,t){const n=this.listeners.get(e);n&&(n.delete(t),n.size||this.listeners.delete(e))}writeToStorage(e){if(this.storage||(this.storage=v()),!this.storage)return;const t=`${b}${e.storeKey}`;try{this.storage.setItem(t,JSON.stringify(e))}catch(e){exports.logger.error(new y("[sync] Failed to write broadcast payload to storage",e))}}};function v(){try{return"undefined"!=typeof window?window.localStorage:null}catch{return null}}var w,O,j,I=class{destroy(){}publish(){}},x=class{constructor(){this.sessionId="noop"}register(e){return new I}},F="stores:",q=!1;function C(){if(O)return O}function k(){return j??(j=A(void 0))}function T(){q=!0}function A(t){return{storage:t?.storage??(n=t?.storageKeyPrefix??F,{clearAll(){try{const e=r();if(!e)return;const t=[];for(let r=0;r<e.length;r++){const o=e.key(r);o?.startsWith(n)&&t.push(o)}for(const n of t)e.removeItem(n)}catch(e){console.error("Error clearing localStorage:",e)}},contains(e){const t=r();return null!==t?.getItem(`${n}${e}`)},delete(e){try{const t=r();t?.removeItem(`${n}${e}`)}catch(e){console.error("Error deleting from localStorage:",e)}},getAllKeys(){try{const e=r();return e?Array.from(e.keys()):[]}catch(e){return console.error("Error getting keys from localStorage:",e),[]}},get(e){try{const t=r();return t?t.getItem(`${n}${e}`)??void 0:void 0}catch(e){return void console.error("Error reading from localStorage:",e)}},set(e,t){try{const o=r();o?.setItem(`${n}${e}`,t)}catch(e){console.error("Error writing to localStorage:",e)}}}),syncEngine:t?.syncEngine??(e?(g||(g=new S),g):(w||(w=new x),w))};var n}var E,D={Error:"error",Idle:"idle",Loading:"loading",Success:"success"},z={ms:e=>e,seconds:e=>1e3*e,minutes:e=>6e4*e,hours:e=>36e5*e,days:e=>864e5*e,weeks:e=>6048e5*e,infinity:1/0,zero:0};function M(e,t){const n=t?.baseDelay??z.seconds(5),r=t?.maxDelay??z.minutes(5);return Math.min(n*Math.pow(2,e),r)}function K(e){return JSON.stringify($(e))}function $(e){return"object"!=typeof e||null===e?e:Object.keys(e).sort().reduce((t,n)=>{const r=e[n];return t[n]=a(r)?$(r):r,t},f())}function P(e,t){return!0===t[1]?e(t[0],!0):e(t[0])}function R(e,t,n){if(!0===n)return L(t)?t(e):t;const r=L(t)?t(e):t;return Object.is(r,e)?e:c(e)&&c(r)?{...e,...r}:r}function L(e){return"function"==typeof e}function N(e,t){return t instanceof Map?{__type:"Map",entries:Array.from(t.entries())}:t instanceof Set?{__type:"Set",values:Array.from(t)}:t}function W(e,t){return function(e){return"object"==typeof e&&null!==e&&"__type"in e&&"Map"===e.__type}(t)?new Map(t.entries):function(e){return"object"==typeof e&&null!==e&&"__type"in e&&"Set"===e.__type}(t)?new Set(t.values):t}var H=Object.freeze({QueryStore:Symbol("queryStore"),VirtualStore:Symbol("virtualStore")});function U(e,t){return Object.assign(e,{[t]:!0})}function _(e,t){B(e)?e.getState().reset(t?.clearQueryCache):V(e)&&e.destroy()}function V(e){return"destroy"in e}function J(e){return"getSnapshot"in e}function B(e){return H.QueryStore in e}function Q(e){return!(!("persist"in e)||!e.persist)&&"string"==typeof e.persist.getOptions().name}function G(e){return H.VirtualStore in e}function X(e,t){return function(...n){const r=e.getState()[t];if("function"==typeof r)return r(...n);throw new Error(`[createVirtualStoreAction]: Method ${String(t)} is not a function`)}}function Y(e,t){return"function"==typeof e[t]}function Z(e,t){const n=Object.prototype.hasOwnProperty;function r(e,t){for(const n of e.keys())if(Z(n,t))return n}let o,s,i;if(e===t)return!0;if(e&&t&&(o=e.constructor)===t.constructor){if(o===Date)return e.getTime()===t.getTime();if(o===RegExp)return e.toString()===t.toString();if(o===Array){if((s=e.length)===t.length)for(;s--&&Z(e[s],t[s]););return-1===s}if(o===Set){if(e.size!==t.size)return!1;for(let n of e){if(i=n,i&&"object"==typeof i&&(i=r(t,i),!i))return!1;if(!t.has(i))return!1}return!0}if(o===Map){if(e.size!==t.size)return!1;for(let n of e){if(i=n[0],i&&"object"==typeof i&&(i=r(t,i),!i))return!1;if(!Z(n[1],t.get(i)))return!1}return!0}if(o===ArrayBuffer)e=new Uint8Array(e),t=new Uint8Array(t);else if(o===DataView){if((s=e.byteLength)===t.byteLength)for(;s--&&e.getInt8(s)===t.getInt8(s););return-1===s}if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(t)){const n=e,r=t;if((s=n.byteLength)===r.byteLength)for(;s--&&n[s]===r[s];);return-1===s}if(!o||"object"==typeof e){s=0;for(const r in e){if(n.call(e,r)&&++s&&!n.call(t,r))return!1;if(!(r in t)||!Z(e[r],t[r]))return!1}return Object.keys(t).length===s}}return e!=e&&t!=t}function ee(e){let t;const n=new Set;function r(...e){const r=R(t,...e);if(Object.is(r,t))return;const o=t;t=r,n.forEach(e=>e(t,o))}function o(){return t}const s={getInitialState:function(){return i},getState:o,setState:r,subscribe:function(...e){return 1===e.length?a(e[0]):function(e,n,r){const o=r?.equalityFn??Object.is;let s=e(t);return r?.fireImmediately&&n(s,s),a(function(t){const r=e(t);if(o(s,r))return;const i=s;s=r,n(r,i)})}(e[0],e[1],e[2])}},i=t=e(r,o,s);return s;function a(e){return n.add(e),()=>{n.delete(e)}}}function te(e){return!!e&&"object"==typeof e&&"then"in e&&"function"==typeof e.then}function ne(e){return{...e,merge:e.merge??re,skipHydration:e.skipHydration??!1}}function re(e,t){return void 0===e?t:{...t,...e}}function oe(){let e,t,n=!1;return{complete:function(){!n&&e&&(n=!0,e(),e=void 0,t=void 0)},isHydrated:function(){return n},fail:function(r){!n&&t&&(n=!0,t(r),t=void 0,e=void 0)},promise:new Promise((n,r)=>{e=n,t=r})}}var se=Math.max,ie=Math.min;function ae(e,t=0,n={}){let r,o,s,i,a,c,u=0,l=!1,f=!1,d=!0;if("function"!=typeof e)throw new TypeError("Expected a function");function y(t){const n=r,s=o;return r=o=void 0,u=t,i=n?e.apply(s,n):e.apply(s),i}function p(e){const n=e-(c??0);return void 0===c||n>=t||n<0||f&&void 0!==s&&e-u>=s}function g(){const e=ce();if(p(e))return h(e);a=setTimeout(g,function(e){const n=t-(e-(c??0));return f&&void 0!==s?ie(n,s-(e-u)):n}(e))}function h(e){return a=void 0,d&&r?y(e):(r=o=void 0,i)}function b(...e){const n=ce(),s=p(n);if(r=e,o=this,c=n,s){if(void 0===a)return function(e){return u=e,a=setTimeout(g,t),l?y(e):i}(c);if(f)return clearTimeout(a),a=setTimeout(g,t),y(c)}return void 0===a&&(a=setTimeout(g,t)),i}return t=ue(t)||0,function(e){const t=typeof e;return null!==e&&("object"===t||"function"===t)}(n)&&(l=!!n.leading,f="maxWait"in n,s=f?se(ue(n.maxWait)||0,t):void 0,d="trailing"in n?!!n.trailing:d),b.cancel=function(){void 0!==a&&clearTimeout(a),u=0,r=c=o=a=void 0},b.flush=function(){return void 0===a?i:h(ce())},b}function ce(){return"undefined"!=typeof performance&&"function"==typeof performance.now?performance.now():Date.now()}function ue(e){if("number"==typeof e)return e;if("symbol"==typeof e||void 0===e)return NaN;if("object"==typeof e&&null!==e){const t="function"==typeof e.valueOf?e.valueOf():e;e="object"==typeof t?t+"":t}return"string"!=typeof e?0===e?e:+e:(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)}function le(e){if(!a(e))return e;const t=f(),n=Object.keys(e);for(let r=0;r<n.length;r++){const o=n[r],s=e[o];"function"!=typeof s&&(t[o]=s)}return t}var fe=n?0:e?z.ms(200):z.seconds(5);function de(e,t,n,r){const o=!(t.deserializer||t.serializer||e.deserializer||e.serializer),s="object"==typeof t.sync&&!0===(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata),i=t.partialize??le,a=t.deserializer??e.deserializer??pe(o),c=t.serializer??e.serializer??ge(o);function u(t,n,o){try{if(Se(r))return;const a={state:i(n),version:o},u=be(r,s,a),l=c(a);try{e.set(t,l),me(r,u)}catch(e){exports.logger.error(new y("[createBaseStore]: Failed to persist store data",e))}}catch(e){exports.logger.error(new y("[createBaseStore]: Failed to persist store data",e))}}const l=void 0!==n?ae(u,n,{leading:!1,maxWait:n,trailing:!0}):u;return{getItem:t=>{const n=e.get(t);return void 0===n?null:a(n)},setItem:(e,t,n)=>{r?.getIsApplyingRemote()||l(e,t,n)},removeItem:t=>{try{e.delete(t)}catch(e){exports.logger.error(new y("[createBaseStore]: Failed to delete persisted store data",e))}}}}function ye(e,t,n,r){const o=!(t.deserializer||t.serializer||e.deserializer||e.serializer),s="object"==typeof t.sync&&!0===(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata),i=t.partialize??le,a=t.deserializer??e.deserializer??pe(o),c=t.serializer??e.serializer??ge(o);async function u(t,n,o){try{if(Se(r))return;const a={state:i(n),version:o},u=be(r,s,a),l=c(a);try{await e.set(t,l),me(r,u)}catch(e){exports.logger.error(new y("[createBaseStore]: Failed to persist store data",e))}}catch(e){exports.logger.error(new y("[createBaseStore]: Failed to serialize persisted store data",e))}}const l=void 0!==n?ae(u,n,{leading:!1,maxWait:n,trailing:!0}):function(e){let t,n=null;return function(...r){return t=r,n||(n=new Promise(r=>{queueMicrotask(async()=>{try{await e(...t)}finally{n=null,r()}})})),n}}(u);return{getItem:async t=>{const n=await e.get(t);return void 0===n?null:a(n)},setItem:async(e,t,n)=>{if(!r?.getIsApplyingRemote())return await l(e,t,n)},removeItem:async t=>{try{await e.delete(t)}catch(e){exports.logger.error(new y("[createBaseStore]: Failed to delete persisted store data",e))}}}}function pe(e){return t=>{if("string"!=typeof t)throw new y("[createBaseStore]: Received non-string serialized state without a custom deserializer. Provide a deserializer on the store or storage adapter.");return function(e,t){try{return JSON.parse(e,t?W:void 0)}catch(e){throw exports.logger.error(new y("[createBaseStore]: Failed to deserialize persisted store data",e)),e}}(t,e)}}function ge(e){return t=>function(e,t){try{return JSON.stringify(e,t?N:void 0)}catch(e){throw exports.logger.error(new y("[createBaseStore]: Failed to serialize store data",e)),e}}(t,e)}var he=Object.freeze({shouldClear:!1});function be(e,t,n){if(!t||!e)return he;const r=e.getFieldTimestampSnapshot();return function(e,t){const n=e.getSessionId(),r=e.getTimestamp();void 0!==n&&void 0!==r&&(t.syncMetadata={origin:n,timestamp:r})}(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 me(e,t){e&&t.shouldClear&&t.fieldSnapshot&&Object.keys(t.fieldSnapshot).length&&e.clearFieldTimestamps(t.fieldSnapshot)}function Se(e){return!!e&&!!e.getIsApplyingRemote()}var[ve,we]=[0,1];function Oe(e,t,n){if(!e)return!0;const r=e[ve],o=e[we];return!(t<r)&&(t>r||n>o)}function je(e,t){return Object.prototype.hasOwnProperty.call(t,e)}function Ie(e,n){if(!t)return!0;if(null===e||null===n)return e===n;const r=typeof e;return r===typeof n&&("object"!==r||Object.prototype.toString.call(e)===Object.prototype.toString.call(n))}function xe(e){if(null===e)return"null";const t=typeof e;return"object"===t?Object.prototype.toString.call(e):t}function Fe(e,t){if(T(),!t)return ee(e);const n=t.storageKey,r="string"==typeof n,o=r?t.storage??k().storage:void 0,s=function(e,t){if(!e)return null;const n="object"==typeof e,r=n?e.key??t:!0===e?t:e;if(!r)throw new y("[createBaseStore]: sync requires a key to be specified either directly or via storageKey");return n?{...e,key:r}:{key:r}}(t.sync,n),i=s?function(e,t,n){const r=t.engine??k().syncEngine,o=function(e){let t,n,r,o=!1;return{isAsync:e,clearFieldTimestamps:function(e){if(e&&r){for(const t of Object.entries(e)){const e=t[0],n=t[1];r[e]===n&&delete r[e]}Object.keys(r).length||(r=void 0)}},getFieldTimestampSnapshot:function(){if(r)return{...r}},getIsApplyingRemote:()=>o,getSessionId:()=>t,getTimestamp:()=>n,mergeFieldTimestamps:function(e){if(r)for(const t of Object.entries(e)){const e=t[0],n=t[1],o=r[e];(void 0===o||n>o)&&(r[e]=n)}else r={...e}},onHydrationComplete:void 0,onHydrationFlushEnd:void 0,setIsApplyingRemote:e=>o=e,setSessionId:e=>t=e,setTimestamp:e=>n=e,setWithoutPersist:void 0}}(n);return{stateCreator:(s,i,a)=>{const c=new Map,u=[],l=[];let d=null,p=!1,g=!1,h=0,b=null,m=[],S=Promise.resolve(),v=!n;function w(e,t){if(o?.setSessionId&&o?.setTimestamp&&r.sessionId&&(o.setSessionId(r.sessionId),o.setTimestamp(e),o.mergeFieldTimestamps&&t.length>0)){const n=f();for(const r of t)n[String(r)]=e;o.mergeFieldTimestamps(n)}}function O(e,t){if(p||!b)return t?s(e,t):s(e);const n=function(){const e=Date.now(),t=e>h?e:h+1;return h=t,t}();let o=[],i=f();const a=r=>{const s=R(r,e,t);for(const e of m)Object.is(s[e],r[e])||(o.push(e),i[e]=s[e]);return o.length&&w(n,o),s},u=t?s(a,!0):s(a);function y(){o.length&&function(e){const t=r.sessionId;for(const n of e.keys)c.set(n,[e.timestamp,t]);d&&g?d.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values}):l.push(e)}({keys:o,replace:t??!1,values:i,timestamp:n})}return te(u)?u.finally(y):(y(),u)}const j=a.setState;a.setState=O;const I=e(O,i,a);if(m=t.fields??function(e){const t=[];for(const n of Object.entries(e)){if("function"==typeof n[1])continue;const e=n[0];t.push(e)}return t}(I),!m.length)return I;async function x(e){h=Math.max(h,e.timestamp);const n=f(),r=i(),s=e.timestamp;let a;if(e.replace)for(const t of m)je(t,e.values)||Oe(c.get(t),s,e.sessionId)&&(a??(a=[])).push(t);for(const o of m){if(!je(o,e.values))continue;if(!b?.has(o))continue;if(!Oe(c.get(o),s,e.sessionId))continue;const i=t.merge?.[o];if(i){const t=e.values[o],a=r[o];if(void 0!==t){const u=i(t,a,r,e.values),l=void 0!==a?a:t;if(!Ie(u,l))return void exports.logger.error(new y(`[sync] Merge function for field "${String(o)}" returned ${xe(u)} but expected ${xe(l)}`));n[o]=u,c.set(o,[s,e.sessionId])}}else n[o]=e.values[o],c.set(o,[s,e.sessionId])}if(Object.keys(n).length>0||a?.length){p=!0,o&&o.setIsApplyingRemote(!0);try{if(e.replace){const e={...r};let t=!1;if(a?.length){t=!0;for(const t of a)delete e[t],c.delete(t)}for(const r in n){if(!Object.prototype.hasOwnProperty.call(n,r))continue;const o=n[r];void 0!==o&&(Object.is(e[r],o)||(t=!0),e[r]=o)}if(!t)return;await(o.setWithoutPersist??j)(e,!0)}else await(o.setWithoutPersist??j)(n)}finally{p=!1,o&&o.setIsApplyingRemote(!1)}}}function F(e){n?S=S.then(()=>x(e)):x(e)}if(b=new Set(m),d=r.register({apply:e=>{v?F(e):u.push(e)},fields:m,getState:i,key:t.key}),d?.onFirstSubscribe||d?.onLastUnsubscribe){let e=0;const t=a.subscribe;a.subscribe=(...n)=>{e||d.onFirstSubscribe?.(),e+=1;const r=1===n.length?t(n[0]):t(n[0],n[1],n[2]);return()=>{r(),e-=1,e||queueMicrotask(()=>{e||d.onLastUnsubscribe?.()})}}}function q(){g=!0,function(){if(d&&l.length){for(const e of l){const t=r.sessionId;for(const n of e.keys)c.set(n,[e.timestamp,t]);w(e.timestamp,e.keys),d.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values})}l.length=0}}()}function C(){v=!0,function(){if(!u.length)return;const e=u.slice();u.length=0;for(const t of e)F(t)}()}return n?(o.onHydrationComplete=q,o.onHydrationFlushEnd=C):d.onHydrated?(d.onHydrated(q),C()):(q(),C()),I},syncContext:o}}(e,s,o?.async??!1):void 0,a=i?.stateCreator??e;if(!r)return ee(a);const c=function(e,t,n){const r=t??e.storage??k().storage,o=(e.sync?void 0:e.persistThrottleMs??fe)||void 0,s=e.version??0;return r.async?{async:!0,persistStorage:ye(r,e,o,n),version:s}:{async:!1,persistStorage:de(r,e,o,n),version:s}}(t,o,i?.syncContext),u=c.async?function(e){let t,n,r,o=!1;return{hydrationPromise:()=>o?t?.promise??n??(n=Promise.resolve()):(t||(t=oe()),t.promise),stateCreator:(n,s,i)=>{let a;return r=()=>{if(a?.length){for(const e of a)P(i.setState,e);a=void 0}},e(function(...e){return o?P(n,e):(t||(t=oe()),a||(a=[]),a.push(e),t.promise)},s,i)},wrapOnRehydrateStorage:(e,n)=>s=>{const i=e?.(s);return(e,s)=>{o=!0,n?.onHydrationComplete?.(),r&&r(),n?.onHydrationFlushEnd?.(),s?t?.fail(p(s)):t?.complete(),i?.(e,s)}}}}(a):void 0,l=u?u.wrapOnRehydrateStorage(t.onRehydrateStorage,i?.syncContext):t.onRehydrateStorage,d=ee(function(e,t){return(n,r,o)=>{let s,i,a,c=ne(t),u=!1,l=0;function f(){return c.storage.setItem(c.name,r(),c.version)}const d=o.setState;o.setState=function(...e){return P(d,e),f()};const y=e(function(...e){return P(n,e),f()},r,o);function p(){const e=function(){const e=++l;return u=!1,i?.forEach(e=>e(r()??y)),e}(),t=c.onRehydrateStorage?.(r()??y);try{const n=c.storage.getItem(c.name);return te(n)?n.then(n=>g(e,n,t)).catch(n=>m(e,t,n)):g(e,n,t)}catch(n){m(e,t,n)}}return o.getInitialState=()=>y,Object.assign(o,{persist:{clearStorage:()=>{c.storage.removeItem(c.name)},getOptions:()=>c,hasHydrated:()=>u,onFinishHydration:e=>(a??(a=new Set),a.add(e),()=>{a?.delete(e),0===a?.size&&(a=void 0)}),onHydrate:e=>(i??(i=new Set),i.add(e),()=>{i?.delete(e),0===i?.size&&(i=void 0)}),rehydrate:p,setOptions:e=>{c=ne({...c,...e,storage:e.storage??c.storage})}}}),c.skipHydration||p(),s??y;function g(e,t,n){const r=function(e,t){if(!t)return{migrated:!1,state:void 0};if("number"!=typeof t.version||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"),{migrated:!1,state:void 0};const n=e.migrate(t.state,t.version);return te(n)?n.then(e=>({migrated:!0,state:e})):{migrated:!0,state:n}}(c,t);return te(r)?r.then(t=>h(e,t,n)).catch(t=>m(e,n,t)):h(e,r,n)}function h(e,t,o){const i=function(e,t){if(e!==l)return;const o=c.merge(t.state,r()??y);return s=o,n(o,!0),t.migrated?f():void 0}(e,t);if(te(i))return i.then(()=>b(e,o));b(e,o)}function b(e,t){if(e!==l)return;t?.(s,void 0);const n=r();s=n,u=!0,a?.forEach(e=>e(n))}function m(e,t,n){e===l&&t?.(void 0,n)}}}(u?(e,t,n)=>(i&&(i.syncContext.setWithoutPersist=n.setState),u.stateCreator(e,t,n)):a,{merge:t.merge,migrate:t.migrate,name:n,onRehydrateStorage:l,storage:c.persistStorage,version:c.version}));return u?Object.assign(d,{persist:Object.assign(d.persist,{hydrationPromise:u.hydrationPromise})}):d}function qe(e,t,n="s"){return 1===t?e:`${e}${n}`}var Ce=!1,ke=!1,Te=new Map,Ae=new Map,Ee=new Map,De=null,ze=1/0;function Me(){return Ce}function Ke(){return De}function $e(){Ce||(Ce=!0,ke||(ke=!0,queueMicrotask(()=>{ke=!1,(()=>{for(;Ae.size>0;){const e=ze,t=Ee.get(e);if(t){Ee.delete(e);for(const e of t)Ae.delete(e);De=e;for(const e of t)e();if(De=null,Ee.size>0){ze=1/0;for(const e of Ee.keys())e<ze&&(ze=e)}else ze=1/0}else{ze=1/0;for(const e of Ee.keys())e<ze&&(ze=e)}}for(;Te.size>0;){const e=Array.from(Te.values());Te.clear();for(const t of e)t()}})(),Ce=!1,De=null,Ae.clear(),Ee.clear(),ze=1/0})))}function Pe(e,t){Ce&&Te.set(e,t)}var Re=Symbol("stores.deriveProxy.unwrap");function Le(e,t,n){const r=t.get(e);if(void 0!==r)return r;const o=function(e,t,n,r=[]){return e&&"object"==typeof e?Ne(e,r,t,n,new WeakSet,new WeakMap):(n(t,r,!0),e)}(J(e)?e.getSnapshot():e.getState(),e,n);return t.set(e,o),o}function Ne(e,t,n,r,o,s){return new Proxy(e,{get(i,a,c){if(a===Re)return r(n,t,!0),i;if(o.has(i))return Reflect.get(i,a,c);if("__proto__"===a||"symbol"==typeof a)return a===Symbol.iterator&&(r(n,t,!0),o.add(i)),Reflect.get(i,a,c);const u=Reflect.get(i,a,i),l=String(a),f=t.concat(l);if("function"==typeof u)return Object.prototype.hasOwnProperty.call(i,a)?function(...e){return r(n,f,!0,{args:e.length?e:void 0}),Reflect.apply(u,i,e)}:(r(n,t,!0),u.bind(e));const d=!!u&&"object"==typeof u;return r(n,f,!d),d?(s.has(u)||s.set(u,Ne(u,f,n,r,o,s)),s.get(u)):u},getOwnPropertyDescriptor:(e,s)=>(r(n,t,!0),o.add(e),Reflect.getOwnPropertyDescriptor(e,s)),has:(e,o)=>(r(n,t,!0),Reflect.has(e,o)),ownKeys:e=>(r(n,t,!0),o.add(e),Reflect.ownKeys(e))})}function We(e,t){if(!e||"object"!=typeof e)return e;const n=function(e){const t=Reflect.get(e,Re);return t&&"object"==typeof t?t:void 0}(e);return n||(Array.isArray(e)?function(e,t){const n=Ue(e,t);if(n)for(let t=0;t<e.length;t++)He(e,String(t),n)}(e,t):a(e)&&function(e,t){const n=Ue(e,t);if(n)for(const t of Reflect.ownKeys(e))He(e,t,n)}(e,t),e)}function He(e,t,n){const r=Reflect.getOwnPropertyDescriptor(e,t);if(!r||!("value"in r))return;const o=We(r.value,n);o!==r.value&&(r.value=o,Reflect.defineProperty(e,t,r))}function Ue(e,t){const n=t??new WeakSet;return n.has(e)?null:(n.add(e),n)}var _e=Object.freeze([]);function Ve(){const e=new Map;return{buildProxySubscriptions(t,n,r,o){const s=new Set;for(const t of e)Qe(t[1],t[0],[],0,s,r);!1!==o?.(s)&&function(e,t,n){for(const n of e){const e=n.invocation?Ze(n.path,n.invocation):Ye(n.path);t(n.store,e,n.path)}n&&function(e){const t=e.size;console.log(`[📡 ${t} ${qe("Proxy Subscription",t)} 📡]:`,JSON.stringify(Array.from(e).map(e=>{const t="name"in(n=e.store)&&"string"==typeof n.name?n.name:"store";var n;const r=e.path.join(".");if(!e.invocation)return r?`$(${t}).${r}`:`$(${t})`;const o=e.invocation.args?.length??0;return`$(${t}).${r}${o?`(${o}_${qe("arg",o)})`:"()"}`}),null,2))}(e)}(s,t,n)},reset(){e.clear()},trackPath(t,n,r,o){let s=e.get(t);s||(s=Je(),e.set(t,s)),Be(s,n,0,r,o)}}}function Je(){return f()}function Be(e,t,n,r,o){if(n===t.length)return r&&(e.isLeaf=!0),void(o&&function(e,t){const n=e.invocation;if(!n)return void(e.invocation=t);if(Ge(n,t))return;const r=e.extraInvocations;if(r){for(let e=0;e<r.length;e++)if(Ge(r[e],t))return;r.push(t)}else e.extraInvocations=[t]}(e,o));e.children||(e.children=Je());const s=t[n];let i=e.children?.[s];i||(i=Je(),e.children[s]=i),Be(i,t,n+1,r,o)}function Qe(e,t,n,r,o,s=2){const i=e.children;if(!i)return void Xe(e,t,n,o);const a=Object.keys(i),c=a.length;if(0!==c)if(e.isLeaf||r>=s&&c>1){Xe(e,t,n,o);for(const e of a){const a=i[e];a.invocation&&Qe(a,t,[...n,e],r+1,o,s)}}else if(r<s&&c>1&&!e.isLeaf)for(const e of a)Qe(i[e],t,[...n,e],r+1,o,s);else{if(1===c){const e=a[0];return void Qe(i[e],t,[...n,e],r+1,o,s)}Xe(e,t,n,o)}else Xe(e,t,n,o)}function Ge(e,t){const n=e.args,r=t.args,o=n?.length??0;if(o!==(r?.length??0))return!1;if(!n||!r)return!0;for(let e=0;e<o;e++)if(!Object.is(n[e],r[e]))return!1;return!0}function Xe(e,t,n,r){const o=e.isLeaf??!1,s=e.invocation;if(!s)return void r.add({store:t,path:n,isLeaf:o});r.add({store:t,path:n,invocation:s,isLeaf:o});const i=e.extraInvocations;if(i)for(let e=0;e<i.length;e++)r.add({store:t,path:n,invocation:i[e],isLeaf:o})}function Ye(e){return t=>et(t,e)}function Ze(e,t){const n=e.slice(0,-1),r=e[e.length-1];return e=>{const o=et(e,n),s=o&&"object"==typeof o?Reflect.get(o,r):void 0;return"function"==typeof s?Reflect.apply(s,o,t.args??_e):void 0}}function et(e,t){let n=e;for(const e of t){if(!n||"object"!=typeof n)return n;n=Reflect.get(n,e)}return n}var tt=Symbol(),nt=Object.freeze({equalityFn:Object.is,isDerivedStore:!0});function rt(e,n=Object.is){const{debounceOptions:r,debugMode:o,equalityFn:s,keepAlive:i,lockDependencies:a}="function"==typeof(f=n)?{debounceOptions:void 0,debugMode:!1,equalityFn:f,keepAlive:!1,lockDependencies:!1}:{debounceOptions:f.debounce,debugMode:(t&&f.debugMode)??!1,equalityFn:f.equalityFn??Object.is,keepAlive:f.keepAlive??!1,lockDependencies:f.lockDependencies??!1},c=String(ot+=1),u=new Set;var f;i&&u.add(st);const d=new Set;let y,p,g=tt,h=!1,b=!0,m=!0,S=0,v=!1,w=null,O=tt;function j(e,t,n){return m&&u.size?t?(d.add(e.subscribe(t,z,n?{equalityFn:n,isDerivedStore:!0}:nt)),t(J(e)?e.getSnapshot():e.getState())):(y||(y=new WeakMap),p||(p=Ve()),Le(e,y,p.trackPath)):(t??l)(J(e)?e.getSnapshot():e.getState())}function I(e){for(const t of d)t(e);d.clear()}let x=!0;function F(){if(!b&&it(g))return g;b=!1,m&&I(!0);const t=g,n=it(t);g=function(t){x=!0;const n=g,r=e(t),i=p?We(r):r;return it(n)&&s(n,i)?(o&&console.log("[🥷 Derive Complete 🥷]: No change detected"),x=!1,n):i}(j);const r=o&&(!n||"verbose"===o&&m);if(r){n?"verbose"===o&&console.log("[🌀 Rebuilding Subscriptions 🌀]: Created…"):console.log("[🌀 Initial Derive Complete 🌀]: Created…");const e=d.size;console.log(`[🎯 ${e} ${qe("Selector Subscription",e)} 🎯]`)}return p&&m&&(p.buildProxySubscriptions((e,t)=>{d.add(e.subscribe(t,z,nt))},r),y=void 0,p.reset(),a&&(p=void 0)),x&&n&&function(e,t){const n=function(){const e=u.has(st)?u.size-1:u.size;return S>0&&S<e}(),r=!S||n,s=n||null!==Ke()||Me()&&r;n&&$e(),o&&console.log(`[📻 Derive Complete 📻]: Notifying ${u.size} ${qe("watcher",u.size)}`);for(const t of u){if("function"==typeof t||!t.isDerivedWatcher)continue;const n=t.selector(e);if(!t.equalityFn(t.currentSlice,n)){const e=t.currentSlice;t.currentSlice=n,t.listener(n,e)}}s?v||(v=!0,it(O)||(O=t),Pe(c,C)):q(e,t)}(g,t),a&&(m=!1),g}function q(e,t){for(const n of u)if("function"==typeof n)n(e,t);else if(!n.isDerivedWatcher){const t=n.selector(e);if(!n.equalityFn(n.currentSlice,t)){const e=n.currentSlice;n.currentSlice=t,n.listener(t,e)}}}function C(){if(!u.size)return;if(b&&!S&&F(),!it(g))return;const e=it(O)?O:g;q(g,e),v=!1,O=tt}const k=r?ae(A,"number"==typeof r?r:r.delay,"number"==typeof r?{leading:!1,maxWait:r,trailing:!0}:r):void 0,T=k??(()=>{h||(h=!0,queueMicrotask(A))});function A(){h=!1,u.size?b&&F():K()}function E(e){e||k&&b?queueMicrotask(()=>{u.size||K()}):K()}function D(){A(),w=null}function z(){if(!b){if(b=!0,!k){if(S){$e();const e=Ke(),t=null===e?0:e+1;if(null!==w&&t<=w)return;return w=t,void function(e,t){if(!Ce)return;const n=t<0?0:0|t,r=Ae.get(e);if(void 0===r){Ae.set(e,n);let t=Ee.get(n);return t||(t=new Set,Ee.set(n,t)),t.add(e),void(n<ze&&(ze=n))}if(n>r){const t=Ee.get(r);if(t&&(t.delete(e),0===t.size&&(Ee.delete(r),r===ze))){ze=1/0;for(const e of Ee.keys())e<ze&&(ze=e)}Ae.set(e,n);let o=Ee.get(n);o||(o=new Set,Ee.set(n,o)),o.add(e),n<ze&&(ze=n)}}(D,t)}if(Me())return void(v||(v=!0,it(g)&&(O=g),Pe(c,C)))}w=null,T()}}function M(){return b||!it(g)?u.size>0?F():e(j):g}function K(e=!0){i&&e||(k?.cancel(),I(),u.clear(),S=0,p=void 0,y=void 0,m=!0,h=!1,b=!0,g=tt,v=!1,O=tt,w=null)}return{destroy:()=>K(!1),flushUpdates:function(){u.size&&(k?k.flush():b&&F())},getSnapshot:function(){if(!it(g)){u.add(st);const e=F();return u.delete(st),e}return h&&A(),g},getState:M,subscribe:function(...e){if(1===e.length){const t=e[0];return u.add(t),1!==u.size||it(g)||M(),()=>{u.delete(t),u.size||E(!1)}}const[t,n,r]=e,o=r?.equalityFn??Object.is,s=r?.isDerivedStore??!1,i={currentSlice:void 0,equalityFn:o,isDerivedWatcher:s,listener:n,selector:t};return u.add(i),i.currentSlice=t(M()),s&&(S+=1),r?.fireImmediately&&n(i.currentSlice,i.currentSlice),()=>{u.delete(i),s&&(S-=1),u.size||E(s)}},getInitialState:()=>{throw new Error("[createDerivedStore]: getInitialState() is not available on derived stores.")},setState:()=>{throw new Error("[createDerivedStore]: setState() is not available on derived stores.")}}}var ot=0;function st(){}function it(e){return e!==tt}var at=class{constructor({disableAutoRefetching:e,initialEnabled:t}){this.count=0,this.enabled=!1,this.lastSubscriptionTime=null,this.fetchThrottleMs=null,this.onSubscribe=null,this.onLastUnsubscribe=null,this.enabled=t,e&&(this.fetchThrottleMs=z.seconds(5))}init({onSubscribe:e,onLastUnsubscribe:t}){this.onSubscribe=e,this.onLastUnsubscribe=t}get(){return{enabled:this.enabled,lastSubscriptionTime:this.lastSubscriptionTime,subscriptionCount:this.count}}setEnabled(e){this.enabled=e}subscribe(){const e=0===this.count,t=null!==this.fetchThrottleMs&&null!==this.lastSubscriptionTime&&!e&&Date.now()-this.lastSubscriptionTime<=this.fetchThrottleMs;return this.onSubscribe?.(this.enabled,e,t),this.count+=1,this.lastSubscriptionTime=Date.now(),e=>{const t=1===this.count;this.count=Math.max(this.count-1,0),t&&(this.onLastUnsubscribe?.(e),this.lastSubscriptionTime=null)}}},ct=new WeakMap,ut=new WeakMap;function lt(e,t=ft,n=Z){return function(e,t,n){let r=ut.get(e);r||(r=new Map,ut.set(e,r));let o=r.get(t);o||(o=new Map,r.set(t,o));const s=o.get(n);if(s)return s;const[i,a,c]=yt(e,t,n),u=new Map,l=e=>{const t={get(t,n){if("value"===n){let t=a();const n=e.split(".");for(const e of n)e&&(t=t[e]);return t}const r="string"==typeof n?n:n.toString(),o=e?`${e}.${r}`:r,s=u.get(o);if(s)return s;const c=l(o);return ct.set(c,i),u.set(o,c),c},set(t,n,r){const o=e.split(".");return""===o[0]&&o.shift(),c(o,r),!0}};return new Proxy(f(),t)},d=l("");return i(()=>{}),ct.set(d,i),o.set(n,d),d}(e,t,n)}var ft=e=>e,dt=(e,t,n)=>{if(!t.length)return n;const[r,...o]=t,s=e[r],i=dt(s,o,n);if(Z(s,i))return e;const a=Array.isArray(e)?e.slice():{...e};return a[r]=i,a},yt=(e,t,n)=>{const r=new Set,o=J(e);let s,i=t(o?e.getSnapshot():e.getState());return[a=>(r.size||(s=e.subscribe(t,e=>{i=e,r.forEach(e=>e())},{equalityFn:n,isDerivedStore:o})),r.add(a),()=>{r.delete(a),!r.size&&s&&(s(),s=void 0)}),()=>(r.size||(i=t(e.getState())),i),(n,r)=>{if(t!==ft)throw new Error("Cannot set a value with a selector");e.setState(e=>dt(e,n,r),!0)}]};function pt(e){return ct.get(e)}var gt={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},ht=Object.freeze({force:!0}),bt=Object.freeze({once:!0}),mt=Object.freeze({updateQueryKey:!0});function St(e,t,n,r){return r?wt(r,n)?r:{...vt(e,t),...r}:vt(e,t)}function vt(e,t){const n=Object.assign(f(),t?.params);for(const t in e?.params){const r=e.params[t];r&&(n[t]=r.value)}return n}function wt(e,t){if(!e)return!1;for(const n of t)if(!(n in e))return!1;return!0}function Ot(e){return"function"==typeof e}function jt(e){return!Ot(e)}function It(e,t){return n=>{const r={...n},o=f();for(const e in r)i(r,e)&&e in gt&&(gt[e]&&(o[e]=r[e]),delete r[e]);return{...t?t(r):le(r),...xt(e,null,o)}}}function xt(e,t,n){if(!n.queryCache)return n;const r=Date.now(),o=t??(e&&n.queryKey||null),s=f();let a=!1;for(const e in n.queryCache){if(!i(n.queryCache,e))continue;const c=n.queryCache[e];c&&(r-(c.lastFetchedAt??c.errorInfo.lastFailedAt)<c.cacheTime||e===o)?!t&&c.errorInfo&&c.errorInfo.retryCount>0?(s[e]={...c,errorInfo:{...c.errorInfo,retryCount:0}},a=!0):s[e]=c:a=!0}return a?{...n,queryCache:s}:n}function Ft(){return Object.create(null)}function qt(e,t,n){return new y(`[createQueryStore: ${e}]: ${t} failed`,n)}function Ct(e){return function(...t){return!0===t[1]?e().setState(t[0],!0):e().setState(t[0])}}exports.DEFAULT_STORAGE_KEY_PREFIX=F,exports.QueryStatuses=D,exports.StoreTags=H,exports.StoresError=y,exports.applyStateUpdate=R,exports.assignStoreTag=U,exports.baseStore=Fe,exports.configureStores=function(e){t&&function(){if(q)throw new Error("[stores]: configureStores() called after first store creation. Call it earlier before creating any stores.")}(),e.logger&&o(e.logger),O??(O=function(e){return e?.queryStoreDefaults?{queryStoreDefaults:e.queryStoreDefaults}:void 0}(e)),j??(j=A(e))},exports.createStoreActions=function(e,n){const r=function(e){const n=e.getState(),r=f(),o=r;if(t&&("object"!=typeof n||null===n))throw new Error("[createStoreActions]: State is not an object");if(G(e))for(const t in n)Y(n,t)&&(o[t]=X(e,t));else for(const e in n)Y(n,e)&&(o[e]=n[e]);return r}(e);return n?Object.assign(r,n):r},exports.deepEqual=function e(t,n){if("object"!=typeof t||null==t||"object"!=typeof n||null==n)return t===n;if(Object.is(t,n))return!0;const r=Object.keys(t);if(r.length!==Object.keys(n).length)return!1;for(const o of r)if(!(o in n)||!e(t[o],n[o]))return!1;return!0},exports.defaultRetryDelay=M,exports.derivedStore=rt,exports.destroyStore=_,exports.destroyStores=function(e,t){for(const n of Array.isArray(e)?e:Object.values(e))n&&!t?.skipDestroy?.(n)&&_(n,t)},exports.ensureError=p,exports.getOptions=C,exports.getQueryKey=K,exports.getStorageConfig=k,exports.getStoreName=function(e){const t="function"==typeof(n=e)?n.name:"";var n;return Q(e)?e.persist.getOptions().name??t:t},exports.hasDestroy=V,exports.hasGetSnapshot=J,exports.identity=l,exports.isDerivedStore=function(e){return"flushUpdates"in e},exports.isPersistedStore=Q,exports.isQueryStore=B,exports.isVirtualStore=G,exports.markStoreCreated=T,exports.nullObject=f,exports.parseQueryKey=function(e){return JSON.parse(e)},exports.queryStore=function(e,r,o){T();const s="function"==typeof r?r:Ft,a="object"==typeof r?r:o,c=function(e){return"string"==typeof e?.storageKey}(a)?a:void 0,u=E??(E=function(){const e={abortInterruptedFetches:!0,cacheTime:z.days(7),debugMode:!1,disableAutoRefetching:!1,keepPreviousData:!1,maxRetries:5,minStaleTime:!1,paramChangeThrottle:!1,retryDelay:M,staleTime:z.minutes(2),suppressStaleTimeWarning:!1},t=C()?.queryStoreDefaults;return t?{...e,...t}:e}()),l=u.minStaleTime,{fetcher:d,onError:g,onFetched:h,setData:b,transform:m,abortInterruptedFetches:S=u.abortInterruptedFetches,cacheTime:v=u.cacheTime,debugMode:w=u.debugMode,disableAutoRefetching:O=u.disableAutoRefetching,disableCache:j=!1,enabled:I=!0,keepPreviousData:x=u.keepPreviousData,maxRetries:F=u.maxRetries,paramChangeThrottle:q=u.paramChangeThrottle,params:k,retryDelay:A=u.retryDelay,staleTime:$=u.staleTime,suppressStaleTimeWarning:P=u.suppressStaleTimeWarning}=e;let R="function"==typeof $?u.staleTime:$;t&&!1!==l&&!O&&!P&&R<l&&console.warn(`[createQueryStore${c?.storageKey?`: ${c.storageKey}`:""}] ❌ Stale times under ${l/1e3} seconds are not recommended. Provided staleTime: ${R/1e3} seconds`);const L=new Error("[createQueryStore: AbortError] Fetch interrupted"),N="function"==typeof v,W=t&&w,_=e.params?Object.keys(e.params):[];let V=null,J=null,B=null,Q=[],G=!1,X=!1,Y=null,ee=null,te=null,ne=null,re=null;const oe={enabled:"function"!=typeof I&&I,error:null,lastFetchedAt:null,queryCache:{},queryKey:"",status:D.Idle},se=new at({disableAutoRefetching:O,initialEnabled:oe.enabled});function ie(){Y&&(ee=null,Y.abort(),Y=null)}function ce(t,n,r){const o=r.setState;function i(e){const t="function"==typeof e;if(t||void 0!==e.enabled){let n;const r=o(r=>{const o=t?e(r):e,s=void 0!==o.enabled?o.enabled:r.enabled;return s!==r.enabled&&(n=()=>function(e,t){e!==t&&re!==t&&(re=t,se.setEnabled(t),t?queueMicrotask(()=>u.fetch(void 0,mt)):(te||S)&&(S&&ie(),te&&(clearTimeout(te),te=null)))}(r.enabled,s)),o});return n?.(),r}return o(e)}function a(e,t){if(O||t?.skipStoreUpdates)return;if(R<=0||R===1/0)return;te&&(clearTimeout(te),te=null);const r=K(e),o=n(),s=(j?ne===r&&o.lastFetchedAt:o.queryCache[r]?.lastFetchedAt)||null,i=s?R-(Date.now()-s):R;te=setTimeout(()=>{const t=se.get();t.enabled&&t.subscriptionCount>0&&u.fetch(e,ht,!0)},i)}r.setState=i,se.init({onSubscribe:(r,o,s)=>{if(J||V||!k&&"function"!=typeof e.enabled&&"function"!=typeof e.staleTime){if(r)if(o){const e=vt(V,J),r=K(e),o=n();o.queryKey!==r&&t({queryKey:r}),o.isStale()?u.fetch(e,void 0,!0):a(e,void 0)}else O&&!s&&u.fetch(void 0,void 0,!0)}else G=!0},onLastUnsubscribe:e=>{te&&(clearTimeout(te),te=null),S&&!e&&ie()}});const u={...s(i,n,r),...oe,async fetch(e,r,o=!1){const s=se.get();if(!r?.force&&!r?.skipStoreUpdates&&!s.enabled)return null;const l=n(),f=l.error,w=l.queryKey,O=l.status===D.Loading,I=St(V,J,_,e),q=K(I);if(O&&ee?.promise&&ee.key===q)return W&&console.log("[🔄 Using Active Fetch 🔄] for params:",JSON.stringify(I)),ee.promise;const C=r?.staleTime??R,k=!!r?.skipStoreUpdates,T="boolean"==typeof r?.updateQueryKey?r.updateQueryKey:!!o&&x,E=(o||w===q||T)&&!k;if(S&&E&&ie(),!r?.force){const e=l.lastFetchedAt,n=l.queryCache[q],o=n?.lastFetchedAt,i=n?.errorInfo,c=i&&i.retryCount>=F,u=(j?ne===q&&e:o)||null;if(u&&!(Date.now()-u>=C)&&(!i||c||k))return E&&!te&&s.subscriptionCount>0&&0!==R&&R!==1/0&&a(I,r),T&&t(e=>e.queryKey!==q?{queryKey:q}:e),W&&console.log("[💾 Returning Cached Data 💾] for params:",JSON.stringify(I)),n?.data??null}E&&(te&&(clearTimeout(te),te=null),!f&&O||t({error:null,status:D.Loading}),ee={key:q});const z=r?.cacheTime??(N?v(I):v);async function M(){const s=c?.storageKey||q;try{W&&(o||!e||wt(e,_)?console.log("[🔄 Fetching 🔄] for params:",JSON.stringify(I)):console.log("[🔄 Fetching with Partial Params 🔄]\n","- Provided params:",`${JSON.stringify(e)}\n`,"- Filled in params:",`${JSON.stringify(Object.fromEntries(Object.keys(I).filter(t=>!(t in e)).map(e=>[e,I[e]])))}`));const n=await(S&&E?async function(e){const t=new AbortController;Y=t;try{return await new Promise((n,r)=>{t.signal.addEventListener("abort",()=>r(L),bt),Promise.resolve(d(e,t)).then(n,r)})}finally{Y===t&&(Y=null)}}(I):d(I,null)),c=Date.now();let l;W&&console.log("[✅ Fetch Successful ✅] for params:",JSON.stringify(I));try{l=function(e,t,n){return n?n(e,t):e}(n,I,m)}catch(e){throw qt(s,"transform",e)}if(k)return W&&console.log("[🥷 Successful Parallel Fetch 🥷] for params:",JSON.stringify(I)),"withCache"===r.skipStoreUpdates&&t(e=>{if(!b)return j?e:{queryCache:{...e.queryCache,[q]:{cacheTime:z,data:l,errorInfo:null,lastFetchedAt:c}}};let t=e;const n=t.queryCache[q];try{b({data:l,params:I,queryKey:q,set:e=>{t="function"==typeof e?{...t,...e(t)}:{...t,...e}}})}catch(e){throw qt(s,"setData",e)}return!j&&Object.is(n,t.queryCache[q])&&(t={...t,queryCache:{...t.queryCache,[q]:{cacheTime:z,data:null,errorInfo:null,lastFetchedAt:c}}}),t}),l;if((b?i:t)(e=>{let t={...e,error:null,lastFetchedAt:c,queryKey:T?q:e.queryKey,status:D.Success};if(b||j){if(b){W&&console.log("[💾 Setting Data 💾] for params:",JSON.stringify(I));const e=t.queryCache[q];try{b({data:l,params:I,queryKey:q,set:e=>{t="function"==typeof e?{...t,...e(t)}:{...t,...e}}})}catch(e){throw qt(s,"setData",e)}!j&&Object.is(e,t.queryCache[q])&&(t.queryCache={...t.queryCache,[q]:{cacheTime:z,data:null,errorInfo:null,lastFetchedAt:c}})}}else W&&console.log("[💾 Setting Cache 💾] for params:",JSON.stringify(I),"| Has previous data?:",!!t.queryCache[q]?.data),t.queryCache={...t.queryCache,[q]:{cacheTime:z,data:l,errorInfo:null,lastFetchedAt:c}};return j||v===1/0?t:xt(x,q,t)}),E&&(ne=q,a(I,r)),h)try{h({data:l,fetch:u.fetch,params:I,set:i})}catch(e){exports.logger.error(qt(s,"onFetched callback",e))}return l??null}catch(i){if(i===L)return W&&console.log("[❌ Fetch Aborted ❌] for params:",JSON.stringify(I)),null;const a=!o&&!0===r?.throwOnError,c=p(i);if(c instanceof y&&exports.logger.error(c),!E){if(a)throw c;return null}const l=j?void 0:n().queryCache[q],f=l?.errorInfo?.retryCount??0,d=f+1;try{g?.(c,f)}catch(e){exports.logger.error(qt(s,"onError callback",e))}if(f<F){if(se.get().subscriptionCount>0){const t="function"==typeof A?A(d,c):A;t!==1/0&&(te&&clearTimeout(te),te=setTimeout(()=>{const t=se.get();t.enabled&&t.subscriptionCount>0&&u.fetch(e,ht,!0)},t))}t(e=>({error:c,queryCache:{...e.queryCache,[q]:{cacheTime:l?.cacheTime??z,data:l?.data??null,lastFetchedAt:l?.lastFetchedAt??null,errorInfo:{error:c,lastFailedAt:Date.now(),retryCount:d}}},queryKey:T?q:e.queryKey,status:D.Error}))}else t(e=>({error:c,queryCache:{...e.queryCache,[q]:{cacheTime:l?.cacheTime??z,data:l?.data??null,lastFetchedAt:l?.lastFetchedAt??null,errorInfo:{error:c,lastFailedAt:Date.now(),retryCount:F}}},queryKey:T?q:e.queryKey,status:D.Error}));if(a)throw c;return null}finally{E&&(ee=null)}}return E?(ee={key:q,promise:M()}).promise:M()},getCacheEntry(e){if(j)return null;const t=n(),r=e?"string"==typeof e?e:K(St(V,J,_,e)):t.queryKey;return t.queryCache[r]??null},getData(e){if(j)return null;const t=n().getCacheEntry(e);return t&&null!==t.data?x?t.data:t.lastFetchedAt&&Date.now()-t.lastFetchedAt>=t.cacheTime?null:t.data:null},getStatus:function(e){const t=n(),r=t.status;switch(e){case"isIdle":return r===D.Idle;case"isLoading":return r===D.Loading;case"isError":case"isInitialLoad":case"isSuccess":case void 0:{const n=t.queryKey,o=t.queryCache[n],s=j?r===D.Error:"number"==typeof o?.errorInfo?.lastFailedAt;if("isError"===e)return s;const i=null!==((j?ne===n&&t.lastFetchedAt:o?.lastFetchedAt)||null),a=!i&&!s&&t.enabled;if("isInitialLoad"===e)return a;const c=i&&!s;return"isSuccess"===e?c:{isError:s,isIdle:r===D.Idle,isLoading:r===D.Loading,isInitialLoad:a,isSuccess:c}}}},isDataExpired(e){const t=n(),r=t.queryCache[t.queryKey],o=t.queryKey,s=t.lastFetchedAt,i=(j?ne===o&&s:r?.lastFetchedAt)||null;if(!i)return!0;const a=e??r?.cacheTime;return void 0===a||Date.now()-i>=a},isStale(e){const t=n(),r=t.queryKey,o=(j?ne===r&&t.lastFetchedAt:t.queryCache[r]?.lastFetchedAt)||null;if(!o)return!0;const s=e??R;return Date.now()-o>=s},reset(e=!1){for(const e of Q)e();Q=[],V=null,J=null,B=null,ie(),te&&(clearTimeout(te),te=null),ee=null,ne=null,e&&t(oe)}},l=r.subscribe;return r.subscribe=(...e)=>{const t=X?()=>{}:se.subscribe(),n=1===e.length?l(e[0]):l(e[0],e[1],e[2]);return e=>{t(e),n()}},u}const ue=c?.storageKey?Fe(ce,(le=c,void 0===(fe={partialize:It(x,c.partialize)})?Object.assign(f(),le):Object.assign(f(),le,fe))):a&&!("storageKey"in a)?Fe(ce,a):Fe(ce);var le,fe;const de=ue.getState(),ye=de.error,pe=de.enabled,ge=de.queryKey,he=de.fetch;let be;if(ge&&!ye&&(ne=ge),X=!0,k||"function"==typeof e.enabled){const{directValues:e,enabledAttachVal:t,enabledDirectValue:n,attachVals:r}=function(e,t,n){const r=f(),o=f(),s=f();for(const e in t){if(!i(t,e))continue;const a=t[e];if(Ot(a)){const t=a(lt,n);r[e]=t,s[e]=t.value}else jt(a)&&(o[e]=a,s[e]=a)}let a,c=null,u=null;if(Ot(e)){const t=e(lt,n);a=t.value,c=t}else a=e,u=e;return{attachVals:r,directValues:o,enabledAttachVal:c,enabledDirectValue:u,resolvedEnabled:a,resolvedParams:s}}(I,k,ue);V={enabled:t,params:r},J={enabled:n,params:e}}"function"==typeof e.staleTime&&(B=e.staleTime(lt,ue),R=B.value);const me=Object.freeze({updateQueryKey:x}),Se=function(){let e,t=!1;return function(...n){e=n,t||(t=!0,queueMicrotask(()=>{t=!1,(e=>{he(e??vt(V,J),me)})(...e)}))}}();function ve(){let e;if(!x){e=vt(V,J);const t=K(e);ue.setState({queryKey:t})}Se(e)}const we=n||!q?ve:ae(ve,"number"==typeof q?q:q.delay,"number"==typeof q?{leading:!1,maxWait:q,trailing:!0}:q);for(const e in V?.params){const t=V.params[e];if(!t)continue;const n=pt(t);if(W&&console.log("[🌀 Param Subscription 🌀] Subscribed to param:",e),n){let r=t.value;const o=n(()=>{const n=t.value;Z(r,n)||(W&&console.log("[🌀 Param Change 🌀] -",e,"- [Old]:",`${r?.toString()},`,"[New]:",n?.toString()),r=n,we())});Q.push(o)}}if(B){const e=pt(B);if(e){const t=B;let n=t.value;W&&console.log("[🌀 StaleTime Subscription 🌀] Initial value:",n);const r=e(()=>{const e=t.value;e!==n&&(W&&console.log("[🌀 StaleTime Change 🌀] - [Old]:",`${n},`,"[New]:",e),n=e,R=e,he())});Q.push(r)}}if(V?.enabled){const e=V.enabled,t=pt(e);if(t){let n=e.value;pe!==n&&((be??(be={})).enabled=n),n&&se.setEnabled(n),W&&console.log("[🌀 Enabled Subscription 🌀] Initial value:",n);const r=t(()=>{const t=e.value;t!==n&&(W&&console.log("[🌀 Enabled Change 🌀] - [Old]:",`${n},`,"[New]:",t),n=t,ue.setState({enabled:t}))});Q.push(r)}}else pe!==oe.enabled&&((be??(be={})).enabled=oe.enabled);const Oe=K(vt(V,J));return Oe!==ge&&((be??(be={})).queryKey=Oe),be&&ue.setState(be),X=!1,G&&queueMicrotask(we),U(ue,H.QueryStore)},exports.replacer=N,exports.reviver=W,exports.setLogger=o,exports.shallowEqual=function(e,t){if("object"!=typeof e||null==e||"object"!=typeof t||null==t)return e===t;if(Object.is(e,t))return!0;const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.is(e[r],t[r]))return!1;return!0},exports.time=z,exports.virtualStore=function(e,t,n){const r="function"==typeof t,o=r?t:void 0,s=r?n:t,i=new Set,a=rt(e,{debugMode:s?.debugMode??!1,equalityFn:function(e,t){const n=Object.is(e,t);return n||(function(e,t){for(const n of i){n.unsubscribe();const r=n.args;if(1===r.length){const o=r[0],s=e.getState(),i=t.getState(),a=t.subscribe(o);n.unsubscribe=a,Object.is(i,s)||o(i,s);continue}const o=r[0],s=r[1];let i=r[2];i?.fireImmediately&&(i={...i,fireImmediately:!1});const a=o(e.getState()),c=o(t.getState()),u=t.subscribe(o,s,i);n.unsubscribe=u,(i?.equalityFn??Object.is)(a,c)||s(c,a)}}(e,t),_(e)),n},keepAlive:!0,lockDependencies:s?.lockDependencies??!0});var c;return Object.assign({[H.VirtualStore]:!0,destroy:a.destroy,getInitialState:()=>a.getState().getInitialState(),getState:()=>a.getState().getState(),persist:(c=a.getState,{clearStorage:()=>c().persist?.clearStorage(),getOptions:()=>c().persist?.getOptions()??{},hasHydrated:()=>c().persist?.hasHydrated()??!0,hydrationPromise:()=>c().persist?.hydrationPromise?.()??Promise.resolve(),onFinishHydration:e=>c().persist?.onFinishHydration(e)??d,onHydrate:e=>c().persist?.onHydrate(e)??d,rehydrate:()=>c().persist?.rehydrate(),setOptions:e=>c().persist?.setOptions(e)}),setState:Ct(a.getState),subscribe:function(...e){const t={args:e,unsubscribe:1===e.length?a.getState().subscribe(e[0]):a.getState().subscribe(e[0],e[1],e[2])};return i.add(t),()=>{t.unsubscribe(),i.delete(t)}}},o?.(a.getState))};
1
+ var e="undefined"!=typeof window&&"undefined"!=typeof document,t="development"===process.env.NODE_ENV,n="test"===process.env.NODE_ENV;function r(){return"undefined"!=typeof window?window.localStorage:null}function o(e){exports.logger=e}exports.logger={debug:(e,n)=>{t&&console.debug(e,n)},error:(e,r)=>{t&&!n&&console.error(e,r)},info:(e,n)=>{t&&console.info(e,n)},warn:(e,n)=>{t&&console.warn(e,n)}};var i=Object.prototype.hasOwnProperty;function s(e,t){return i.call(e,t)}function a(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}function c(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}var u=Object.freeze(Object.create(null));function l(e){return e}function f(){return Object.create(u)}function d(){}var y=class extends Error{constructor(e,t){super(e),this.name="StoresError",void 0!==t&&Object.defineProperty(this,"cause",{configurable:!0,value:t,writable:!0})}};function p(e){return e instanceof Error?e:new Error(String(e))}var g,h="stores/core/sync-channel",b=`${h}:storage:`,m=class{constructor(e){this.broadcast=e.broadcast,this.origin=e.origin,this.storeKey=e.storeKey,this.teardown=e.teardown}destroy(){this.teardown()}publish(e){const t=f();for(const n of Object.entries(e.values))t[n[0]]=n[1];const n={origin:this.origin,replace:e.replace,sessionId:e.sessionId,storeKey:this.storeKey,timestamp:e.timestamp,values:t};this.broadcast(n)}},S=class{constructor(){this.listeners=new Map,this.origin="undefined"!=typeof crypto&&"randomUUID"in crypto?crypto.randomUUID():`${Math.random().toString(36).slice(2)}:${Date.now().toString(36)}`,this.onChannelMessage=e=>{e.data&&this.dispatch(e.data)},this.onStorageEvent=e=>{if(e.key&&e.newValue&&e.key.startsWith(b))try{const t=JSON.parse(e.newValue);this.dispatch(t)}catch(e){exports.logger.error(new y("[sync] Failed to parse storage event payload",e))}},this.channel="undefined"==typeof BroadcastChannel?null:new BroadcastChannel(h),this.storage=v(),this.channel&&this.channel.addEventListener("message",this.onChannelMessage),e&&window.addEventListener("storage",this.onStorageEvent)}get sessionId(){return this.origin}register(e){const t=t=>{if(t.origin===this.origin||t.storeKey!==e.key)return;const n=f();for(const r of e.fields)s(t.values,r)&&(n[r]=t.values[r]);Object.keys(n).length&&e.apply({replace:t.replace,sessionId:t.sessionId,timestamp:t.timestamp,values:n})};let n=this.listeners.get(e.key);return n||(n=new Set,this.listeners.set(e.key,n)),n.add(t),new m({broadcast:e=>this.broadcast(e),origin:this.origin,storeKey:e.key,teardown:()=>this.removeListener(e.key,t)})}broadcast(e){try{this.channel&&this.channel.postMessage(e),this.writeToStorage(e)}catch(e){exports.logger.error(new y("[sync] Failed to broadcast update",e))}}dispatch(e){if(!e.storeKey)return;const t=this.listeners.get(e.storeKey);if(t&&t.size)for(const n of t)n(e)}removeListener(e,t){const n=this.listeners.get(e);n&&(n.delete(t),n.size||this.listeners.delete(e))}writeToStorage(e){if(this.storage||(this.storage=v()),!this.storage)return;const t=`${b}${e.storeKey}`;try{this.storage.setItem(t,JSON.stringify(e))}catch(e){exports.logger.error(new y("[sync] Failed to write broadcast payload to storage",e))}}};function v(){try{return"undefined"!=typeof window?window.localStorage:null}catch{return null}}var w,O,j,I=class{destroy(){}publish(){}},k=class{constructor(){this.sessionId="noop"}register(e){return new I}},C="stores:",F=!1;function q(){if(O)return O}function x(){return j??(j=T(void 0))}function A(){F=!0}function T(t){return{storage:t?.storage??(n=t?.storageKeyPrefix??C,{clearAll(){try{const e=r();if(!e)return;const t=[];for(let r=0;r<e.length;r++){const o=e.key(r);o?.startsWith(n)&&t.push(o)}for(const n of t)e.removeItem(n)}catch(e){console.error("Error clearing localStorage:",e)}},contains(e){const t=r();return null!==t?.getItem(`${n}${e}`)},delete(e){try{const t=r();t?.removeItem(`${n}${e}`)}catch(e){console.error("Error deleting from localStorage:",e)}},getAllKeys(){try{const e=r();return e?Array.from(e.keys()):[]}catch(e){return console.error("Error getting keys from localStorage:",e),[]}},get(e){try{const t=r();return t?t.getItem(`${n}${e}`)??void 0:void 0}catch(e){return void console.error("Error reading from localStorage:",e)}},set(e,t){try{const o=r();o?.setItem(`${n}${e}`,t)}catch(e){console.error("Error writing to localStorage:",e)}}}),syncEngine:t?.syncEngine??(e?(g||(g=new S),g):(w||(w=new k),w))};var n}var z,E={Error:"error",Idle:"idle",Loading:"loading",Success:"success"},D={ms:e=>e,seconds:e=>1e3*e,minutes:e=>6e4*e,hours:e=>36e5*e,days:e=>864e5*e,weeks:e=>6048e5*e,infinity:1/0,zero:0};function P(e,t){const n=t?.baseDelay??D.seconds(5),r=t?.maxDelay??D.minutes(5);return Math.min(n*Math.pow(2,e),r)}function K(e,t){return!0===t[1]?e(t[0],!0):e(t[0])}function M(e,t,n){if(!0===n)return $(t)?t(e):t;const r=$(t)?t(e):t;return Object.is(r,e)?e:c(e)&&c(r)?{...e,...r}:r}function $(e){return"function"==typeof e}function R(e,t){return t instanceof Map?{__type:"Map",entries:Array.from(t.entries())}:t instanceof Set?{__type:"Set",values:Array.from(t)}:t}function L(e,t){return function(e){return"object"==typeof e&&null!==e&&"__type"in e&&"Map"===e.__type}(t)?new Map(t.entries):function(e){return"object"==typeof e&&null!==e&&"__type"in e&&"Set"===e.__type}(t)?new Set(t.values):t}var N=Object.freeze({QueryStore:Symbol("queryStore"),VirtualStore:Symbol("virtualStore")});function H(e,t){return Object.assign(e,{[t]:!0})}function _(e,t){V(e)?e.getState().reset(t?.clearQueryCache):U(e)&&e.destroy()}function U(e){return"destroy"in e}function W(e){return"getSnapshot"in e}function V(e){return N.QueryStore in e}function J(e){return!(!("persist"in e)||!e.persist)&&"string"==typeof e.persist.getOptions().name}function B(e){return N.VirtualStore in e}function Q(e,t){return function(...n){const r=e.getState()[t];if("function"==typeof r)return r(...n);throw new Error(`[createVirtualStoreAction]: Method ${String(t)} is not a function`)}}function G(e,t){return"function"==typeof e[t]}function X(e,t){const n=Object.prototype.hasOwnProperty;function r(e,t){for(const n of e.keys())if(X(n,t))return n}let o,i,s;if(e===t)return!0;if(e&&t&&(o=e.constructor)===t.constructor){if(o===Date)return e.getTime()===t.getTime();if(o===RegExp)return e.toString()===t.toString();if(o===Array){if((i=e.length)===t.length)for(;i--&&X(e[i],t[i]););return-1===i}if(o===Set){if(e.size!==t.size)return!1;for(let n of e){if(s=n,s&&"object"==typeof s&&(s=r(t,s),!s))return!1;if(!t.has(s))return!1}return!0}if(o===Map){if(e.size!==t.size)return!1;for(let n of e){if(s=n[0],s&&"object"==typeof s&&(s=r(t,s),!s))return!1;if(!X(n[1],t.get(s)))return!1}return!0}if(o===ArrayBuffer)e=new Uint8Array(e),t=new Uint8Array(t);else if(o===DataView){if((i=e.byteLength)===t.byteLength)for(;i--&&e.getInt8(i)===t.getInt8(i););return-1===i}if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(t)){const n=e,r=t;if((i=n.byteLength)===r.byteLength)for(;i--&&n[i]===r[i];);return-1===i}if(!o||"object"==typeof e){i=0;for(const r in e){if(n.call(e,r)&&++i&&!n.call(t,r))return!1;if(!(r in t)||!X(e[r],t[r]))return!1}return Object.keys(t).length===i}}return e!=e&&t!=t}function Y(e){return e()}var Z=!1,ee=!1,te=!1,ne=new Set,re=new Map,oe=new Map,ie=null,se=1/0;function ae(){return Z}function ce(){return ie}function ue(){Z||(Z=!0,te||(te=!0,queueMicrotask(()=>{te=!1,le()})))}function le(){if(Z)if(ee)de();else{ee=!0;try{Y(de)}finally{ge()}}}function fe(e){Z&&ne.add(e)}function de(){for(;re.size>0||ne.size>0;)ye(),pe()}function ye(){for(;re.size>0;){const e=se,t=oe.get(e);if(t){oe.delete(e);for(const e of t)re.delete(e);ie=e;for(const e of t)e();ie=null,se=1/0;for(const e of oe.keys())e<se&&(se=e)}else{se=1/0;for(const e of oe.keys())e<se&&(se=e)}}}function pe(){for(const e of ne)ne.delete(e),e()}function ge(){Z=!1,ee=!1,ie=null,ne.clear(),re.clear(),oe.clear(),se=1/0}function he(e){let t;const n=new Set;let r;function o(...e){const o=M(t,...e);if(Object.is(o,t))return;const i=t;if(t=o,r)for(const e of r)e(t,i);n.size&&le();for(const e of n)e(t,i)}function i(){return t}const s={getInitialState:function(){return a},getState:i,setState:o,subscribe:function(...e){return 1===e.length?c(e[0]):function(e,n,o){const i=o?.equalityFn??Object.is,s=o?.isCascadeParticipant??!1;let a=e(t);function u(t){const r=e(t);if(i(a,r))return;const o=a;a=r,s&&ue(),n(r,o)}return o?.fireImmediately&&n(a,a),s?function(e){return(r??(r=new Set)).add(e),()=>{r?.delete(e),0===r?.size&&(r=void 0)}}(u):c(u)}(e[0],e[1],e[2])}},a=t=e(o,i,s);return s;function c(e){return n.add(e),()=>{n.delete(e)}}}function be(e){return!!e&&"object"==typeof e&&"then"in e&&"function"==typeof e.then}function me(e){return{...e,merge:e.merge??Se,skipHydration:e.skipHydration??!1}}function Se(e,t){return void 0===e?t:{...t,...e}}function ve(){let e,t,n=!1;return{complete:function(){!n&&e&&(n=!0,e(),e=void 0,t=void 0)},isHydrated:function(){return n},fail:function(r){!n&&t&&(n=!0,t(r),t=void 0,e=void 0)},promise:new Promise((n,r)=>{e=n,t=r})}}var we=Math.max,Oe=Math.min;function je(e,t=0,n={}){let r,o,i,s,a,c,u=0,l=!1,f=!1,d=!0;if("function"!=typeof e)throw new TypeError("Expected a function");function y(t){const n=r,i=o;return r=o=void 0,u=t,s=n?e.apply(i,n):e.apply(i),s}function p(e){const n=e-(c??0);return void 0===c||n>=t||n<0||f&&void 0!==i&&e-u>=i}function g(){const e=Ie();if(p(e))return h(e);a=setTimeout(g,function(e){const n=t-(e-(c??0));return f&&void 0!==i?Oe(n,i-(e-u)):n}(e))}function h(e){return a=void 0,d&&r?y(e):(r=o=void 0,s)}function b(...e){const n=Ie(),i=p(n);if(r=e,o=this,c=n,i){if(void 0===a)return function(e){return u=e,a=setTimeout(g,t),l?y(e):s}(c);if(f)return clearTimeout(a),a=setTimeout(g,t),y(c)}return void 0===a&&(a=setTimeout(g,t)),s}return t=ke(t)||0,function(e){const t=typeof e;return null!==e&&("object"===t||"function"===t)}(n)&&(l=!!n.leading,f="maxWait"in n,i=f?we(ke(n.maxWait)||0,t):void 0,d="trailing"in n?!!n.trailing:d),b.cancel=function(){void 0!==a&&clearTimeout(a),u=0,r=c=o=a=void 0},b.flush=function(){return void 0===a?s:h(Ie())},b}function Ie(){return"undefined"!=typeof performance&&"function"==typeof performance.now?performance.now():Date.now()}function ke(e){if("number"==typeof e)return e;if("symbol"==typeof e||void 0===e)return NaN;if("object"==typeof e&&null!==e){const t="function"==typeof e.valueOf?e.valueOf():e;e="object"==typeof t?t+"":t}return"string"!=typeof e?0===e?e:+e:(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)}function Ce(e){if(!a(e))return e;const t=f(),n=Object.keys(e);for(let r=0;r<n.length;r++){const o=n[r],i=e[o];"function"!=typeof i&&(t[o]=i)}return t}var Fe=n?0:e?D.ms(200):D.seconds(5);function qe(e,t,n,r){const o=!(t.deserializer||t.serializer||e.deserializer||e.serializer),i="object"==typeof t.sync&&!0===(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata),s=t.partialize??Ce,a=t.deserializer??e.deserializer??Ae(o),c=t.serializer??e.serializer??Te(o);function u(t,n,o){try{if(Pe(r))return;const a={state:s(n),version:o},u=Ee(r,i,a),l=c(a);try{e.set(t,l),De(r,u)}catch(e){exports.logger.error(new y("[createBaseStore]: Failed to persist store data",e))}}catch(e){exports.logger.error(new y("[createBaseStore]: Failed to persist store data",e))}}const l=void 0!==n?je(u,n,{leading:!1,maxWait:n,trailing:!0}):u;return{getItem:t=>{const n=e.get(t);return void 0===n?null:a(n)},setItem:(e,t,n)=>{r?.getIsApplyingRemote()||l(e,t,n)},removeItem:t=>{try{e.delete(t)}catch(e){exports.logger.error(new y("[createBaseStore]: Failed to delete persisted store data",e))}}}}function xe(e,t,n,r){const o=!(t.deserializer||t.serializer||e.deserializer||e.serializer),i="object"==typeof t.sync&&!0===(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata),s=t.partialize??Ce,a=t.deserializer??e.deserializer??Ae(o),c=t.serializer??e.serializer??Te(o);async function u(t,n,o){try{if(Pe(r))return;const a={state:s(n),version:o},u=Ee(r,i,a),l=c(a);try{await e.set(t,l),De(r,u)}catch(e){exports.logger.error(new y("[createBaseStore]: Failed to persist store data",e))}}catch(e){exports.logger.error(new y("[createBaseStore]: Failed to serialize persisted store data",e))}}const l=void 0!==n?je(u,n,{leading:!1,maxWait:n,trailing:!0}):function(e){let t,n=null;return function(...r){return t=r,n||(n=new Promise(r=>{queueMicrotask(async()=>{try{await e(...t)}finally{n=null,r()}})})),n}}(u);return{getItem:async t=>{const n=await e.get(t);return void 0===n?null:a(n)},setItem:async(e,t,n)=>{if(!r?.getIsApplyingRemote())return await l(e,t,n)},removeItem:async t=>{try{await e.delete(t)}catch(e){exports.logger.error(new y("[createBaseStore]: Failed to delete persisted store data",e))}}}}function Ae(e){return t=>{if("string"!=typeof t)throw new y("[createBaseStore]: Received non-string serialized state without a custom deserializer. Provide a deserializer on the store or storage adapter.");return function(e,t){try{return JSON.parse(e,t?L:void 0)}catch(e){throw exports.logger.error(new y("[createBaseStore]: Failed to deserialize persisted store data",e)),e}}(t,e)}}function Te(e){return t=>function(e,t){try{return JSON.stringify(e,t?R:void 0)}catch(e){throw exports.logger.error(new y("[createBaseStore]: Failed to serialize store data",e)),e}}(t,e)}var ze=Object.freeze({shouldClear:!1});function Ee(e,t,n){if(!t||!e)return ze;const r=e.getFieldTimestampSnapshot();return function(e,t){const n=e.getSessionId(),r=e.getTimestamp();void 0!==n&&void 0!==r&&(t.syncMetadata={origin:n,timestamp:r})}(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 De(e,t){e&&t.shouldClear&&t.fieldSnapshot&&Object.keys(t.fieldSnapshot).length&&e.clearFieldTimestamps(t.fieldSnapshot)}function Pe(e){return!!e&&!!e.getIsApplyingRemote()}var[Ke,Me]=[0,1];function $e(e,t,n){if(!e)return!0;const r=e[Ke],o=e[Me];return!(t<r)&&(t>r||n>o)}function Re(e,t){return Object.prototype.hasOwnProperty.call(t,e)}function Le(e,n){if(!t)return!0;if(null===e||null===n)return e===n;const r=typeof e;return r===typeof n&&("object"!==r||Object.prototype.toString.call(e)===Object.prototype.toString.call(n))}function Ne(e){if(null===e)return"null";const t=typeof e;return"object"===t?Object.prototype.toString.call(e):t}function He(e,t){if(A(),!t)return he(e);const n=t.storageKey,r="string"==typeof n,o=r?t.storage??x().storage:void 0,i=function(e,t){if(!e)return null;const n="object"==typeof e,r=n?e.key??t:!0===e?t:e;if(!r)throw new y("[createBaseStore]: sync requires a key to be specified either directly or via storageKey");return n?{...e,key:r}:{key:r}}(t.sync,n),s=i?function(e,t,n){const r=t.engine??x().syncEngine,o=function(e){let t,n,r,o=!1;return{isAsync:e,clearFieldTimestamps:function(e){if(e&&r){for(const t of Object.entries(e)){const e=t[0],n=t[1];r[e]===n&&delete r[e]}Object.keys(r).length||(r=void 0)}},getFieldTimestampSnapshot:function(){if(r)return{...r}},getIsApplyingRemote:()=>o,getSessionId:()=>t,getTimestamp:()=>n,mergeFieldTimestamps:function(e){if(r)for(const t of Object.entries(e)){const e=t[0],n=t[1],o=r[e];(void 0===o||n>o)&&(r[e]=n)}else r={...e}},onHydrationComplete:void 0,onHydrationFlushEnd:void 0,setIsApplyingRemote:e=>o=e,setSessionId:e=>t=e,setTimestamp:e=>n=e,setWithoutPersist:void 0}}(n);return{stateCreator:(i,s,a)=>{const c=new Map,u=[],l=[];let d=null,p=!1,g=!1,h=0,b=null,m=[],S=Promise.resolve(),v=!n;function w(e,t){if(o?.setSessionId&&o?.setTimestamp&&r.sessionId&&(o.setSessionId(r.sessionId),o.setTimestamp(e),o.mergeFieldTimestamps&&t.length>0)){const n=f();for(const r of t)n[String(r)]=e;o.mergeFieldTimestamps(n)}}function O(e,t){if(p||!b)return t?i(e,t):i(e);const n=function(){const e=Date.now(),t=e>h?e:h+1;return h=t,t}();let o=[],s=f();const a=r=>{const i=M(r,e,t);for(const e of m)Object.is(i[e],r[e])||(o.push(e),s[e]=i[e]);return o.length&&w(n,o),i},u=t?i(a,!0):i(a);function y(){o.length&&function(e){const t=r.sessionId;for(const n of e.keys)c.set(n,[e.timestamp,t]);d&&g?d.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values}):l.push(e)}({keys:o,replace:t??!1,values:s,timestamp:n})}return be(u)?u.finally(y):(y(),u)}const j=a.setState;a.setState=O;const I=e(O,s,a);if(m=t.fields??function(e){const t=[];for(const n of Object.entries(e)){if("function"==typeof n[1])continue;const e=n[0];t.push(e)}return t}(I),!m.length)return I;async function k(e){h=Math.max(h,e.timestamp);const n=f(),r=s(),i=e.timestamp;let a;if(e.replace)for(const t of m)Re(t,e.values)||$e(c.get(t),i,e.sessionId)&&(a??(a=[])).push(t);for(const o of m){if(!Re(o,e.values))continue;if(!b?.has(o))continue;if(!$e(c.get(o),i,e.sessionId))continue;const s=t.merge?.[o];if(s){const t=e.values[o],a=r[o];if(void 0!==t){const u=s(t,a,r,e.values),l=void 0!==a?a:t;if(!Le(u,l))return void exports.logger.error(new y(`[sync] Merge function for field "${String(o)}" returned ${Ne(u)} but expected ${Ne(l)}`));n[o]=u,c.set(o,[i,e.sessionId])}}else n[o]=e.values[o],c.set(o,[i,e.sessionId])}if(Object.keys(n).length>0||a?.length){p=!0,o&&o.setIsApplyingRemote(!0);try{if(e.replace){const e={...r};let t=!1;if(a?.length){t=!0;for(const t of a)delete e[t],c.delete(t)}for(const r in n){if(!Object.prototype.hasOwnProperty.call(n,r))continue;const o=n[r];void 0!==o&&(Object.is(e[r],o)||(t=!0),e[r]=o)}if(!t)return;await(o.setWithoutPersist??j)(e,!0)}else await(o.setWithoutPersist??j)(n)}finally{p=!1,o&&o.setIsApplyingRemote(!1)}}}function C(e){n?S=S.then(()=>k(e)):k(e)}if(b=new Set(m),d=r.register({apply:e=>{v?C(e):u.push(e)},fields:m,getState:s,key:t.key}),d?.onFirstSubscribe||d?.onLastUnsubscribe){let e=0;const t=a.subscribe;a.subscribe=(...n)=>{e||d.onFirstSubscribe?.(),e+=1;const r=1===n.length?t(n[0]):t(n[0],n[1],n[2]);return()=>{r(),e-=1,e||queueMicrotask(()=>{e||d.onLastUnsubscribe?.()})}}}function F(){g=!0,function(){if(d&&l.length){for(const e of l){const t=r.sessionId;for(const n of e.keys)c.set(n,[e.timestamp,t]);w(e.timestamp,e.keys),d.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values})}l.length=0}}()}function q(){v=!0,function(){if(!u.length)return;const e=u.slice();u.length=0;for(const t of e)C(t)}()}return n?(o.onHydrationComplete=F,o.onHydrationFlushEnd=q):d.onHydrated?(d.onHydrated(F),q()):(F(),q()),I},syncContext:o}}(e,i,o?.async??!1):void 0,a=s?.stateCreator??e;if(!r)return he(a);const c=function(e,t,n){const r=t??e.storage??x().storage,o=(e.sync?void 0:e.persistThrottleMs??Fe)||void 0,i=e.version??0;return r.async?{async:!0,persistStorage:xe(r,e,o,n),version:i}:{async:!1,persistStorage:qe(r,e,o,n),version:i}}(t,o,s?.syncContext),u=c.async?function(e){let t,n,r,o=!1;return{hydrationPromise:()=>o?t?.promise??n??(n=Promise.resolve()):(t||(t=ve()),t.promise),stateCreator:(n,i,s)=>{let a;return r=()=>{if(a?.length){for(const e of a)K(s.setState,e);a=void 0}},e(function(...e){return o?K(n,e):(t||(t=ve()),a||(a=[]),a.push(e),t.promise)},i,s)},wrapOnRehydrateStorage:(e,n)=>i=>{const s=e?.(i);return(e,i)=>{o=!0,n?.onHydrationComplete?.(),r&&r(),n?.onHydrationFlushEnd?.(),i?t?.fail(p(i)):t?.complete(),s?.(e,i)}}}}(a):void 0,l=u?u.wrapOnRehydrateStorage(t.onRehydrateStorage,s?.syncContext):t.onRehydrateStorage,d=he(function(e,t){return(n,r,o)=>{let i,s,a,c=me(t),u=!1,l=0;function f(){return c.storage.setItem(c.name,r(),c.version)}const d=o.setState;o.setState=function(...e){return K(d,e),f()};const y=e(function(...e){return K(n,e),f()},r,o);function p(){const e=function(){const e=++l;return u=!1,s?.forEach(e=>e(r()??y)),e}(),t=c.onRehydrateStorage?.(r()??y);try{const n=c.storage.getItem(c.name);return be(n)?n.then(n=>g(e,n,t)).catch(n=>m(e,t,n)):g(e,n,t)}catch(n){m(e,t,n)}}return o.getInitialState=()=>y,Object.assign(o,{persist:{clearStorage:()=>{c.storage.removeItem(c.name)},getOptions:()=>c,hasHydrated:()=>u,onFinishHydration:e=>(a??(a=new Set),a.add(e),()=>{a?.delete(e),0===a?.size&&(a=void 0)}),onHydrate:e=>(s??(s=new Set),s.add(e),()=>{s?.delete(e),0===s?.size&&(s=void 0)}),rehydrate:p,setOptions:e=>{c=me({...c,...e,storage:e.storage??c.storage})}}}),c.skipHydration||p(),i??y;function g(e,t,n){const r=function(e,t){if(!t)return{migrated:!1,state:void 0};if("number"!=typeof t.version||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"),{migrated:!1,state:void 0};const n=e.migrate(t.state,t.version);return be(n)?n.then(e=>({migrated:!0,state:e})):{migrated:!0,state:n}}(c,t);return be(r)?r.then(t=>h(e,t,n)).catch(t=>m(e,n,t)):h(e,r,n)}function h(e,t,o){const s=function(e,t){if(e!==l)return;const o=c.merge(t.state,r()??y);return i=o,n(o,!0),t.migrated?f():void 0}(e,t);if(be(s))return s.then(()=>b(e,o));b(e,o)}function b(e,t){if(e!==l)return;t?.(i,void 0);const n=r();i=n,u=!0,a?.forEach(e=>e(n))}function m(e,t,n){e===l&&t?.(void 0,n)}}}(u?(e,t,n)=>(s&&(s.syncContext.setWithoutPersist=n.setState),u.stateCreator(e,t,n)):a,{merge:t.merge,migrate:t.migrate,name:n,onRehydrateStorage:l,storage:c.persistStorage,version:c.version}));return u?Object.assign(d,{persist:Object.assign(d.persist,{hydrationPromise:u.hydrationPromise})}):d}function _e(e,t,n="s"){return 1===t?e:`${e}${n}`}var Ue=Symbol("stores.deriveProxy.unwrap");function We(e,t,n){const r=t.get(e);if(void 0!==r)return r;const o=function(e,t,n,r=[]){return e&&"object"==typeof e?Ve(e,r,t,n,new WeakSet,new WeakMap):(n(t,r,!0),e)}(W(e)?e.getSnapshot():e.getState(),e,n);return t.set(e,o),o}function Ve(e,t,n,r,o,i){return new Proxy(e,{get(s,a,c){if(a===Ue)return r(n,t,!0),s;if(o.has(s))return Reflect.get(s,a,c);if("__proto__"===a||"symbol"==typeof a)return a===Symbol.iterator&&(r(n,t,!0),o.add(s)),Reflect.get(s,a,c);const u=Reflect.get(s,a,s),l=String(a),f=t.concat(l);if("function"==typeof u)return Object.prototype.hasOwnProperty.call(s,a)?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));const d=!!u&&"object"==typeof u;return r(n,f,!d),d?(i.has(u)||i.set(u,Ve(u,f,n,r,o,i)),i.get(u)):u},getOwnPropertyDescriptor:(e,i)=>(r(n,t,!0),o.add(e),Reflect.getOwnPropertyDescriptor(e,i)),has:(e,o)=>(r(n,t,!0),Reflect.has(e,o)),ownKeys:e=>(r(n,t,!0),o.add(e),Reflect.ownKeys(e))})}function Je(e,t){if(!e||"object"!=typeof e)return e;const n=function(e){const t=Reflect.get(e,Ue);return t&&"object"==typeof t?t:void 0}(e);return n||(Array.isArray(e)?function(e,t){const n=Qe(e,t);if(n)for(let t=0;t<e.length;t++)Be(e,String(t),n)}(e,t):a(e)&&function(e,t){const n=Qe(e,t);if(n)for(const t of Reflect.ownKeys(e))Be(e,t,n)}(e,t),e)}function Be(e,t,n){const r=Reflect.getOwnPropertyDescriptor(e,t);if(!r||!("value"in r))return;const o=Je(r.value,n);o!==r.value&&(r.value=o,Reflect.defineProperty(e,t,r))}function Qe(e,t){const n=t??new WeakSet;return n.has(e)?null:(n.add(e),n)}var Ge=Object.freeze([]);function Xe(){const e=new Map;return{buildProxySubscriptions(t,n,r,o){const i=new Set;for(const t of e)et(t[1],t[0],[],0,i,r);!1!==o?.(i)&&function(e,t,n){for(const n of e){const e=n.invocation?ot(n.path,n.invocation):rt(n.path);t(n.store,e,n.path)}n&&function(e){const t=e.size;console.log(`[📡 ${t} ${_e("Proxy Subscription",t)} 📡]:`,JSON.stringify(Array.from(e).map(e=>{const t="name"in(n=e.store)&&"string"==typeof n.name?n.name:"store";var n;const r=e.path.join(".");if(!e.invocation)return r?`$(${t}).${r}`:`$(${t})`;const o=e.invocation.args?.length??0;return`$(${t}).${r}${o?`(${o}_${_e("arg",o)})`:"()"}`}),null,2))}(e)}(i,t,n)},reset(){e.clear()},trackPath(t,n,r,o){let i=e.get(t);i||(i=Ye(),e.set(t,i)),Ze(i,n,0,r,o)}}}function Ye(){return f()}function Ze(e,t,n,r,o){if(n===t.length)return r&&(e.isLeaf=!0),void(o&&function(e,t){const n=e.invocation;if(!n)return void(e.invocation=t);if(tt(n,t))return;const r=e.extraInvocations;if(r){for(let e=0;e<r.length;e++)if(tt(r[e],t))return;r.push(t)}else e.extraInvocations=[t]}(e,o));e.children||(e.children=Ye());const i=t[n];let s=e.children?.[i];s||(s=Ye(),e.children[i]=s),Ze(s,t,n+1,r,o)}function et(e,t,n,r,o,i=2){const s=e.children;if(!s)return void nt(e,t,n,o);const a=Object.keys(s),c=a.length;if(0!==c)if(e.isLeaf||r>=i&&c>1){nt(e,t,n,o);for(const e of a){const a=s[e];a.invocation&&et(a,t,[...n,e],r+1,o,i)}}else if(r<i&&c>1&&!e.isLeaf)for(const e of a)et(s[e],t,[...n,e],r+1,o,i);else{if(1===c){const e=a[0];return void et(s[e],t,[...n,e],r+1,o,i)}nt(e,t,n,o)}else nt(e,t,n,o)}function tt(e,t){const n=e.args,r=t.args,o=n?.length??0;if(o!==(r?.length??0))return!1;if(!n||!r)return!0;for(let e=0;e<o;e++)if(!Object.is(n[e],r[e]))return!1;return!0}function nt(e,t,n,r){const o=e.isLeaf??!1,i=e.invocation;if(!i)return void r.add({store:t,path:n,isLeaf:o});r.add({store:t,path:n,invocation:i,isLeaf:o});const s=e.extraInvocations;if(s)for(let e=0;e<s.length;e++)r.add({store:t,path:n,invocation:s[e],isLeaf:o})}function rt(e){return t=>it(t,e)}function ot(e,t){const n=e.slice(0,-1),r=e[e.length-1];return e=>{const o=it(e,n),i=o&&"object"==typeof o?Reflect.get(o,r):void 0;return"function"==typeof i?Reflect.apply(i,o,t.args??Ge):void 0}}function it(e,t){let n=e;for(const e of t){if(!n||"object"!=typeof n)return n;n=Reflect.get(n,e)}return n}var st=Symbol(),at=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});function ct(e,n=Object.is){const{debounceOptions:r,debugMode:o,equalityFn:i,keepAlive:s,lockDependencies:a}="function"==typeof(u=n)?{debounceOptions:void 0,debugMode:!1,equalityFn:u,keepAlive:!1,lockDependencies:!1}:{debounceOptions:u.debounce,debugMode:(t&&u.debugMode)??!1,equalityFn:u.equalityFn??Object.is,keepAlive:u.keepAlive??!1,lockDependencies:u.lockDependencies??!1},c=new Set;var u;s&&c.add(ut);const f=new Set;let d,y,p=st,g=!1,h=!1,b=!0,m=!0,S=0,v=!1,w=null,O=st;function j(e,t,n){if(!m||!c.size)return(t??l)(e.getState());if(!t)return d||(d=new WeakMap),y||(y=Xe()),We(e,d,y.trackPath);const r=n?{equalityFn:n,isCascadeParticipant:!0}:at;return f.add(e.subscribe(t,D,r)),t(W(e)?e.getSnapshot():e.getState())}function I(e){for(const t of f)t(e);f.clear()}let k=!0;function C(){if(!b&&lt(p))return p;b=!1,m&&I(!0);const t=p,n=lt(t);h=!0;try{p=function(t){k=!0;const n=p,r=e(t),s=y?Je(r):r;return lt(n)&&i(n,s)?(o&&console.log("[🥷 Derive Complete 🥷]: No change detected"),k=!1,n):s}(j)}finally{h=!1}const r=o&&(!n||"verbose"===o&&m);if(r){n?"verbose"===o&&console.log("[🌀 Rebuilding Subscriptions 🌀]: Created…"):console.log("[🌀 Initial Derive Complete 🌀]: Created…");const e=f.size;console.log(`[🎯 ${e} ${_e("Selector Subscription",e)} 🎯]`)}return y&&m&&(y.buildProxySubscriptions((e,t)=>{f.add(e.subscribe(t,D,at))},r),d=void 0,y.reset(),a&&(y=void 0)),k&&n&&function(e,t){const n=function(){const e=c.has(ut)?c.size-1:c.size;return S>0&&S<e}(),r=(!S||n)&&(n||null!==ce()||ae());n&&ue(),o&&console.log(`[📻 Derive Complete 📻]: Notifying ${c.size} ${_e("watcher",c.size)}`);for(const t of c){if("function"==typeof t||!t.isCascadeParticipant)continue;const n=t.selector(e);if(!t.equalityFn(t.currentSlice,n)){const e=t.currentSlice;t.currentSlice=n,t.listener(n,e)}}if(r)return lt(O)||(O=t),void(v||(v=!0,fe(q)));F(e,t)}(p,t),a&&(m=!1),p}function F(e,t){for(const n of c)if("function"==typeof n)n(e,t);else if(!n.isCascadeParticipant){const t=n.selector(e);if(!n.equalityFn(n.currentSlice,t)){const e=n.currentSlice;n.currentSlice=t,n.listener(t,e)}}}function q(){c.size&&b&&!S&&C();const e=O;v=!1,O=st,c.size&&lt(p)&&lt(e)&&F(p,e)}const x=r?je(T,"number"==typeof r?r:r.delay,"number"==typeof r?{leading:!1,maxWait:r,trailing:!0}:r):void 0,A=x??(()=>{g||(g=!0,queueMicrotask(T))});function T(){g=!1,c.size?b&&C():M()}function z(e){e||x&&b?queueMicrotask(()=>{c.size||M()}):M()}function E(){T(),w=null}function D(){if(!h&&!b){if(b=!0,!x){if(S){ue();const e=ce(),t=null===e?0:e+1;if(null!==w&&t<=w)return;return w=t,void function(e,t){if(!Z)return;const n=t<0?0:0|t,r=re.get(e);if(void 0===r){re.set(e,n);let t=oe.get(n);return t||(t=new Set,oe.set(n,t)),t.add(e),void(n<se&&(se=n))}if(n>r){const t=oe.get(r);if(t&&(t.delete(e),0===t.size&&(oe.delete(r),r===se))){se=1/0;for(const e of oe.keys())e<se&&(se=e)}re.set(e,n);let o=oe.get(n);o||(o=new Set,oe.set(n,o)),o.add(e),n<se&&(se=n)}}(E,t)}if(ae())return void(v||(v=!0,fe(q)))}w=null,A()}}function P(e){c.add(ut);try{return e()}finally{c.delete(ut)}}function K(){return ae()&&function(){if(Z)if(ee)null===ie&&ye();else{ee=!0;try{ye()}catch(e){throw ge(),e}finally{ee=!1,ie=null}}}(),b||!lt(p)?c.size>0?C():e(j):p}function M(e=!0){s&&e||(x?.cancel(),I(),c.clear(),S=0,y=void 0,d=void 0,m=!0,g=!1,h=!1,b=!0,p=st,v=!1,O=st,w=null)}return{destroy:()=>M(!1),flushUpdates:function(){c.size&&(x?x.flush():b&&C())},getSnapshot:function(){return lt(p)?(g&&T(),p):c.size?C():P(C)},getState:K,subscribe:function(...e){if(1===e.length){const t=e[0];return c.add(t),lt(p)||K(),()=>{c.delete(t),c.size||z(!1)}}const[t,n,r]=e,o=r?.equalityFn??Object.is,i=r?.isCascadeParticipant??!1,s=function(e){return e(c.size?K():P(K))}(t),a={currentSlice:s,equalityFn:o,isCascadeParticipant:i,listener:n,selector:t};return c.add(a),i&&(S+=1),r?.fireImmediately&&n(s,s),()=>{c.delete(a),i&&(S-=1),c.size||z(i)}},getInitialState:()=>{throw new Error("[createDerivedStore]: getInitialState() is not available on derived stores.")},setState:()=>{throw new Error("[createDerivedStore]: setState() is not available on derived stores.")}}}function ut(){}function lt(e){return e!==st}var ft=class{constructor(e){this.count=0,this.lastSubscriptionTime=null,this.fetchThrottleMs=null,this.onSubscribe=null,this.onLastUnsubscribe=null,e&&(this.fetchThrottleMs=D.seconds(5))}init({onSubscribe:e,onLastUnsubscribe:t}){this.onSubscribe=e,this.onLastUnsubscribe=t}hasSubscribers(){return this.count>0}subscribe(){const e=0===this.count,t=null!==this.fetchThrottleMs,n=t&&null!==this.lastSubscriptionTime&&!e&&Date.now()-this.lastSubscriptionTime<=this.fetchThrottleMs;return this.count+=1,this.onSubscribe?.(e,n),t&&(this.lastSubscriptionTime=Date.now()),e=>{const t=1===this.count;this.count=Math.max(this.count-1,0),t&&(this.onLastUnsubscribe?.(e),this.lastSubscriptionTime=null)}}},dt=Symbol("stores.queryParamConfig");function yt(e){return JSON.stringify(pt(e))}function pt(e){return"object"!=typeof e||null===e?e:Object.keys(e).sort().reduce((t,n)=>{const r=e[n];return t[n]=a(r)?pt(r):r,t},f())}var gt=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});function ht(e,t,n){const r=f();let o=null,i=!1;if(e)for(const n in e){if(!s(e,n))continue;const a=bt(r,e[n],n,t);a&&((o??(o=f()))[n]=a,void 0!==a.key&&(i=!0))}return{buildKey:(e=r)=>yt(i?function(e,t){const n=f();for(const r in t){if(!s(t,r))continue;const o=e?.[r];if(!1===o?.key)continue;const i=t[r];n[r]=o?.key?o.key(i):i}return n}(o,e):e),complete:e=>e?function(e,t){for(const n of t)if(!(n in e))return!1;return!0}(e,n)?e:{...r,...e}:vt(r),get:()=>vt(r),subscribe:e=>function(e,t,n){if(!e)return d;let r;for(const o in e){const i=e[o]?.tracked;i&&(r??(r=[])).push(i.subscribe(e=>{const r=t[o];X(r,e)||(t[o]=e,n(o,r,e))}))}return r?e=>{for(const t of r)t(e)}:d}(o,r,e)}}function bt(e,t,n,r){return(o=t)&&"object"==typeof o&&dt in o?St(e,t.value,n,r,t.key):St(e,t,n,r);var o}function mt(e,t){const n=[];let r,o;function i(e,t=l){return t(wt(e))}const s=e(function(e,t,i){return t?(n.push(n=>e.subscribe(t,n,function(e){return e?{equalityFn:e,isCascadeParticipant:!0}:gt}(i))),t(wt(e))):(r??(r=Xe()),o??(o=new WeakMap),We(e,o,r.trackPath))},t),a=r?Je(s):s;return r&&(r.buildProxySubscriptions((e,t)=>{n.push(n=>e.subscribe(t,n,gt))},!1),r.reset()),o=void 0,{initialValue:a,subscribe(r){const o=()=>r(e(i,t)),s=n.map(e=>e(o));return e=>{for(const t of s)t(e)}}}}function St(e,t,n,r,o){if(function(e){return"function"==typeof e}(t)){const i=mt(t,r);return e[n]=i.initialValue,void 0===o?{tracked:i}:{key:o,tracked:i}}return e[n]=t,void 0===o?null:{key:o}}function vt(e){const t=f();for(const n in e)s(e,n)&&(t[n]=e[n]);return t}function wt(e){return W(e)?e.getSnapshot():e.getState()}var Ot={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},jt=Object.freeze({force:!0}),It=Object.freeze({once:!0}),kt=new Set,Ct=!1;function Ft(e){kt.add(e),Ct||(Ct=!0,queueMicrotask(()=>{Ct=!1,Y(qt)}))}function qt(){for(const e of kt)kt.delete(e),e()}function xt(e,t){return n=>{const r={...n},o=f();for(const e in r)s(r,e)&&e in Ot&&(Ot[e]&&(o[e]=r[e]),delete r[e]);return{...t?t(r):Ce(r),...At(e,null,o)}}}function At(e,t,n){if(!n.queryCache)return n;const r=Date.now(),o=t??(e&&n.queryKey||null),i=f();let a=!1;for(const e in n.queryCache){if(!s(n.queryCache,e))continue;const c=n.queryCache[e];c&&(r-(c.lastFetchedAt??c.errorInfo.lastFailedAt)<c.cacheTime||e===o)?!t&&c.errorInfo&&c.errorInfo.retryCount>0?(i[e]={...c,errorInfo:{...c.errorInfo,retryCount:0}},a=!0):i[e]=c:a=!0}return a?{...n,queryCache:i}:n}function Tt(){return Object.create(null)}function zt(e,t,n){return new y(`[createQueryStore: ${e}]: ${t} failed`,n)}function Et(e){return function(...t){return!0===t[1]?e().setState(t[0],!0):e().setState(t[0])}}exports.DEFAULT_STORAGE_KEY_PREFIX=C,exports.QueryStatuses=E,exports.StoreTags=N,exports.StoresError=y,exports.applyStateUpdate=M,exports.assignStoreTag=H,exports.baseStore=He,exports.configureStores=function(e){t&&function(){if(F)throw new Error("[stores]: configureStores() called after first store creation. Call it earlier before creating any stores.")}(),e.logger&&o(e.logger),O??(O=function(e){return e?.queryStoreDefaults?{queryStoreDefaults:e.queryStoreDefaults}:void 0}(e)),j??(j=T(e))},exports.createStoreActions=function(e,n){const r=function(e){const n=e.getState(),r=f(),o=r;if(t&&("object"!=typeof n||null===n))throw new Error("[createStoreActions]: State is not an object");if(B(e))for(const t in n)G(n,t)&&(o[t]=Q(e,t));else for(const e in n)G(n,e)&&(o[e]=n[e]);return r}(e);return n?Object.assign(r,n):r},exports.deepEqual=function e(t,n){if("object"!=typeof t||null==t||"object"!=typeof n||null==n)return t===n;if(Object.is(t,n))return!0;const r=Object.keys(t);if(r.length!==Object.keys(n).length)return!1;for(const o of r)if(!(o in n)||!e(t[o],n[o]))return!1;return!0},exports.defaultRetryDelay=P,exports.derivedStore=ct,exports.destroyStore=_,exports.destroyStores=function(e,t){for(const n of Array.isArray(e)?e:Object.values(e))n&&!t?.skipDestroy?.(n)&&_(n,t)},exports.ensureError=p,exports.getOptions=q,exports.getStorageConfig=x,exports.getStoreName=function(e){const t="function"==typeof(n=e)?n.name:"";var n;return J(e)?e.persist.getOptions().name??t:t},exports.hasDestroy=U,exports.hasGetSnapshot=W,exports.identity=l,exports.isDerivedStore=function(e){return"flushUpdates"in e},exports.isPersistedStore=J,exports.isQueryStore=V,exports.isVirtualStore=B,exports.markStoreCreated=A,exports.nullObject=f,exports.queryStore=function(e,r,o){A();const i="function"==typeof r?r:Tt,s="object"==typeof r?r:o,a=function(e){return"string"==typeof e?.storageKey}(s)?s:void 0,c=z??(z=function(){const e={abortInterruptedFetches:!0,cacheTime:D.days(7),debugMode:!1,disableAutoRefetching:!1,keepPreviousData:!1,maxRetries:5,minStaleTime:!1,paramChangeThrottle:!1,retryDelay:P,staleTime:D.minutes(2),suppressStaleTimeWarning:!1},t=q()?.queryStoreDefaults;return t?{...e,...t}:e}()),u=c.minStaleTime,{fetcher:l,onError:d,onFetched:g,setData:h,transform:b,abortInterruptedFetches:m=c.abortInterruptedFetches,cacheTime:S=c.cacheTime,debugMode:v=c.debugMode,disableAutoRefetching:w=c.disableAutoRefetching,disableCache:O=!1,enabled:j=!0,keepPreviousData:I=c.keepPreviousData,maxRetries:k=c.maxRetries,paramChangeThrottle:C=c.paramChangeThrottle,params:F,retryDelay:x=c.retryDelay,staleTime:T=c.staleTime,suppressStaleTimeWarning:K=c.suppressStaleTimeWarning}=e;let M="function"==typeof T?c.staleTime:T;t&&!1!==u&&!w&&!K&&M<u&&console.warn(`[createQueryStore${a?.storageKey?`: ${a.storageKey}`:""}] ❌ Stale times under ${u/1e3} seconds are not recommended. Provided staleTime: ${M/1e3} seconds`);const $=new Error("[createQueryStore: AbortError] Fetch interrupted"),R="function"==typeof S,L=t&&v,_=e.params?Object.keys(e.params):[];let U,W=!1,V=[],J=null,B=null,Q=null,G=null,X=null,Y=null,Z=null;const ee={enabled:"function"!=typeof j&&j,error:null,lastFetchedAt:null,queryCache:{},queryKey:"",status:E.Idle},te=new ft(w);function ne(){Q&&(G=null,Q.abort(),Q=null)}function re(){X&&(clearTimeout(X),X=null)}function oe(e,t,n){const r=n.setState;function o(e){const t="function"==typeof e;if(t||void 0!==e.enabled){let n;const o=r(r=>{const o=t?e(r):e,i=void 0!==o.enabled?o.enabled:r.enabled;return i!==r.enabled&&(n=()=>function(e,t){e!==t&&Z!==t&&(Z=t,t&&te.hasSubscribers()?queueMicrotask(()=>c.fetch(void 0,void 0,!0)):(X||m)&&(m&&ne(),re()))}(r.enabled,i)),o});return n?.(),o}return r(e)}function s(e){if(w||M<=0||M===1/0)return;if(!te.hasSubscribers())return;re();const n=t();if(!n.enabled)return;const r=U.buildKey(e),o=(O?Y===r&&n.lastFetchedAt:n.queryCache[r]?.lastFetchedAt)||null,i=o?M-(Date.now()-o):M;X=setTimeout(()=>{t().enabled&&c.fetch(e,jt,!0)},i)}n.setState=o,te.init({onSubscribe:(n,r)=>{const o=t();if(o.enabled)if(n){const t=U.get(),n=U.buildKey(t);o.queryKey!==n&&e({queryKey:n}),o.isStale()?c.fetch(t,void 0,!0):s(t)}else w&&!r&&c.fetch(void 0,void 0,!0)},onLastUnsubscribe:e=>{re(),m&&!e&&ne()}});const c={...i(o,t,n),...ee,async fetch(n,r,i=!1){const u=!!r?.skipStoreUpdates,f=t();if(!u){if(!f.enabled&&!r?.force)return null;if(i&&!te.hasSubscribers())return null}const v=f.error,w=f.queryKey,j=f.status===E.Loading,C=U.complete(n),F=U.buildKey(C);if(j&&G?.promise&&G.key===F)return L&&console.log("[🔄 Using Active Fetch 🔄] for params:",JSON.stringify(C)),G.promise;const q=r?.staleTime??M,A="boolean"==typeof r?.updateQueryKey?r.updateQueryKey:!!i&&I,T=(i||w===F||A)&&!u,z=null!==G;if(m&&T&&ne(),!r?.force){const t=f.lastFetchedAt,n=f.queryCache[F],r=n?.lastFetchedAt,o=n?.errorInfo,i=o&&o.retryCount>=k,a=(O?Y===F&&t:r)||null;if(a&&!(Date.now()-a>=q)&&(!o||i||u))return T&&!X&&0!==M&&M!==1/0&&s(C),A&&e(e=>e.queryKey!==F?{queryKey:F}:e),L&&console.log("[💾 Returning Cached Data 💾] for params:",JSON.stringify(C)),n?.data??null}const D=T?{key:F}:null,P=r?.cacheTime??(R?S(C):S);async function K(){const f=a?.storageKey||F;try{L&&(!i&&n&&_.some(e=>!(e in n))?console.log("[🔄 Fetching with Partial Params 🔄]\n","- Provided params:",`${JSON.stringify(n)}\n`,"- Filled in params:",`${JSON.stringify(Object.fromEntries(Object.keys(C).filter(e=>!(e in n)).map(e=>[e,C[e]])))}`):console.log("[🔄 Fetching 🔄] for params:",JSON.stringify(C)));const t=await(m&&T?async function(e){const t=new AbortController;Q=t;try{return await new Promise((n,r)=>{t.signal.addEventListener("abort",()=>r($),It),Promise.resolve(l(e,t)).then(n,r)})}finally{Q===t&&(Q=null)}}(C):l(C,null)),a=Date.now();let d;L&&console.log("[✅ Fetch Successful ✅] for params:",JSON.stringify(C));try{d=function(e,t,n){return n?n(e,t):e}(t,C,b)}catch(e){throw zt(f,"transform",e)}if(u)return L&&console.log("[🥷 Successful Parallel Fetch 🥷] for params:",JSON.stringify(C)),"withCache"===r.skipStoreUpdates&&e(e=>{if(!h)return O?e:{queryCache:{...e.queryCache,[F]:{cacheTime:P,data:d,errorInfo:null,lastFetchedAt:a}}};let t=e;const n=t.queryCache[F];try{h({data:d,params:C,queryKey:F,set:e=>{t="function"==typeof e?{...t,...e(t)}:{...t,...e}}})}catch(e){throw zt(f,"setData",e)}return!O&&Object.is(n,t.queryCache[F])&&(t={...t,queryCache:{...t.queryCache,[F]:{cacheTime:P,data:null,errorInfo:null,lastFetchedAt:a}}}),t}),d;if((h?o:e)(e=>{let t={...e,error:null,lastFetchedAt:a,queryKey:A?F:e.queryKey,status:E.Success};if(h||O){if(h){L&&console.log("[💾 Setting Data 💾] for params:",JSON.stringify(C));const e=t.queryCache[F];try{h({data:d,params:C,queryKey:F,set:e=>{t="function"==typeof e?{...t,...e(t)}:{...t,...e}}})}catch(e){throw zt(f,"setData",e)}!O&&Object.is(e,t.queryCache[F])&&(t.queryCache={...t.queryCache,[F]:{cacheTime:P,data:null,errorInfo:null,lastFetchedAt:a}})}}else L&&console.log("[💾 Setting Cache 💾] for params:",JSON.stringify(C),"| Has previous data?:",!!t.queryCache[F]?.data),t.queryCache={...t.queryCache,[F]:{cacheTime:P,data:d,errorInfo:null,lastFetchedAt:a}};return O||S===1/0?t:At(I,F,t)}),T&&(Y=F,s(C)),g)try{g({data:d,fetch:c.fetch,params:C,set:o})}catch(e){exports.logger.error(zt(f,"onFetched callback",e))}return d??null}catch(n){if(n===$)return L&&console.log("[❌ Fetch Aborted ❌] for params:",JSON.stringify(C)),null;const o=!i&&!0===r?.throwOnError,s=p(n);if(s instanceof y&&exports.logger.error(s),!T){if(o)throw s;return null}const a=O?void 0:t().queryCache[F],u=a?.errorInfo?.retryCount??0,l=u+1;try{d?.(s,u)}catch(e){exports.logger.error(zt(f,"onError callback",e))}if(u<k){if(t().enabled&&te.hasSubscribers()){const e="function"==typeof x?x(l,s):x;e!==1/0&&(re(),X=setTimeout(()=>{t().enabled&&c.fetch(C,jt,!0)},e))}e(e=>({error:s,queryCache:{...e.queryCache,[F]:{cacheTime:a?.cacheTime??P,data:a?.data??null,lastFetchedAt:a?.lastFetchedAt??null,errorInfo:{error:s,lastFailedAt:Date.now(),retryCount:l}}},queryKey:A?F:e.queryKey,status:E.Error}))}else e(e=>({error:s,queryCache:{...e.queryCache,[F]:{cacheTime:a?.cacheTime??P,data:a?.data??null,lastFetchedAt:a?.lastFetchedAt??null,errorInfo:{error:s,lastFailedAt:Date.now(),retryCount:k}}},queryKey:A?F:e.queryKey,status:E.Error}));if(o)throw s;return null}finally{G===D&&(G=null)}}return D&&(re(),A&&!z&&null===f.lastFetchedAt&&w!==F?e({error:null,queryKey:F,status:E.Loading}):!v&&j||e({error:null,status:E.Loading}),G=D),D?(D.promise=K(),D.promise):K()},getCacheEntry(e){if(O)return null;const n=t(),r=e?"string"==typeof e?e:U.buildKey(U.complete(e)):n.queryKey;return n.queryCache[r]??null},getData(e){if(O)return null;const n=t().getCacheEntry(e);return n&&null!==n.data?I?n.data:n.lastFetchedAt&&Date.now()-n.lastFetchedAt>=n.cacheTime?null:n.data:null},getStatus:function(e){const n=t(),r=n.status;switch(e){case"isIdle":return r===E.Idle;case"isLoading":return r===E.Loading;case"isError":case"isInitialLoad":case"isSuccess":case void 0:{const t=n.queryKey,o=n.queryCache[t],i=O?r===E.Error:"number"==typeof o?.errorInfo?.lastFailedAt;if("isError"===e)return i;const s=null!==((O?Y===t&&n.lastFetchedAt:o?.lastFetchedAt)||null),a=!s&&!i&&n.enabled;if("isInitialLoad"===e)return a;const c=s&&!i;return"isSuccess"===e?c:{isError:i,isIdle:r===E.Idle,isLoading:r===E.Loading,isInitialLoad:a,isSuccess:c}}}},isDataExpired(e){const n=t(),r=n.queryCache[n.queryKey],o=n.queryKey,i=n.lastFetchedAt,s=(O?Y===o&&i:r?.lastFetchedAt)||null;if(!s)return!0;const a=e??r?.cacheTime;return void 0===a||Date.now()-s>=a},isStale(e){const n=t(),r=n.queryKey,o=(O?Y===r&&n.lastFetchedAt:n.queryCache[r]?.lastFetchedAt)||null;if(!o)return!0;const i=e??M;return Date.now()-o>=i},reset(t=!1){for(const e of V)e();V=[],U=ht(void 0,ie,_),J=null,B=null,ne(),re(),G=null,Y=null,t&&e(ee)}},u=n.subscribe;return n.subscribe=(...e)=>{const t=W?void 0:te.subscribe(),n=1===e.length?u(e[0]):u(e[0],e[1],e[2]);return e=>{t?.(e),n()}},c}const ie=a?.storageKey?He(oe,(se=a,void 0===(ae={partialize:xt(I,a.partialize)})?Object.assign(f(),se):Object.assign(f(),se,ae))):s&&!("storageKey"in s)?He(oe,s):He(oe);var se,ae;const ce=ie.getState(),ue=ce.error,le=ce.enabled,fe=ce.queryKey,de=ce.fetch;fe&&!ue&&(Y=fe),W=!0,U=ht(F,ie,_),"function"==typeof j&&(J=mt(j,ie)),"function"==typeof e.staleTime&&(B=mt(e.staleTime,ie),M=B.initialValue);const ye=function(e,t=queueMicrotask){let n,r=!1;function o(){r=!1,e(...n)}return function(...e){n=e,r||(r=!0,t(o))}}(e=>{de(e,void 0,!0)},Ft);function pe(){if(I)ye(void 0);else{const e=U.get();ie.setState({queryKey:U.buildKey(e)}),ye(e)}}const ge=n||!C?void 0:je(pe,"number"==typeof C?C:C.delay,"number"==typeof C?{leading:!1,maxWait:C,trailing:!0}:C);if(V.push(U.subscribe((e,t,n)=>{L&&console.log("[🌀 Param Change 🌀] -",e,"- [Old]:",`${t?.toString()},`,"[New]:",n?.toString()),function(){if(re(),ge){const e=ie.getState();return void(I&&G?.key===e.queryKey&&null===e.lastFetchedAt?pe():ge())}pe()}()})),B){let e=B.initialValue;L&&console.log("[🌀 StaleTime Subscription 🌀] Initial value:",e),V.push(B.subscribe(t=>{t!==e&&(L&&console.log("[🌀 StaleTime Change 🌀] - [Old]:",`${e},`,"[New]:",t),e=t,M=t,re(),de(void 0,void 0,!0))}))}let he;if(J){let e=J.initialValue;le!==e&&((he??(he={})).enabled=e),L&&console.log("[🌀 Enabled Subscription 🌀] Initial value:",e),V.push(J.subscribe(t=>{t!==e&&(L&&console.log("[🌀 Enabled Change 🌀] - [Old]:",`${e},`,"[New]:",t),e=t,ie.setState({enabled:t}))}))}else le!==ee.enabled&&((he??(he={})).enabled=ee.enabled);const be=U.buildKey();return be!==fe&&((he??(he={})).queryKey=be),he&&ie.setState(he),W=!1,H(ie,N.QueryStore)},exports.replacer=R,exports.reviver=L,exports.setLogger=o,exports.shallowEqual=function(e,t){if("object"!=typeof e||null==e||"object"!=typeof t||null==t)return e===t;if(Object.is(e,t))return!0;const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.is(e[r],t[r]))return!1;return!0},exports.time=D,exports.virtualStore=function(e,t,n){const r="function"==typeof t,o=r?t:void 0,i=r?n:t,s=new Set;let a;function c(e,t,n,r){u(e,t,n,r)&&ue()}function u(e,t,n,r){e.unsubscribe();const o=e.args;if(1===o.length){const i=o[0],s=t.subscribe(i);e.unsubscribe=s;const a=!Object.is(r,n);return a&&i(r,n),a}const i=o[0],s=o[1];let a=o[2];a?.fireImmediately&&(a={...a,fireImmediately:!1});const c=i(n),u=i(r),l=t.subscribe(i,s,a);return e.unsubscribe=l,!(a?.equalityFn??Object.is)(c,u)&&(s(u,c),!0)}function l(e,t){!function(e,t){const n=e.getState(),r=t.getState();if(a)for(const e of a)c(e,t,n,r);s.size&&le();for(const e of s)u(e,t,n,r)}(t,e),_(t)}const f=ct(e,{debugMode:i?.debugMode??!1,lockDependencies:i?.lockDependencies??!0});let y;function p(){return y??(y=f.subscribe(l)),f.getState()}var g;return Object.assign({[N.VirtualStore]:!0,destroy:()=>{y?.(),y=void 0,f.destroy()},getInitialState:()=>p().getInitialState(),getState:()=>p().getState(),persist:(g=p,{clearStorage:()=>g().persist?.clearStorage(),getOptions:()=>g().persist?.getOptions()??{},hasHydrated:()=>g().persist?.hasHydrated()??!0,hydrationPromise:()=>g().persist?.hydrationPromise?.()??Promise.resolve(),onFinishHydration:e=>g().persist?.onFinishHydration(e)??d,onHydrate:e=>g().persist?.onHydrate(e)??d,rehydrate:()=>g().persist?.rehydrate(),setOptions:e=>g().persist?.setOptions(e)}),setState:Et(p),subscribe:function(...e){const t=p(),n={args:e,unsubscribe:1===e.length?t.subscribe(e[0]):t.subscribe(e[0],e[1],e[2])},r=e[2]?.isCascadeParticipant??!1;return r?(a??(a=new Set)).add(n):s.add(n),()=>{n.unsubscribe(),r?a?.delete(n)&&0===a.size&&(a=void 0):s.delete(n)}}},o?.(p))};
@@ -1 +1 @@
1
- import{isPlainObject as e,isRecordLike as t,hasOwn as n,isPromiseLike as r,reviver as o,replacer as i}from"../chunk-QJLWBD7M.mjs";export{replacer,reviver}from"../chunk-QJLWBD7M.mjs";import{IS_DEV as s,IS_TEST as a,IS_BROWSER as c,nullObject as u,IS_IOS as l,buildNullObject as f,noop as d,identity as y}from"../chunk-V4LHP7LR.mjs";export{identity,nullObject}from"../chunk-V4LHP7LR.mjs";function h(){return"undefined"!=typeof window?window.localStorage:null}var g={debug:(e,t)=>{s&&console.debug(e,t)},error:(e,t)=>{s&&!a&&console.error(e,t)},info:(e,t)=>{s&&console.info(e,t)},warn:(e,t)=>{s&&console.warn(e,t)}};function p(e){g=e}var m=class extends Error{constructor(e,t){super(e),this.name="StoresError",void 0!==t&&Object.defineProperty(this,"cause",{configurable:!0,value:t,writable:!0})}};function b(e){return e instanceof Error?e:new Error(String(e))}var S,v="stores/core/sync-channel",w=`${v}:storage:`,O=class{constructor(e){this.broadcast=e.broadcast,this.origin=e.origin,this.storeKey=e.storeKey,this.teardown=e.teardown}destroy(){this.teardown()}publish(e){const t=u();for(const n of Object.entries(e.values))t[n[0]]=n[1];const n={origin:this.origin,replace:e.replace,sessionId:e.sessionId,storeKey:this.storeKey,timestamp:e.timestamp,values:t};this.broadcast(n)}},j=class{constructor(){this.listeners=new Map,this.origin="undefined"!=typeof crypto&&"randomUUID"in crypto?crypto.randomUUID():`${Math.random().toString(36).slice(2)}:${Date.now().toString(36)}`,this.onChannelMessage=e=>{e.data&&this.dispatch(e.data)},this.onStorageEvent=e=>{if(e.key&&e.newValue&&e.key.startsWith(w))try{const t=JSON.parse(e.newValue);this.dispatch(t)}catch(e){g.error(new m("[sync] Failed to parse storage event payload",e))}},this.channel="undefined"==typeof BroadcastChannel?null:new BroadcastChannel(v),this.storage=I(),this.channel&&this.channel.addEventListener("message",this.onChannelMessage),c&&window.addEventListener("storage",this.onStorageEvent)}get sessionId(){return this.origin}register(e){const t=t=>{if(t.origin===this.origin||t.storeKey!==e.key)return;const r=u();for(const o of e.fields)n(t.values,o)&&(r[o]=t.values[o]);Object.keys(r).length&&e.apply({replace:t.replace,sessionId:t.sessionId,timestamp:t.timestamp,values:r})};let r=this.listeners.get(e.key);return r||(r=new Set,this.listeners.set(e.key,r)),r.add(t),new O({broadcast:e=>this.broadcast(e),origin:this.origin,storeKey:e.key,teardown:()=>this.removeListener(e.key,t)})}broadcast(e){try{this.channel&&this.channel.postMessage(e),this.writeToStorage(e)}catch(e){g.error(new m("[sync] Failed to broadcast update",e))}}dispatch(e){if(!e.storeKey)return;const t=this.listeners.get(e.storeKey);if(t&&t.size)for(const n of t)n(e)}removeListener(e,t){const n=this.listeners.get(e);n&&(n.delete(t),n.size||this.listeners.delete(e))}writeToStorage(e){if(this.storage||(this.storage=I()),!this.storage)return;const t=`${w}${e.storeKey}`;try{this.storage.setItem(t,JSON.stringify(e))}catch(e){g.error(new m("[sync] Failed to write broadcast payload to storage",e))}}};function I(){try{return"undefined"!=typeof window?window.localStorage:null}catch{return null}}var k,F,C,q=class{destroy(){}publish(){}},T=class{constructor(){this.sessionId="noop"}register(e){return new q}},A="stores:",z=!1;function D(e){s&&function(){if(z)throw new Error("[stores]: configureStores() called after first store creation. Call it earlier before creating any stores.")}(),e.logger&&p(e.logger),F??(F=function(e){return e?.queryStoreDefaults?{queryStoreDefaults:e.queryStoreDefaults}:void 0}(e)),C??(C=K(e))}function E(){if(F)return F}function M(){return C??(C=K(void 0))}function $(){z=!0}function K(e){return{storage:e?.storage??(t=e?.storageKeyPrefix??A,{clearAll(){try{const e=h();if(!e)return;const n=[];for(let r=0;r<e.length;r++){const o=e.key(r);o?.startsWith(t)&&n.push(o)}for(const t of n)e.removeItem(t)}catch(e){console.error("Error clearing localStorage:",e)}},contains(e){const n=h();return null!==n?.getItem(`${t}${e}`)},delete(e){try{const n=h();n?.removeItem(`${t}${e}`)}catch(e){console.error("Error deleting from localStorage:",e)}},getAllKeys(){try{const e=h();return e?Array.from(e.keys()):[]}catch(e){return console.error("Error getting keys from localStorage:",e),[]}},get(e){try{const n=h();return n?n.getItem(`${t}${e}`)??void 0:void 0}catch(e){return void console.error("Error reading from localStorage:",e)}},set(e,n){try{const r=h();r?.setItem(`${t}${e}`,n)}catch(e){console.error("Error writing to localStorage:",e)}}}),syncEngine:e?.syncEngine??(c?(S||(S=new j),S):(k||(k=new T),k))};var t}var P,R={Error:"error",Idle:"idle",Loading:"loading",Success:"success"},x={ms:e=>e,seconds:e=>1e3*e,minutes:e=>6e4*e,hours:e=>36e5*e,days:e=>864e5*e,weeks:e=>6048e5*e,infinity:1/0,zero:0};function L(e,t){const n=t?.baseDelay??x.seconds(5),r=t?.maxDelay??x.minutes(5);return Math.min(n*Math.pow(2,e),r)}function N(e){return JSON.stringify(H(e))}function W(e){return JSON.parse(e)}function H(t){return"object"!=typeof t||null===t?t:Object.keys(t).sort().reduce((n,r)=>{const o=t[r];return n[r]=e(o)?H(o):o,n},u())}function U(e,t){return!0===t[1]?e(t[0],!0):e(t[0])}function J(e,n,r){if(!0===r)return V(n)?n(e):n;const o=V(n)?n(e):n;return Object.is(o,e)?e:t(e)&&t(o)?{...e,...o}:o}function V(e){return"function"==typeof e}var B=Object.freeze({QueryStore:Symbol("queryStore"),VirtualStore:Symbol("virtualStore")});function Q(e,t){return Object.assign(e,{[t]:!0})}function _(e,t){ee(e)?e.getState().reset(t?.clearQueryCache):Y(e)&&e.destroy()}function G(e,t){for(const n of Array.isArray(e)?e:Object.values(e))n&&!t?.skipDestroy?.(n)&&_(n,t)}function X(e){const t="function"==typeof(n=e)?n.name:"";var n;return ne(e)?e.persist.getOptions().name??t:t}function Y(e){return"destroy"in e}function Z(e){return"getSnapshot"in e}function ee(e){return B.QueryStore in e}function te(e){return"flushUpdates"in e}function ne(e){return!(!("persist"in e)||!e.persist)&&"string"==typeof e.persist.getOptions().name}function re(e){return B.VirtualStore in e}function oe(e,t){const n=function(e){const t=e.getState(),n=u(),r=n;if(s&&("object"!=typeof t||null===t))throw new Error("[createStoreActions]: State is not an object");if(re(e))for(const n in t)se(t,n)&&(r[n]=ie(e,n));else for(const e in t)se(t,e)&&(r[e]=t[e]);return n}(e);return t?Object.assign(n,t):n}function ie(e,t){return function(...n){const r=e.getState()[t];if("function"==typeof r)return r(...n);throw new Error(`[createVirtualStoreAction]: Method ${String(t)} is not a function`)}}function se(e,t){return"function"==typeof e[t]}function ae(e,t){if("object"!=typeof e||null==e||"object"!=typeof t||null==t)return e===t;if(Object.is(e,t))return!0;const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!(r in t)||!ae(e[r],t[r]))return!1;return!0}function ce(e,t){if("object"!=typeof e||null==e||"object"!=typeof t||null==t)return e===t;if(Object.is(e,t))return!0;const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.is(e[r],t[r]))return!1;return!0}function ue(e,t){const n=Object.prototype.hasOwnProperty;function r(e,t){for(const n of e.keys())if(ue(n,t))return n}let o,i,s;if(e===t)return!0;if(e&&t&&(o=e.constructor)===t.constructor){if(o===Date)return e.getTime()===t.getTime();if(o===RegExp)return e.toString()===t.toString();if(o===Array){if((i=e.length)===t.length)for(;i--&&ue(e[i],t[i]););return-1===i}if(o===Set){if(e.size!==t.size)return!1;for(let n of e){if(s=n,s&&"object"==typeof s&&(s=r(t,s),!s))return!1;if(!t.has(s))return!1}return!0}if(o===Map){if(e.size!==t.size)return!1;for(let n of e){if(s=n[0],s&&"object"==typeof s&&(s=r(t,s),!s))return!1;if(!ue(n[1],t.get(s)))return!1}return!0}if(o===ArrayBuffer)e=new Uint8Array(e),t=new Uint8Array(t);else if(o===DataView){if((i=e.byteLength)===t.byteLength)for(;i--&&e.getInt8(i)===t.getInt8(i););return-1===i}if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(t)){const n=e,r=t;if((i=n.byteLength)===r.byteLength)for(;i--&&n[i]===r[i];);return-1===i}if(!o||"object"==typeof e){i=0;for(const r in e){if(n.call(e,r)&&++i&&!n.call(t,r))return!1;if(!(r in t)||!ue(e[r],t[r]))return!1}return Object.keys(t).length===i}}return e!=e&&t!=t}function le(e){let t;const n=new Set;function r(...e){const r=J(t,...e);if(Object.is(r,t))return;const o=t;t=r,n.forEach(e=>e(t,o))}function o(){return t}const i={getInitialState:function(){return s},getState:o,setState:r,subscribe:function(...e){return 1===e.length?a(e[0]):function(e,n,r){const o=r?.equalityFn??Object.is;let i=e(t);return r?.fireImmediately&&n(i,i),a(function(t){const r=e(t);if(o(i,r))return;const s=i;i=r,n(r,s)})}(e[0],e[1],e[2])}},s=t=e(r,o,i);return i;function a(e){return n.add(e),()=>{n.delete(e)}}}function fe(e){return{...e,merge:e.merge??de,skipHydration:e.skipHydration??!1}}function de(e,t){return void 0===e?t:{...t,...e}}function ye(){let e,t,n=!1;return{complete:function(){!n&&e&&(n=!0,e(),e=void 0,t=void 0)},isHydrated:function(){return n},fail:function(r){!n&&t&&(n=!0,t(r),t=void 0,e=void 0)},promise:new Promise((n,r)=>{e=n,t=r})}}var he=Math.max,ge=Math.min;function pe(e,t=0,n={}){let r,o,i,s,a,c,u=0,l=!1,f=!1,d=!0;if("function"!=typeof e)throw new TypeError("Expected a function");function y(t){const n=r,i=o;return r=o=void 0,u=t,s=n?e.apply(i,n):e.apply(i),s}function h(e){const n=e-(c??0);return void 0===c||n>=t||n<0||f&&void 0!==i&&e-u>=i}function g(){const e=me();if(h(e))return p(e);a=setTimeout(g,function(e){const n=t-(e-(c??0));return f&&void 0!==i?ge(n,i-(e-u)):n}(e))}function p(e){return a=void 0,d&&r?y(e):(r=o=void 0,s)}function m(...e){const n=me(),i=h(n);if(r=e,o=this,c=n,i){if(void 0===a)return function(e){return u=e,a=setTimeout(g,t),l?y(e):s}(c);if(f)return clearTimeout(a),a=setTimeout(g,t),y(c)}return void 0===a&&(a=setTimeout(g,t)),s}return t=be(t)||0,function(e){const t=typeof e;return null!==e&&("object"===t||"function"===t)}(n)&&(l=!!n.leading,f="maxWait"in n,i=f?he(be(n.maxWait)||0,t):void 0,d="trailing"in n?!!n.trailing:d),m.cancel=function(){void 0!==a&&clearTimeout(a),u=0,r=c=o=a=void 0},m.flush=function(){return void 0===a?s:p(me())},m}function me(){return"undefined"!=typeof performance&&"function"==typeof performance.now?performance.now():Date.now()}function be(e){if("number"==typeof e)return e;if("symbol"==typeof e||void 0===e)return NaN;if("object"==typeof e&&null!==e){const t="function"==typeof e.valueOf?e.valueOf():e;e="object"==typeof t?t+"":t}return"string"!=typeof e?0===e?e:+e:(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)}function Se(t){if(!e(t))return t;const n=u(),r=Object.keys(t);for(let e=0;e<r.length;e++){const o=r[e],i=t[o];"function"!=typeof i&&(n[o]=i)}return n}var ve=a?0:c?x.ms(200):x.seconds(l?3:5);function we(e,t,n,r){const o=!(t.deserializer||t.serializer||e.deserializer||e.serializer),i="object"==typeof t.sync&&!0===(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata),s=t.partialize??Se,a=t.deserializer??e.deserializer??je(o),c=t.serializer??e.serializer??Ie(o);function u(t,n,o){try{if(qe(r))return;const a={state:s(n),version:o},u=Fe(r,i,a),l=c(a);try{e.set(t,l),Ce(r,u)}catch(e){g.error(new m("[createBaseStore]: Failed to persist store data",e))}}catch(e){g.error(new m("[createBaseStore]: Failed to persist store data",e))}}const l=void 0!==n?pe(u,n,{leading:!1,maxWait:n,trailing:!0}):u;return{getItem:t=>{const n=e.get(t);return void 0===n?null:a(n)},setItem:(e,t,n)=>{r?.getIsApplyingRemote()||l(e,t,n)},removeItem:t=>{try{e.delete(t)}catch(e){g.error(new m("[createBaseStore]: Failed to delete persisted store data",e))}}}}function Oe(e,t,n,r){const o=!(t.deserializer||t.serializer||e.deserializer||e.serializer),i="object"==typeof t.sync&&!0===(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata),s=t.partialize??Se,a=t.deserializer??e.deserializer??je(o),c=t.serializer??e.serializer??Ie(o);async function u(t,n,o){try{if(qe(r))return;const a={state:s(n),version:o},u=Fe(r,i,a),l=c(a);try{await e.set(t,l),Ce(r,u)}catch(e){g.error(new m("[createBaseStore]: Failed to persist store data",e))}}catch(e){g.error(new m("[createBaseStore]: Failed to serialize persisted store data",e))}}const l=void 0!==n?pe(u,n,{leading:!1,maxWait:n,trailing:!0}):function(e){let t,n=null;return function(...r){return t=r,n||(n=new Promise(r=>{queueMicrotask(async()=>{try{await e(...t)}finally{n=null,r()}})})),n}}(u);return{getItem:async t=>{const n=await e.get(t);return void 0===n?null:a(n)},setItem:async(e,t,n)=>{if(!r?.getIsApplyingRemote())return await l(e,t,n)},removeItem:async t=>{try{await e.delete(t)}catch(e){g.error(new m("[createBaseStore]: Failed to delete persisted store data",e))}}}}function je(e){return t=>{if("string"!=typeof t)throw new m("[createBaseStore]: Received non-string serialized state without a custom deserializer. Provide a deserializer on the store or storage adapter.");return function(e,t){try{return JSON.parse(e,t?o:void 0)}catch(e){throw g.error(new m("[createBaseStore]: Failed to deserialize persisted store data",e)),e}}(t,e)}}function Ie(e){return t=>function(e,t){try{return JSON.stringify(e,t?i:void 0)}catch(e){throw g.error(new m("[createBaseStore]: Failed to serialize store data",e)),e}}(t,e)}var ke=Object.freeze({shouldClear:!1});function Fe(e,t,n){if(!t||!e)return ke;const r=e.getFieldTimestampSnapshot();return function(e,t){const n=e.getSessionId(),r=e.getTimestamp();void 0!==n&&void 0!==r&&(t.syncMetadata={origin:n,timestamp:r})}(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 Ce(e,t){e&&t.shouldClear&&t.fieldSnapshot&&Object.keys(t.fieldSnapshot).length&&e.clearFieldTimestamps(t.fieldSnapshot)}function qe(e){return!!e&&!!e.getIsApplyingRemote()}var[Te,Ae]=[0,1];function ze(e,t,n){if(!e)return!0;const r=e[Te],o=e[Ae];return!(t<r)&&(t>r||n>o)}function De(e,t){return Object.prototype.hasOwnProperty.call(t,e)}function Ee(e,t){if(!s)return!0;if(null===e||null===t)return e===t;const n=typeof e;return n===typeof t&&("object"!==n||Object.prototype.toString.call(e)===Object.prototype.toString.call(t))}function Me(e){if(null===e)return"null";const t=typeof e;return"object"===t?Object.prototype.toString.call(e):t}function $e(e,t){if($(),!t)return le(e);const n=t.storageKey,o="string"==typeof n,i=o?t.storage??M().storage:void 0,s=function(e,t){if(!e)return null;const n="object"==typeof e,r=n?e.key??t:!0===e?t:e;if(!r)throw new m("[createBaseStore]: sync requires a key to be specified either directly or via storageKey");return n?{...e,key:r}:{key:r}}(t.sync,n),a=s?function(e,t,n){const o=t.engine??M().syncEngine,i=function(e){let t,n,r,o=!1;return{isAsync:e,clearFieldTimestamps:function(e){if(e&&r){for(const t of Object.entries(e)){const e=t[0],n=t[1];r[e]===n&&delete r[e]}Object.keys(r).length||(r=void 0)}},getFieldTimestampSnapshot:function(){if(r)return{...r}},getIsApplyingRemote:()=>o,getSessionId:()=>t,getTimestamp:()=>n,mergeFieldTimestamps:function(e){if(r)for(const t of Object.entries(e)){const e=t[0],n=t[1],o=r[e];(void 0===o||n>o)&&(r[e]=n)}else r={...e}},onHydrationComplete:void 0,onHydrationFlushEnd:void 0,setIsApplyingRemote:e=>o=e,setSessionId:e=>t=e,setTimestamp:e=>n=e,setWithoutPersist:void 0}}(n);return{stateCreator:(s,a,c)=>{const l=new Map,f=[],d=[];let y=null,h=!1,p=!1,b=0,S=null,v=[],w=Promise.resolve(),O=!n;function j(e,t){if(i?.setSessionId&&i?.setTimestamp&&o.sessionId&&(i.setSessionId(o.sessionId),i.setTimestamp(e),i.mergeFieldTimestamps&&t.length>0)){const n=u();for(const r of t)n[String(r)]=e;i.mergeFieldTimestamps(n)}}function I(e,t){if(h||!S)return t?s(e,t):s(e);const n=function(){const e=Date.now(),t=e>b?e:b+1;return b=t,t}();let i=[],a=u();const c=r=>{const o=J(r,e,t);for(const e of v)Object.is(o[e],r[e])||(i.push(e),a[e]=o[e]);return i.length&&j(n,i),o},f=t?s(c,!0):s(c);function g(){i.length&&function(e){const t=o.sessionId;for(const n of e.keys)l.set(n,[e.timestamp,t]);y&&p?y.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values}):d.push(e)}({keys:i,replace:t??!1,values:a,timestamp:n})}return r(f)?f.finally(g):(g(),f)}const k=c.setState;c.setState=I;const F=e(I,a,c);if(v=t.fields??function(e){const t=[];for(const n of Object.entries(e)){if("function"==typeof n[1])continue;const e=n[0];t.push(e)}return t}(F),!v.length)return F;async function C(e){b=Math.max(b,e.timestamp);const n=u(),r=a(),o=e.timestamp;let s;if(e.replace)for(const t of v)De(t,e.values)||ze(l.get(t),o,e.sessionId)&&(s??(s=[])).push(t);for(const i of v){if(!De(i,e.values))continue;if(!S?.has(i))continue;if(!ze(l.get(i),o,e.sessionId))continue;const s=t.merge?.[i];if(s){const t=e.values[i],a=r[i];if(void 0!==t){const c=s(t,a,r,e.values),u=void 0!==a?a:t;if(!Ee(c,u))return void g.error(new m(`[sync] Merge function for field "${String(i)}" returned ${Me(c)} but expected ${Me(u)}`));n[i]=c,l.set(i,[o,e.sessionId])}}else n[i]=e.values[i],l.set(i,[o,e.sessionId])}if(Object.keys(n).length>0||s?.length){h=!0,i&&i.setIsApplyingRemote(!0);try{if(e.replace){const e={...r};let t=!1;if(s?.length){t=!0;for(const t of s)delete e[t],l.delete(t)}for(const r in n){if(!Object.prototype.hasOwnProperty.call(n,r))continue;const o=n[r];void 0!==o&&(Object.is(e[r],o)||(t=!0),e[r]=o)}if(!t)return;await(i.setWithoutPersist??k)(e,!0)}else await(i.setWithoutPersist??k)(n)}finally{h=!1,i&&i.setIsApplyingRemote(!1)}}}function q(e){n?w=w.then(()=>C(e)):C(e)}if(S=new Set(v),y=o.register({apply:e=>{O?q(e):f.push(e)},fields:v,getState:a,key:t.key}),y?.onFirstSubscribe||y?.onLastUnsubscribe){let e=0;const t=c.subscribe;c.subscribe=(...n)=>{e||y.onFirstSubscribe?.(),e+=1;const r=1===n.length?t(n[0]):t(n[0],n[1],n[2]);return()=>{r(),e-=1,e||queueMicrotask(()=>{e||y.onLastUnsubscribe?.()})}}}function T(){p=!0,function(){if(y&&d.length){for(const e of d){const t=o.sessionId;for(const n of e.keys)l.set(n,[e.timestamp,t]);j(e.timestamp,e.keys),y.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values})}d.length=0}}()}function A(){O=!0,function(){if(!f.length)return;const e=f.slice();f.length=0;for(const t of e)q(t)}()}return n?(i.onHydrationComplete=T,i.onHydrationFlushEnd=A):y.onHydrated?(y.onHydrated(T),A()):(T(),A()),F},syncContext:i}}(e,s,i?.async??!1):void 0,c=a?.stateCreator??e;if(!o)return le(c);const l=function(e,t,n){const r=t??e.storage??M().storage,o=(e.sync?void 0:e.persistThrottleMs??ve)||void 0,i=e.version??0;return r.async?{async:!0,persistStorage:Oe(r,e,o,n),version:i}:{async:!1,persistStorage:we(r,e,o,n),version:i}}(t,i,a?.syncContext),f=l.async?function(e){let t,n,r,o=!1;return{hydrationPromise:()=>o?t?.promise??n??(n=Promise.resolve()):(t||(t=ye()),t.promise),stateCreator:(n,i,s)=>{let a;return r=()=>{if(a?.length){for(const e of a)U(s.setState,e);a=void 0}},e(function(...e){return o?U(n,e):(t||(t=ye()),a||(a=[]),a.push(e),t.promise)},i,s)},wrapOnRehydrateStorage:(e,n)=>i=>{const s=e?.(i);return(e,i)=>{o=!0,n?.onHydrationComplete?.(),r&&r(),n?.onHydrationFlushEnd?.(),i?t?.fail(b(i)):t?.complete(),s?.(e,i)}}}}(c):void 0,d=f?f.wrapOnRehydrateStorage(t.onRehydrateStorage,a?.syncContext):t.onRehydrateStorage,y=le(function(e,t){return(n,o,i)=>{let s,a,c,u=fe(t),l=!1,f=0;function d(){return u.storage.setItem(u.name,o(),u.version)}const y=i.setState;i.setState=function(...e){return U(y,e),d()};const h=e(function(...e){return U(n,e),d()},o,i);function g(){const e=function(){const e=++f;return l=!1,a?.forEach(e=>e(o()??h)),e}(),t=u.onRehydrateStorage?.(o()??h);try{const n=u.storage.getItem(u.name);return r(n)?n.then(n=>p(e,n,t)).catch(n=>S(e,t,n)):p(e,n,t)}catch(n){S(e,t,n)}}return i.getInitialState=()=>h,Object.assign(i,{persist:{clearStorage:()=>{u.storage.removeItem(u.name)},getOptions:()=>u,hasHydrated:()=>l,onFinishHydration:e=>(c??(c=new Set),c.add(e),()=>{c?.delete(e),0===c?.size&&(c=void 0)}),onHydrate:e=>(a??(a=new Set),a.add(e),()=>{a?.delete(e),0===a?.size&&(a=void 0)}),rehydrate:g,setOptions:e=>{u=fe({...u,...e,storage:e.storage??u.storage})}}}),u.skipHydration||g(),s??h;function p(e,t,n){const o=function(e,t){if(!t)return{migrated:!1,state:void 0};if("number"!=typeof t.version||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"),{migrated:!1,state:void 0};const n=e.migrate(t.state,t.version);return r(n)?n.then(e=>({migrated:!0,state:e})):{migrated:!0,state:n}}(u,t);return r(o)?o.then(t=>m(e,t,n)).catch(t=>S(e,n,t)):m(e,o,n)}function m(e,t,i){const a=function(e,t){if(e!==f)return;const r=u.merge(t.state,o()??h);return s=r,n(r,!0),t.migrated?d():void 0}(e,t);if(r(a))return a.then(()=>b(e,i));b(e,i)}function b(e,t){if(e!==f)return;t?.(s,void 0);const n=o();s=n,l=!0,c?.forEach(e=>e(n))}function S(e,t,n){e===f&&t?.(void 0,n)}}}(f?(e,t,n)=>(a&&(a.syncContext.setWithoutPersist=n.setState),f.stateCreator(e,t,n)):c,{merge:t.merge,migrate:t.migrate,name:n,onRehydrateStorage:d,storage:l.persistStorage,version:l.version}));return f?Object.assign(y,{persist:Object.assign(y.persist,{hydrationPromise:f.hydrationPromise})}):y}function Ke(e,t,n="s"){return 1===t?e:`${e}${n}`}var Pe=!1,Re=!1,xe=new Map,Le=new Map,Ne=new Map,We=null,He=1/0;function Ue(){return Pe}function Je(){return We}function Ve(){Pe||(Pe=!0,Re||(Re=!0,queueMicrotask(()=>{Re=!1,(()=>{for(;Le.size>0;){const e=He,t=Ne.get(e);if(t){Ne.delete(e);for(const e of t)Le.delete(e);We=e;for(const e of t)e();if(We=null,Ne.size>0){He=1/0;for(const e of Ne.keys())e<He&&(He=e)}else He=1/0}else{He=1/0;for(const e of Ne.keys())e<He&&(He=e)}}for(;xe.size>0;){const e=Array.from(xe.values());xe.clear();for(const t of e)t()}})(),Pe=!1,We=null,Le.clear(),Ne.clear(),He=1/0})))}function Be(e,t){Pe&&xe.set(e,t)}var Qe=Symbol("stores.deriveProxy.unwrap");function _e(e,t,n){const r=t.get(e);if(void 0!==r)return r;const o=function(e,t,n,r=[]){return e&&"object"==typeof e?Ge(e,r,t,n,new WeakSet,new WeakMap):(n(t,r,!0),e)}(Z(e)?e.getSnapshot():e.getState(),e,n);return t.set(e,o),o}function Ge(e,t,n,r,o,i){return new Proxy(e,{get(s,a,c){if(a===Qe)return r(n,t,!0),s;if(o.has(s))return Reflect.get(s,a,c);if("__proto__"===a||"symbol"==typeof a)return a===Symbol.iterator&&(r(n,t,!0),o.add(s)),Reflect.get(s,a,c);const u=Reflect.get(s,a,s),l=String(a),f=t.concat(l);if("function"==typeof u)return Object.prototype.hasOwnProperty.call(s,a)?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));const d=!!u&&"object"==typeof u;return r(n,f,!d),d?(i.has(u)||i.set(u,Ge(u,f,n,r,o,i)),i.get(u)):u},getOwnPropertyDescriptor:(e,i)=>(r(n,t,!0),o.add(e),Reflect.getOwnPropertyDescriptor(e,i)),has:(e,o)=>(r(n,t,!0),Reflect.has(e,o)),ownKeys:e=>(r(n,t,!0),o.add(e),Reflect.ownKeys(e))})}function Xe(t,n){if(!t||"object"!=typeof t)return t;const r=function(e){const t=Reflect.get(e,Qe);return t&&"object"==typeof t?t:void 0}(t);return r||(Array.isArray(t)?function(e,t){const n=Ze(e,t);if(n)for(let t=0;t<e.length;t++)Ye(e,String(t),n)}(t,n):e(t)&&function(e,t){const n=Ze(e,t);if(n)for(const t of Reflect.ownKeys(e))Ye(e,t,n)}(t,n),t)}function Ye(e,t,n){const r=Reflect.getOwnPropertyDescriptor(e,t);if(!r||!("value"in r))return;const o=Xe(r.value,n);o!==r.value&&(r.value=o,Reflect.defineProperty(e,t,r))}function Ze(e,t){const n=t??new WeakSet;return n.has(e)?null:(n.add(e),n)}var et=Object.freeze([]);function tt(){const e=new Map;return{buildProxySubscriptions(t,n,r,o){const i=new Set;for(const t of e)ot(t[1],t[0],[],0,i,r);!1!==o?.(i)&&function(e,t,n){for(const n of e){const e=n.invocation?ct(n.path,n.invocation):at(n.path);t(n.store,e,n.path)}n&&function(e){const t=e.size;console.log(`[📡 ${t} ${Ke("Proxy Subscription",t)} 📡]:`,JSON.stringify(Array.from(e).map(e=>{const t="name"in(n=e.store)&&"string"==typeof n.name?n.name:"store";var n;const r=e.path.join(".");if(!e.invocation)return r?`$(${t}).${r}`:`$(${t})`;const o=e.invocation.args?.length??0;return`$(${t}).${r}${o?`(${o}_${Ke("arg",o)})`:"()"}`}),null,2))}(e)}(i,t,n)},reset(){e.clear()},trackPath(t,n,r,o){let i=e.get(t);i||(i=nt(),e.set(t,i)),rt(i,n,0,r,o)}}}function nt(){return u()}function rt(e,t,n,r,o){if(n===t.length)return r&&(e.isLeaf=!0),void(o&&function(e,t){const n=e.invocation;if(!n)return void(e.invocation=t);if(it(n,t))return;const r=e.extraInvocations;if(r){for(let e=0;e<r.length;e++)if(it(r[e],t))return;r.push(t)}else e.extraInvocations=[t]}(e,o));e.children||(e.children=nt());const i=t[n];let s=e.children?.[i];s||(s=nt(),e.children[i]=s),rt(s,t,n+1,r,o)}function ot(e,t,n,r,o,i=2){const s=e.children;if(!s)return void st(e,t,n,o);const a=Object.keys(s),c=a.length;if(0!==c)if(e.isLeaf||r>=i&&c>1){st(e,t,n,o);for(const e of a){const a=s[e];a.invocation&&ot(a,t,[...n,e],r+1,o,i)}}else if(r<i&&c>1&&!e.isLeaf)for(const e of a)ot(s[e],t,[...n,e],r+1,o,i);else{if(1===c){const e=a[0];return void ot(s[e],t,[...n,e],r+1,o,i)}st(e,t,n,o)}else st(e,t,n,o)}function it(e,t){const n=e.args,r=t.args,o=n?.length??0;if(o!==(r?.length??0))return!1;if(!n||!r)return!0;for(let e=0;e<o;e++)if(!Object.is(n[e],r[e]))return!1;return!0}function st(e,t,n,r){const o=e.isLeaf??!1,i=e.invocation;if(!i)return void r.add({store:t,path:n,isLeaf:o});r.add({store:t,path:n,invocation:i,isLeaf:o});const s=e.extraInvocations;if(s)for(let e=0;e<s.length;e++)r.add({store:t,path:n,invocation:s[e],isLeaf:o})}function at(e){return t=>ut(t,e)}function ct(e,t){const n=e.slice(0,-1),r=e[e.length-1];return e=>{const o=ut(e,n),i=o&&"object"==typeof o?Reflect.get(o,r):void 0;return"function"==typeof i?Reflect.apply(i,o,t.args??et):void 0}}function ut(e,t){let n=e;for(const e of t){if(!n||"object"!=typeof n)return n;n=Reflect.get(n,e)}return n}var lt=Symbol(),ft=Object.freeze({equalityFn:Object.is,isDerivedStore:!0});function dt(e,t=Object.is){const{debounceOptions:n,debugMode:r,equalityFn:o,keepAlive:i,lockDependencies:a}="function"==typeof(l=t)?{debounceOptions:void 0,debugMode:!1,equalityFn:l,keepAlive:!1,lockDependencies:!1}:{debounceOptions:l.debounce,debugMode:(s&&l.debugMode)??!1,equalityFn:l.equalityFn??Object.is,keepAlive:l.keepAlive??!1,lockDependencies:l.lockDependencies??!1},c=String(yt+=1),u=new Set;var l;i&&u.add(ht);const f=new Set;let d,h,g=lt,p=!1,m=!0,b=!0,S=0,v=!1,w=null,O=lt;function j(e,t,n){return b&&u.size?t?(f.add(e.subscribe(t,M,n?{equalityFn:n,isDerivedStore:!0}:ft)),t(Z(e)?e.getSnapshot():e.getState())):(d||(d=new WeakMap),h||(h=tt()),_e(e,d,h.trackPath)):(t??y)(Z(e)?e.getSnapshot():e.getState())}function I(e){for(const t of f)t(e);f.clear()}let k=!0;function F(){if(!m&&gt(g))return g;m=!1,b&&I(!0);const t=g,n=gt(t);g=function(t){k=!0;const n=g,i=e(t),s=h?Xe(i):i;return gt(n)&&o(n,s)?(r&&console.log("[🥷 Derive Complete 🥷]: No change detected"),k=!1,n):s}(j);const i=r&&(!n||"verbose"===r&&b);if(i){n?"verbose"===r&&console.log("[🌀 Rebuilding Subscriptions 🌀]: Created…"):console.log("[🌀 Initial Derive Complete 🌀]: Created…");const e=f.size;console.log(`[🎯 ${e} ${Ke("Selector Subscription",e)} 🎯]`)}return h&&b&&(h.buildProxySubscriptions((e,t)=>{f.add(e.subscribe(t,M,ft))},i),d=void 0,h.reset(),a&&(h=void 0)),k&&n&&function(e,t){const n=function(){const e=u.has(ht)?u.size-1:u.size;return S>0&&S<e}(),o=!S||n,i=n||null!==Je()||Ue()&&o;n&&Ve(),r&&console.log(`[📻 Derive Complete 📻]: Notifying ${u.size} ${Ke("watcher",u.size)}`);for(const t of u){if("function"==typeof t||!t.isDerivedWatcher)continue;const n=t.selector(e);if(!t.equalityFn(t.currentSlice,n)){const e=t.currentSlice;t.currentSlice=n,t.listener(n,e)}}i?v||(v=!0,gt(O)||(O=t),Be(c,q)):C(e,t)}(g,t),a&&(b=!1),g}function C(e,t){for(const n of u)if("function"==typeof n)n(e,t);else if(!n.isDerivedWatcher){const t=n.selector(e);if(!n.equalityFn(n.currentSlice,t)){const e=n.currentSlice;n.currentSlice=t,n.listener(t,e)}}}function q(){if(!u.size)return;if(m&&!S&&F(),!gt(g))return;const e=gt(O)?O:g;C(g,e),v=!1,O=lt}const T=n?pe(z,"number"==typeof n?n:n.delay,"number"==typeof n?{leading:!1,maxWait:n,trailing:!0}:n):void 0,A=T??(()=>{p||(p=!0,queueMicrotask(z))});function z(){p=!1,u.size?m&&F():K()}function D(e){e||T&&m?queueMicrotask(()=>{u.size||K()}):K()}function E(){z(),w=null}function M(){if(!m){if(m=!0,!T){if(S){Ve();const e=Je(),t=null===e?0:e+1;if(null!==w&&t<=w)return;return w=t,void function(e,t){if(!Pe)return;const n=t<0?0:0|t,r=Le.get(e);if(void 0===r){Le.set(e,n);let t=Ne.get(n);return t||(t=new Set,Ne.set(n,t)),t.add(e),void(n<He&&(He=n))}if(n>r){const t=Ne.get(r);if(t&&(t.delete(e),0===t.size&&(Ne.delete(r),r===He))){He=1/0;for(const e of Ne.keys())e<He&&(He=e)}Le.set(e,n);let o=Ne.get(n);o||(o=new Set,Ne.set(n,o)),o.add(e),n<He&&(He=n)}}(E,t)}if(Ue())return void(v||(v=!0,gt(g)&&(O=g),Be(c,q)))}w=null,A()}}function $(){return m||!gt(g)?u.size>0?F():e(j):g}function K(e=!0){i&&e||(T?.cancel(),I(),u.clear(),S=0,h=void 0,d=void 0,b=!0,p=!1,m=!0,g=lt,v=!1,O=lt,w=null)}return{destroy:()=>K(!1),flushUpdates:function(){u.size&&(T?T.flush():m&&F())},getSnapshot:function(){if(!gt(g)){u.add(ht);const e=F();return u.delete(ht),e}return p&&z(),g},getState:$,subscribe:function(...e){if(1===e.length){const t=e[0];return u.add(t),1!==u.size||gt(g)||$(),()=>{u.delete(t),u.size||D(!1)}}const[t,n,r]=e,o=r?.equalityFn??Object.is,i=r?.isDerivedStore??!1,s={currentSlice:void 0,equalityFn:o,isDerivedWatcher:i,listener:n,selector:t};return u.add(s),s.currentSlice=t($()),i&&(S+=1),r?.fireImmediately&&n(s.currentSlice,s.currentSlice),()=>{u.delete(s),i&&(S-=1),u.size||D(i)}},getInitialState:()=>{throw new Error("[createDerivedStore]: getInitialState() is not available on derived stores.")},setState:()=>{throw new Error("[createDerivedStore]: setState() is not available on derived stores.")}}}var yt=0;function ht(){}function gt(e){return e!==lt}var pt=class{constructor({disableAutoRefetching:e,initialEnabled:t}){this.count=0,this.enabled=!1,this.lastSubscriptionTime=null,this.fetchThrottleMs=null,this.onSubscribe=null,this.onLastUnsubscribe=null,this.enabled=t,e&&(this.fetchThrottleMs=x.seconds(5))}init({onSubscribe:e,onLastUnsubscribe:t}){this.onSubscribe=e,this.onLastUnsubscribe=t}get(){return{enabled:this.enabled,lastSubscriptionTime:this.lastSubscriptionTime,subscriptionCount:this.count}}setEnabled(e){this.enabled=e}subscribe(){const e=0===this.count,t=null!==this.fetchThrottleMs&&null!==this.lastSubscriptionTime&&!e&&Date.now()-this.lastSubscriptionTime<=this.fetchThrottleMs;return this.onSubscribe?.(this.enabled,e,t),this.count+=1,this.lastSubscriptionTime=Date.now(),e=>{const t=1===this.count;this.count=Math.max(this.count-1,0),t&&(this.onLastUnsubscribe?.(e),this.lastSubscriptionTime=null)}}},mt=new WeakMap,bt=new WeakMap;function St(e,t=vt,n=ue){return function(e,t,n){let r=bt.get(e);r||(r=new Map,bt.set(e,r));let o=r.get(t);o||(o=new Map,r.set(t,o));const i=o.get(n);if(i)return i;const[s,a,c]=Ot(e,t,n),l=new Map,f=e=>{const t={get(t,n){if("value"===n){let t=a();const n=e.split(".");for(const e of n)e&&(t=t[e]);return t}const r="string"==typeof n?n:n.toString(),o=e?`${e}.${r}`:r,i=l.get(o);if(i)return i;const c=f(o);return mt.set(c,s),l.set(o,c),c},set(t,n,r){const o=e.split(".");return""===o[0]&&o.shift(),c(o,r),!0}};return new Proxy(u(),t)},d=f("");return s(()=>{}),mt.set(d,s),o.set(n,d),d}(e,t,n)}var vt=e=>e,wt=(e,t,n)=>{if(!t.length)return n;const[r,...o]=t,i=e[r],s=wt(i,o,n);if(ue(i,s))return e;const a=Array.isArray(e)?e.slice():{...e};return a[r]=s,a},Ot=(e,t,n)=>{const r=new Set,o=Z(e);let i,s=t(o?e.getSnapshot():e.getState());return[a=>(r.size||(i=e.subscribe(t,e=>{s=e,r.forEach(e=>e())},{equalityFn:n,isDerivedStore:o})),r.add(a),()=>{r.delete(a),!r.size&&i&&(i(),i=void 0)}),()=>(r.size||(s=t(e.getState())),s),(n,r)=>{if(t!==vt)throw new Error("Cannot set a value with a selector");e.setState(e=>wt(e,n,r),!0)}]};function jt(e){return mt.get(e)}var It={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},kt=Object.freeze({force:!0}),Ft=Object.freeze({once:!0}),Ct=Object.freeze({updateQueryKey:!0});function qt(e,t,r){$();const o="function"==typeof t?t:Kt,i="object"==typeof t?t:r,c=function(e){return"string"==typeof e?.storageKey}(i)?i:void 0,l=P??(P=function(){const e={abortInterruptedFetches:!0,cacheTime:x.days(7),debugMode:!1,disableAutoRefetching:!1,keepPreviousData:!1,maxRetries:5,minStaleTime:!1,paramChangeThrottle:!1,retryDelay:L,staleTime:x.minutes(2),suppressStaleTimeWarning:!1},t=E()?.queryStoreDefaults;return t?{...e,...t}:e}()),d=l.minStaleTime,{fetcher:y,onError:h,onFetched:p,setData:S,transform:v,abortInterruptedFetches:w=l.abortInterruptedFetches,cacheTime:O=l.cacheTime,debugMode:j=l.debugMode,disableAutoRefetching:I=l.disableAutoRefetching,disableCache:k=!1,enabled:F=!0,keepPreviousData:C=l.keepPreviousData,maxRetries:q=l.maxRetries,paramChangeThrottle:T=l.paramChangeThrottle,params:A,retryDelay:z=l.retryDelay,staleTime:D=l.staleTime,suppressStaleTimeWarning:M=l.suppressStaleTimeWarning}=e;let K="function"==typeof D?l.staleTime:D;s&&!1!==d&&!I&&!M&&K<d&&console.warn(`[createQueryStore${c?.storageKey?`: ${c.storageKey}`:""}] ❌ Stale times under ${d/1e3} seconds are not recommended. Provided staleTime: ${K/1e3} seconds`);const W=new Error("[createQueryStore: AbortError] Fetch interrupted"),H="function"==typeof O,U=s&&j,J=e.params?Object.keys(e.params):[];let V=null,_=null,G=null,X=[],Y=!1,Z=!1,ee=null,te=null,ne=null,re=null,oe=null;const ie={enabled:"function"!=typeof F&&F,error:null,lastFetchedAt:null,queryCache:{},queryKey:"",status:R.Idle},se=new pt({disableAutoRefetching:I,initialEnabled:ie.enabled});function ae(){ee&&(te=null,ee.abort(),ee=null)}function ce(t,n,r){const i=r.setState;function s(e){const t="function"==typeof e;if(t||void 0!==e.enabled){let n;const r=i(r=>{const o=t?e(r):e,i=void 0!==o.enabled?o.enabled:r.enabled;return i!==r.enabled&&(n=()=>function(e,t){e!==t&&oe!==t&&(oe=t,se.setEnabled(t),t?queueMicrotask(()=>u.fetch(void 0,Ct)):(ne||w)&&(w&&ae(),ne&&(clearTimeout(ne),ne=null)))}(r.enabled,i)),o});return n?.(),r}return i(e)}function a(e,t){if(I||t?.skipStoreUpdates)return;if(K<=0||K===1/0)return;ne&&(clearTimeout(ne),ne=null);const r=N(e),o=n(),i=(k?re===r&&o.lastFetchedAt:o.queryCache[r]?.lastFetchedAt)||null,s=i?K-(Date.now()-i):K;ne=setTimeout(()=>{const t=se.get();t.enabled&&t.subscriptionCount>0&&u.fetch(e,kt,!0)},s)}r.setState=s,se.init({onSubscribe:(r,o,i)=>{if(_||V||!A&&"function"!=typeof e.enabled&&"function"!=typeof e.staleTime){if(r)if(o){const e=At(V,_),r=N(e),o=n();o.queryKey!==r&&t({queryKey:r}),o.isStale()?u.fetch(e,void 0,!0):a(e,void 0)}else I&&!i&&u.fetch(void 0,void 0,!0)}else Y=!0},onLastUnsubscribe:e=>{ne&&(clearTimeout(ne),ne=null),w&&!e&&ae()}});const u={...o(s,n,r),...ie,async fetch(e,r,o=!1){const i=se.get();if(!r?.force&&!r?.skipStoreUpdates&&!i.enabled)return null;const l=n(),f=l.error,d=l.queryKey,j=l.status===R.Loading,I=Tt(V,_,J,e),F=N(I);if(j&&te?.promise&&te.key===F)return U&&console.log("[🔄 Using Active Fetch 🔄] for params:",JSON.stringify(I)),te.promise;const T=r?.staleTime??K,A=!!r?.skipStoreUpdates,D="boolean"==typeof r?.updateQueryKey?r.updateQueryKey:!!o&&C,E=(o||d===F||D)&&!A;if(w&&E&&ae(),!r?.force){const e=l.lastFetchedAt,n=l.queryCache[F],o=n?.lastFetchedAt,s=n?.errorInfo,c=s&&s.retryCount>=q,u=(k?re===F&&e:o)||null;if(u&&!(Date.now()-u>=T)&&(!s||c||A))return E&&!ne&&i.subscriptionCount>0&&0!==K&&K!==1/0&&a(I,r),D&&t(e=>e.queryKey!==F?{queryKey:F}:e),U&&console.log("[💾 Returning Cached Data 💾] for params:",JSON.stringify(I)),n?.data??null}E&&(ne&&(clearTimeout(ne),ne=null),!f&&j||t({error:null,status:R.Loading}),te={key:F});const M=r?.cacheTime??(H?O(I):O);async function $(){const i=c?.storageKey||F;try{U&&(o||!e||zt(e,J)?console.log("[🔄 Fetching 🔄] for params:",JSON.stringify(I)):console.log("[🔄 Fetching with Partial Params 🔄]\n","- Provided params:",`${JSON.stringify(e)}\n`,"- Filled in params:",`${JSON.stringify(Object.fromEntries(Object.keys(I).filter(t=>!(t in e)).map(e=>[e,I[e]])))}`));const n=await(w&&E?async function(e){const t=new AbortController;ee=t;try{return await new Promise((n,r)=>{t.signal.addEventListener("abort",()=>r(W),Ft),Promise.resolve(y(e,t)).then(n,r)})}finally{ee===t&&(ee=null)}}(I):y(I,null)),c=Date.now();let l;U&&console.log("[✅ Fetch Successful ✅] for params:",JSON.stringify(I));try{l=function(e,t,n){return n?n(e,t):e}(n,I,v)}catch(e){throw Pt(i,"transform",e)}if(A)return U&&console.log("[🥷 Successful Parallel Fetch 🥷] for params:",JSON.stringify(I)),"withCache"===r.skipStoreUpdates&&t(e=>{if(!S)return k?e:{queryCache:{...e.queryCache,[F]:{cacheTime:M,data:l,errorInfo:null,lastFetchedAt:c}}};let t=e;const n=t.queryCache[F];try{S({data:l,params:I,queryKey:F,set:e=>{t="function"==typeof e?{...t,...e(t)}:{...t,...e}}})}catch(e){throw Pt(i,"setData",e)}return!k&&Object.is(n,t.queryCache[F])&&(t={...t,queryCache:{...t.queryCache,[F]:{cacheTime:M,data:null,errorInfo:null,lastFetchedAt:c}}}),t}),l;if((S?s:t)(e=>{let t={...e,error:null,lastFetchedAt:c,queryKey:D?F:e.queryKey,status:R.Success};if(S||k){if(S){U&&console.log("[💾 Setting Data 💾] for params:",JSON.stringify(I));const e=t.queryCache[F];try{S({data:l,params:I,queryKey:F,set:e=>{t="function"==typeof e?{...t,...e(t)}:{...t,...e}}})}catch(e){throw Pt(i,"setData",e)}!k&&Object.is(e,t.queryCache[F])&&(t.queryCache={...t.queryCache,[F]:{cacheTime:M,data:null,errorInfo:null,lastFetchedAt:c}})}}else U&&console.log("[💾 Setting Cache 💾] for params:",JSON.stringify(I),"| Has previous data?:",!!t.queryCache[F]?.data),t.queryCache={...t.queryCache,[F]:{cacheTime:M,data:l,errorInfo:null,lastFetchedAt:c}};return k||O===1/0?t:$t(C,F,t)}),E&&(re=F,a(I,r)),p)try{p({data:l,fetch:u.fetch,params:I,set:s})}catch(e){g.error(Pt(i,"onFetched callback",e))}return l??null}catch(s){if(s===W)return U&&console.log("[❌ Fetch Aborted ❌] for params:",JSON.stringify(I)),null;const a=!o&&!0===r?.throwOnError,c=b(s);if(c instanceof m&&g.error(c),!E){if(a)throw c;return null}const l=k?void 0:n().queryCache[F],f=l?.errorInfo?.retryCount??0,d=f+1;try{h?.(c,f)}catch(e){g.error(Pt(i,"onError callback",e))}if(f<q){if(se.get().subscriptionCount>0){const t="function"==typeof z?z(d,c):z;t!==1/0&&(ne&&clearTimeout(ne),ne=setTimeout(()=>{const t=se.get();t.enabled&&t.subscriptionCount>0&&u.fetch(e,kt,!0)},t))}t(e=>({error:c,queryCache:{...e.queryCache,[F]:{cacheTime:l?.cacheTime??M,data:l?.data??null,lastFetchedAt:l?.lastFetchedAt??null,errorInfo:{error:c,lastFailedAt:Date.now(),retryCount:d}}},queryKey:D?F:e.queryKey,status:R.Error}))}else t(e=>({error:c,queryCache:{...e.queryCache,[F]:{cacheTime:l?.cacheTime??M,data:l?.data??null,lastFetchedAt:l?.lastFetchedAt??null,errorInfo:{error:c,lastFailedAt:Date.now(),retryCount:q}}},queryKey:D?F:e.queryKey,status:R.Error}));if(a)throw c;return null}finally{E&&(te=null)}}return E?(te={key:F,promise:$()}).promise:$()},getCacheEntry(e){if(k)return null;const t=n(),r=e?"string"==typeof e?e:N(Tt(V,_,J,e)):t.queryKey;return t.queryCache[r]??null},getData(e){if(k)return null;const t=n().getCacheEntry(e);return t&&null!==t.data?C?t.data:t.lastFetchedAt&&Date.now()-t.lastFetchedAt>=t.cacheTime?null:t.data:null},getStatus:function(e){const t=n(),r=t.status;switch(e){case"isIdle":return r===R.Idle;case"isLoading":return r===R.Loading;case"isError":case"isInitialLoad":case"isSuccess":case void 0:{const n=t.queryKey,o=t.queryCache[n],i=k?r===R.Error:"number"==typeof o?.errorInfo?.lastFailedAt;if("isError"===e)return i;const s=null!==((k?re===n&&t.lastFetchedAt:o?.lastFetchedAt)||null),a=!s&&!i&&t.enabled;if("isInitialLoad"===e)return a;const c=s&&!i;return"isSuccess"===e?c:{isError:i,isIdle:r===R.Idle,isLoading:r===R.Loading,isInitialLoad:a,isSuccess:c}}}},isDataExpired(e){const t=n(),r=t.queryCache[t.queryKey],o=t.queryKey,i=t.lastFetchedAt,s=(k?re===o&&i:r?.lastFetchedAt)||null;if(!s)return!0;const a=e??r?.cacheTime;return void 0===a||Date.now()-s>=a},isStale(e){const t=n(),r=t.queryKey,o=(k?re===r&&t.lastFetchedAt:t.queryCache[r]?.lastFetchedAt)||null;if(!o)return!0;const i=e??K;return Date.now()-o>=i},reset(e=!1){for(const e of X)e();X=[],V=null,_=null,G=null,ae(),ne&&(clearTimeout(ne),ne=null),te=null,re=null,e&&t(ie)}},l=r.subscribe;return r.subscribe=(...e)=>{const t=Z?()=>{}:se.subscribe(),n=1===e.length?l(e[0]):l(e[0],e[1],e[2]);return e=>{t(e),n()}},u}const le=c?.storageKey?$e(ce,f(c,{partialize:Mt(C,c.partialize)})):i&&!("storageKey"in i)?$e(ce,i):$e(ce),fe=le.getState(),de=fe.error,ye=fe.enabled,he=fe.queryKey,ge=fe.fetch;let me;if(he&&!de&&(re=he),Z=!0,A||"function"==typeof e.enabled){const{directValues:e,enabledAttachVal:t,enabledDirectValue:r,attachVals:o}=function(e,t,r){const o=u(),i=u(),s=u();for(const e in t){if(!n(t,e))continue;const a=t[e];if(Dt(a)){const t=a(St,r);o[e]=t,s[e]=t.value}else Et(a)&&(i[e]=a,s[e]=a)}let a,c=null,l=null;if(Dt(e)){const t=e(St,r);a=t.value,c=t}else a=e,l=e;return{attachVals:o,directValues:i,enabledAttachVal:c,enabledDirectValue:l,resolvedEnabled:a,resolvedParams:s}}(F,A,le);V={enabled:t,params:o},_={enabled:r,params:e}}"function"==typeof e.staleTime&&(G=e.staleTime(St,le),K=G.value);const be=Object.freeze({updateQueryKey:C}),Se=function(){let e,t=!1;return function(...n){e=n,t||(t=!0,queueMicrotask(()=>{t=!1,(e=>{ge(e??At(V,_),be)})(...e)}))}}();function ve(){let e;if(!C){e=At(V,_);const t=N(e);le.setState({queryKey:t})}Se(e)}const we=a||!T?ve:pe(ve,"number"==typeof T?T:T.delay,"number"==typeof T?{leading:!1,maxWait:T,trailing:!0}:T);for(const e in V?.params){const t=V.params[e];if(!t)continue;const n=jt(t);if(U&&console.log("[🌀 Param Subscription 🌀] Subscribed to param:",e),n){let r=t.value;const o=n(()=>{const n=t.value;ue(r,n)||(U&&console.log("[🌀 Param Change 🌀] -",e,"- [Old]:",`${r?.toString()},`,"[New]:",n?.toString()),r=n,we())});X.push(o)}}if(G){const e=jt(G);if(e){const t=G;let n=t.value;U&&console.log("[🌀 StaleTime Subscription 🌀] Initial value:",n);const r=e(()=>{const e=t.value;e!==n&&(U&&console.log("[🌀 StaleTime Change 🌀] - [Old]:",`${n},`,"[New]:",e),n=e,K=e,ge())});X.push(r)}}if(V?.enabled){const e=V.enabled,t=jt(e);if(t){let n=e.value;ye!==n&&((me??(me={})).enabled=n),n&&se.setEnabled(n),U&&console.log("[🌀 Enabled Subscription 🌀] Initial value:",n);const r=t(()=>{const t=e.value;t!==n&&(U&&console.log("[🌀 Enabled Change 🌀] - [Old]:",`${n},`,"[New]:",t),n=t,le.setState({enabled:t}))});X.push(r)}}else ye!==ie.enabled&&((me??(me={})).enabled=ie.enabled);const Oe=N(At(V,_));return Oe!==he&&((me??(me={})).queryKey=Oe),me&&le.setState(me),Z=!1,Y&&queueMicrotask(we),Q(le,B.QueryStore)}function Tt(e,t,n,r){return r?zt(r,n)?r:{...At(e,t),...r}:At(e,t)}function At(e,t){const n=Object.assign(u(),t?.params);for(const t in e?.params){const r=e.params[t];r&&(n[t]=r.value)}return n}function zt(e,t){if(!e)return!1;for(const n of t)if(!(n in e))return!1;return!0}function Dt(e){return"function"==typeof e}function Et(e){return!Dt(e)}function Mt(e,t){return r=>{const o={...r},i=u();for(const e in o)n(o,e)&&e in It&&(It[e]&&(i[e]=o[e]),delete o[e]);return{...t?t(o):Se(o),...$t(e,null,i)}}}function $t(e,t,r){if(!r.queryCache)return r;const o=Date.now(),i=t??(e&&r.queryKey||null),s=u();let a=!1;for(const e in r.queryCache){if(!n(r.queryCache,e))continue;const c=r.queryCache[e];c&&(o-(c.lastFetchedAt??c.errorInfo.lastFailedAt)<c.cacheTime||e===i)?!t&&c.errorInfo&&c.errorInfo.retryCount>0?(s[e]={...c,errorInfo:{...c.errorInfo,retryCount:0}},a=!0):s[e]=c:a=!0}return a?{...r,queryCache:s}:r}function Kt(){return Object.create(null)}function Pt(e,t,n){return new m(`[createQueryStore: ${e}]: ${t} failed`,n)}function Rt(e,t,n){const r="function"==typeof t,o=r?t:void 0,i=r?n:t,s=new Set,a=dt(e,{debugMode:i?.debugMode??!1,equalityFn:function(e,t){const n=Object.is(e,t);return n||(function(e,t){for(const n of s){n.unsubscribe();const r=n.args;if(1===r.length){const o=r[0],i=e.getState(),s=t.getState(),a=t.subscribe(o);n.unsubscribe=a,Object.is(s,i)||o(s,i);continue}const o=r[0],i=r[1];let s=r[2];s?.fireImmediately&&(s={...s,fireImmediately:!1});const a=o(e.getState()),c=o(t.getState()),u=t.subscribe(o,i,s);n.unsubscribe=u,(s?.equalityFn??Object.is)(a,c)||i(c,a)}}(e,t),_(e)),n},keepAlive:!0,lockDependencies:i?.lockDependencies??!0}),c=Object.assign({[B.VirtualStore]:!0,destroy:a.destroy,getInitialState:()=>a.getState().getInitialState(),getState:()=>a.getState().getState(),persist:(u=a.getState,{clearStorage:()=>u().persist?.clearStorage(),getOptions:()=>u().persist?.getOptions()??{},hasHydrated:()=>u().persist?.hasHydrated()??!0,hydrationPromise:()=>u().persist?.hydrationPromise?.()??Promise.resolve(),onFinishHydration:e=>u().persist?.onFinishHydration(e)??d,onHydrate:e=>u().persist?.onHydrate(e)??d,rehydrate:()=>u().persist?.rehydrate(),setOptions:e=>u().persist?.setOptions(e)}),setState:xt(a.getState),subscribe:function(...e){const t={args:e,unsubscribe:1===e.length?a.getState().subscribe(e[0]):a.getState().subscribe(e[0],e[1],e[2])};return s.add(t),()=>{t.unsubscribe(),s.delete(t)}}},o?.(a.getState));var u;return c}function xt(e){return function(...t){return!0===t[1]?e().setState(t[0],!0):e().setState(t[0])}}export{A as DEFAULT_STORAGE_KEY_PREFIX,R as QueryStatuses,B as StoreTags,m as StoresError,J as applyStateUpdate,Q as assignStoreTag,$e as baseStore,D as configureStores,oe as createStoreActions,ae as deepEqual,L as defaultRetryDelay,dt as derivedStore,_ as destroyStore,G as destroyStores,b as ensureError,E as getOptions,N as getQueryKey,M as getStorageConfig,X as getStoreName,Y as hasDestroy,Z as hasGetSnapshot,te as isDerivedStore,ne as isPersistedStore,ee as isQueryStore,re as isVirtualStore,g as logger,$ as markStoreCreated,W as parseQueryKey,qt as queryStore,p as setLogger,ce as shallowEqual,x as time,Rt as virtualStore};
1
+ import{getQueryKey as e,isQueryParamConfig as t}from"../chunk-PLDNKWGX.mjs";import{isPromiseLike as n,reviver as r,replacer as o}from"../chunk-FENSEQ3V.mjs";export{replacer,reviver}from"../chunk-FENSEQ3V.mjs";import{IS_DEV as i,IS_TEST as s,IS_BROWSER as c,isRecordLike as a,nullObject as u,IS_IOS as l,buildNullObject as f,hasOwn as d,noop as y,isPlainObject as h,identity as p}from"../chunk-FPYZVFBM.mjs";export{identity,nullObject}from"../chunk-FPYZVFBM.mjs";function g(){return"undefined"!=typeof window?window.localStorage:null}var b={debug:(e,t)=>{i&&console.debug(e,t)},error:(e,t)=>{i&&!s&&console.error(e,t)},info:(e,t)=>{i&&console.info(e,t)},warn:(e,t)=>{i&&console.warn(e,t)}};function m(e){b=e}var S=class extends Error{constructor(e,t){super(e),this.name="StoresError",void 0!==t&&Object.defineProperty(this,"cause",{configurable:!0,value:t,writable:!0})}};function v(e){return e instanceof Error?e:new Error(String(e))}var w,O="stores/core/sync-channel",j=`${O}:storage:`,F=class{constructor(e){this.broadcast=e.broadcast,this.origin=e.origin,this.storeKey=e.storeKey,this.teardown=e.teardown}destroy(){this.teardown()}publish(e){const t=u();for(const n of Object.entries(e.values))t[n[0]]=n[1];const n={origin:this.origin,replace:e.replace,sessionId:e.sessionId,storeKey:this.storeKey,timestamp:e.timestamp,values:t};this.broadcast(n)}},k=class{constructor(){this.listeners=new Map,this.origin="undefined"!=typeof crypto&&"randomUUID"in crypto?crypto.randomUUID():`${Math.random().toString(36).slice(2)}:${Date.now().toString(36)}`,this.onChannelMessage=e=>{e.data&&this.dispatch(e.data)},this.onStorageEvent=e=>{if(e.key&&e.newValue&&e.key.startsWith(j))try{const t=JSON.parse(e.newValue);this.dispatch(t)}catch(e){b.error(new S("[sync] Failed to parse storage event payload",e))}},this.channel="undefined"==typeof BroadcastChannel?null:new BroadcastChannel(O),this.storage=I(),this.channel&&this.channel.addEventListener("message",this.onChannelMessage),c&&window.addEventListener("storage",this.onStorageEvent)}get sessionId(){return this.origin}register(e){const t=t=>{if(t.origin===this.origin||t.storeKey!==e.key)return;const n=u();for(const r of e.fields)d(t.values,r)&&(n[r]=t.values[r]);Object.keys(n).length&&e.apply({replace:t.replace,sessionId:t.sessionId,timestamp:t.timestamp,values:n})};let n=this.listeners.get(e.key);return n||(n=new Set,this.listeners.set(e.key,n)),n.add(t),new F({broadcast:e=>this.broadcast(e),origin:this.origin,storeKey:e.key,teardown:()=>this.removeListener(e.key,t)})}broadcast(e){try{this.channel&&this.channel.postMessage(e),this.writeToStorage(e)}catch(e){b.error(new S("[sync] Failed to broadcast update",e))}}dispatch(e){if(!e.storeKey)return;const t=this.listeners.get(e.storeKey);if(t&&t.size)for(const n of t)n(e)}removeListener(e,t){const n=this.listeners.get(e);n&&(n.delete(t),n.size||this.listeners.delete(e))}writeToStorage(e){if(this.storage||(this.storage=I()),!this.storage)return;const t=`${j}${e.storeKey}`;try{this.storage.setItem(t,JSON.stringify(e))}catch(e){b.error(new S("[sync] Failed to write broadcast payload to storage",e))}}};function I(){try{return"undefined"!=typeof window?window.localStorage:null}catch{return null}}var C,q,T,z=class{destroy(){}publish(){}},A=class{constructor(){this.sessionId="noop"}register(e){return new z}},K="stores:",P=!1;function E(e){i&&function(){if(P)throw new Error("[stores]: configureStores() called after first store creation. Call it earlier before creating any stores.")}(),e.logger&&m(e.logger),q??(q=function(e){return e?.queryStoreDefaults?{queryStoreDefaults:e.queryStoreDefaults}:void 0}(e)),T??(T=x(e))}function D(){if(q)return q}function M(){return T??(T=x(void 0))}function $(){P=!0}function x(e){return{storage:e?.storage??(t=e?.storageKeyPrefix??K,{clearAll(){try{const e=g();if(!e)return;const n=[];for(let r=0;r<e.length;r++){const o=e.key(r);o?.startsWith(t)&&n.push(o)}for(const t of n)e.removeItem(t)}catch(e){console.error("Error clearing localStorage:",e)}},contains(e){const n=g();return null!==n?.getItem(`${t}${e}`)},delete(e){try{const n=g();n?.removeItem(`${t}${e}`)}catch(e){console.error("Error deleting from localStorage:",e)}},getAllKeys(){try{const e=g();return e?Array.from(e.keys()):[]}catch(e){return console.error("Error getting keys from localStorage:",e),[]}},get(e){try{const n=g();return n?n.getItem(`${t}${e}`)??void 0:void 0}catch(e){return void console.error("Error reading from localStorage:",e)}},set(e,n){try{const r=g();r?.setItem(`${t}${e}`,n)}catch(e){console.error("Error writing to localStorage:",e)}}}),syncEngine:e?.syncEngine??(c?(w||(w=new k),w):(C||(C=new A),C))};var t}var R,L={Error:"error",Idle:"idle",Loading:"loading",Success:"success"},N={ms:e=>e,seconds:e=>1e3*e,minutes:e=>6e4*e,hours:e=>36e5*e,days:e=>864e5*e,weeks:e=>6048e5*e,infinity:1/0,zero:0};function H(e,t){const n=t?.baseDelay??N.seconds(5),r=t?.maxDelay??N.minutes(5);return Math.min(n*Math.pow(2,e),r)}function W(e,t){return!0===t[1]?e(t[0],!0):e(t[0])}function U(e,t,n){if(!0===n)return V(t)?t(e):t;const r=V(t)?t(e):t;return Object.is(r,e)?e:a(e)&&a(r)?{...e,...r}:r}function V(e){return"function"==typeof e}var B=Object.freeze({QueryStore:Symbol("queryStore"),VirtualStore:Symbol("virtualStore")});function J(e,t){return Object.assign(e,{[t]:!0})}function Q(e,t){X(e)?e.getState().reset(t?.clearQueryCache):Z(e)&&e.destroy()}function _(e,t){for(const n of Array.isArray(e)?e:Object.values(e))n&&!t?.skipDestroy?.(n)&&Q(n,t)}function Y(e){const t="function"==typeof(n=e)?n.name:"";var n;return te(e)?e.persist.getOptions().name??t:t}function Z(e){return"destroy"in e}function G(e){return"getSnapshot"in e}function X(e){return B.QueryStore in e}function ee(e){return"flushUpdates"in e}function te(e){return!(!("persist"in e)||!e.persist)&&"string"==typeof e.persist.getOptions().name}function ne(e){return B.VirtualStore in e}function re(e,t){const n=function(e){const t=e.getState(),n=u(),r=n;if(i&&("object"!=typeof t||null===t))throw new Error("[createStoreActions]: State is not an object");if(ne(e))for(const n in t)ie(t,n)&&(r[n]=oe(e,n));else for(const e in t)ie(t,e)&&(r[e]=t[e]);return n}(e);return t?Object.assign(n,t):n}function oe(e,t){return function(...n){const r=e.getState()[t];if("function"==typeof r)return r(...n);throw new Error(`[createVirtualStoreAction]: Method ${String(t)} is not a function`)}}function ie(e,t){return"function"==typeof e[t]}function se(e,t){if("object"!=typeof e||null==e||"object"!=typeof t||null==t)return e===t;if(Object.is(e,t))return!0;const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!(r in t)||!se(e[r],t[r]))return!1;return!0}function ce(e,t){if("object"!=typeof e||null==e||"object"!=typeof t||null==t)return e===t;if(Object.is(e,t))return!0;const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.is(e[r],t[r]))return!1;return!0}function ae(e,t){const n=Object.prototype.hasOwnProperty;function r(e,t){for(const n of e.keys())if(ae(n,t))return n}let o,i,s;if(e===t)return!0;if(e&&t&&(o=e.constructor)===t.constructor){if(o===Date)return e.getTime()===t.getTime();if(o===RegExp)return e.toString()===t.toString();if(o===Array){if((i=e.length)===t.length)for(;i--&&ae(e[i],t[i]););return-1===i}if(o===Set){if(e.size!==t.size)return!1;for(let n of e){if(s=n,s&&"object"==typeof s&&(s=r(t,s),!s))return!1;if(!t.has(s))return!1}return!0}if(o===Map){if(e.size!==t.size)return!1;for(let n of e){if(s=n[0],s&&"object"==typeof s&&(s=r(t,s),!s))return!1;if(!ae(n[1],t.get(s)))return!1}return!0}if(o===ArrayBuffer)e=new Uint8Array(e),t=new Uint8Array(t);else if(o===DataView){if((i=e.byteLength)===t.byteLength)for(;i--&&e.getInt8(i)===t.getInt8(i););return-1===i}if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(t)){const n=e,r=t;if((i=n.byteLength)===r.byteLength)for(;i--&&n[i]===r[i];);return-1===i}if(!o||"object"==typeof e){i=0;for(const r in e){if(n.call(e,r)&&++i&&!n.call(t,r))return!1;if(!(r in t)||!ae(e[r],t[r]))return!1}return Object.keys(t).length===i}}return e!=e&&t!=t}function ue(e){return e()}var le=!1,fe=!1,de=!1,ye=new Set,he=new Map,pe=new Map,ge=null,be=1/0;function me(){return le}function Se(){return ge}function ve(){le||(le=!0,de||(de=!0,queueMicrotask(()=>{de=!1,we()})))}function we(){if(le)if(fe)je();else{fe=!0;try{ue(je)}finally{Ie()}}}function Oe(e){le&&ye.add(e)}function je(){for(;he.size>0||ye.size>0;)Fe(),ke()}function Fe(){for(;he.size>0;){const e=be,t=pe.get(e);if(t){pe.delete(e);for(const e of t)he.delete(e);ge=e;for(const e of t)e();ge=null,be=1/0;for(const e of pe.keys())e<be&&(be=e)}else{be=1/0;for(const e of pe.keys())e<be&&(be=e)}}}function ke(){for(const e of ye)ye.delete(e),e()}function Ie(){le=!1,fe=!1,ge=null,ye.clear(),he.clear(),pe.clear(),be=1/0}function Ce(e){let t;const n=new Set;let r;function o(...e){const o=U(t,...e);if(Object.is(o,t))return;const i=t;if(t=o,r)for(const e of r)e(t,i);n.size&&we();for(const e of n)e(t,i)}function i(){return t}const s={getInitialState:function(){return c},getState:i,setState:o,subscribe:function(...e){return 1===e.length?a(e[0]):function(e,n,o){const i=o?.equalityFn??Object.is,s=o?.isCascadeParticipant??!1;let c=e(t);function u(t){const r=e(t);if(i(c,r))return;const o=c;c=r,s&&ve(),n(r,o)}return o?.fireImmediately&&n(c,c),s?function(e){return(r??(r=new Set)).add(e),()=>{r?.delete(e),0===r?.size&&(r=void 0)}}(u):a(u)}(e[0],e[1],e[2])}},c=t=e(o,i,s);return s;function a(e){return n.add(e),()=>{n.delete(e)}}}function qe(e){return{...e,merge:e.merge??Te,skipHydration:e.skipHydration??!1}}function Te(e,t){return void 0===e?t:{...t,...e}}function ze(){let e,t,n=!1;return{complete:function(){!n&&e&&(n=!0,e(),e=void 0,t=void 0)},isHydrated:function(){return n},fail:function(r){!n&&t&&(n=!0,t(r),t=void 0,e=void 0)},promise:new Promise((n,r)=>{e=n,t=r})}}var Ae=Math.max,Ke=Math.min;function Pe(e,t=0,n={}){let r,o,i,s,c,a,u=0,l=!1,f=!1,d=!0;if("function"!=typeof e)throw new TypeError("Expected a function");function y(t){const n=r,i=o;return r=o=void 0,u=t,s=n?e.apply(i,n):e.apply(i),s}function h(e){const n=e-(a??0);return void 0===a||n>=t||n<0||f&&void 0!==i&&e-u>=i}function p(){const e=Ee();if(h(e))return g(e);c=setTimeout(p,function(e){const n=t-(e-(a??0));return f&&void 0!==i?Ke(n,i-(e-u)):n}(e))}function g(e){return c=void 0,d&&r?y(e):(r=o=void 0,s)}function b(...e){const n=Ee(),i=h(n);if(r=e,o=this,a=n,i){if(void 0===c)return function(e){return u=e,c=setTimeout(p,t),l?y(e):s}(a);if(f)return clearTimeout(c),c=setTimeout(p,t),y(a)}return void 0===c&&(c=setTimeout(p,t)),s}return t=De(t)||0,function(e){const t=typeof e;return null!==e&&("object"===t||"function"===t)}(n)&&(l=!!n.leading,f="maxWait"in n,i=f?Ae(De(n.maxWait)||0,t):void 0,d="trailing"in n?!!n.trailing:d),b.cancel=function(){void 0!==c&&clearTimeout(c),u=0,r=a=o=c=void 0},b.flush=function(){return void 0===c?s:g(Ee())},b}function Ee(){return"undefined"!=typeof performance&&"function"==typeof performance.now?performance.now():Date.now()}function De(e){if("number"==typeof e)return e;if("symbol"==typeof e||void 0===e)return NaN;if("object"==typeof e&&null!==e){const t="function"==typeof e.valueOf?e.valueOf():e;e="object"==typeof t?t+"":t}return"string"!=typeof e?0===e?e:+e:(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)}function Me(e){if(!h(e))return e;const t=u(),n=Object.keys(e);for(let r=0;r<n.length;r++){const o=n[r],i=e[o];"function"!=typeof i&&(t[o]=i)}return t}var $e=s?0:c?N.ms(200):N.seconds(l?3:5);function xe(e,t,n,r){const o=!(t.deserializer||t.serializer||e.deserializer||e.serializer),i="object"==typeof t.sync&&!0===(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata),s=t.partialize??Me,c=t.deserializer??e.deserializer??Le(o),a=t.serializer??e.serializer??Ne(o);function u(t,n,o){try{if(Ve(r))return;const c={state:s(n),version:o},u=We(r,i,c),l=a(c);try{e.set(t,l),Ue(r,u)}catch(e){b.error(new S("[createBaseStore]: Failed to persist store data",e))}}catch(e){b.error(new S("[createBaseStore]: Failed to persist store data",e))}}const l=void 0!==n?Pe(u,n,{leading:!1,maxWait:n,trailing:!0}):u;return{getItem:t=>{const n=e.get(t);return void 0===n?null:c(n)},setItem:(e,t,n)=>{r?.getIsApplyingRemote()||l(e,t,n)},removeItem:t=>{try{e.delete(t)}catch(e){b.error(new S("[createBaseStore]: Failed to delete persisted store data",e))}}}}function Re(e,t,n,r){const o=!(t.deserializer||t.serializer||e.deserializer||e.serializer),i="object"==typeof t.sync&&!0===(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata),s=t.partialize??Me,c=t.deserializer??e.deserializer??Le(o),a=t.serializer??e.serializer??Ne(o);async function u(t,n,o){try{if(Ve(r))return;const c={state:s(n),version:o},u=We(r,i,c),l=a(c);try{await e.set(t,l),Ue(r,u)}catch(e){b.error(new S("[createBaseStore]: Failed to persist store data",e))}}catch(e){b.error(new S("[createBaseStore]: Failed to serialize persisted store data",e))}}const l=void 0!==n?Pe(u,n,{leading:!1,maxWait:n,trailing:!0}):function(e){let t,n=null;return function(...r){return t=r,n||(n=new Promise(r=>{queueMicrotask(async()=>{try{await e(...t)}finally{n=null,r()}})})),n}}(u);return{getItem:async t=>{const n=await e.get(t);return void 0===n?null:c(n)},setItem:async(e,t,n)=>{if(!r?.getIsApplyingRemote())return await l(e,t,n)},removeItem:async t=>{try{await e.delete(t)}catch(e){b.error(new S("[createBaseStore]: Failed to delete persisted store data",e))}}}}function Le(e){return t=>{if("string"!=typeof t)throw new S("[createBaseStore]: Received non-string serialized state without a custom deserializer. Provide a deserializer on the store or storage adapter.");return function(e,t){try{return JSON.parse(e,t?r:void 0)}catch(e){throw b.error(new S("[createBaseStore]: Failed to deserialize persisted store data",e)),e}}(t,e)}}function Ne(e){return t=>function(e,t){try{return JSON.stringify(e,t?o:void 0)}catch(e){throw b.error(new S("[createBaseStore]: Failed to serialize store data",e)),e}}(t,e)}var He=Object.freeze({shouldClear:!1});function We(e,t,n){if(!t||!e)return He;const r=e.getFieldTimestampSnapshot();return function(e,t){const n=e.getSessionId(),r=e.getTimestamp();void 0!==n&&void 0!==r&&(t.syncMetadata={origin:n,timestamp:r})}(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 Ue(e,t){e&&t.shouldClear&&t.fieldSnapshot&&Object.keys(t.fieldSnapshot).length&&e.clearFieldTimestamps(t.fieldSnapshot)}function Ve(e){return!!e&&!!e.getIsApplyingRemote()}var[Be,Je]=[0,1];function Qe(e,t,n){if(!e)return!0;const r=e[Be],o=e[Je];return!(t<r)&&(t>r||n>o)}function _e(e,t){return Object.prototype.hasOwnProperty.call(t,e)}function Ye(e,t){if(!i)return!0;if(null===e||null===t)return e===t;const n=typeof e;return n===typeof t&&("object"!==n||Object.prototype.toString.call(e)===Object.prototype.toString.call(t))}function Ze(e){if(null===e)return"null";const t=typeof e;return"object"===t?Object.prototype.toString.call(e):t}function Ge(e,t){if($(),!t)return Ce(e);const r=t.storageKey,o="string"==typeof r,i=o?t.storage??M().storage:void 0,s=function(e,t){if(!e)return null;const n="object"==typeof e,r=n?e.key??t:!0===e?t:e;if(!r)throw new S("[createBaseStore]: sync requires a key to be specified either directly or via storageKey");return n?{...e,key:r}:{key:r}}(t.sync,r),c=s?function(e,t,r){const o=t.engine??M().syncEngine,i=function(e){let t,n,r,o=!1;return{isAsync:e,clearFieldTimestamps:function(e){if(e&&r){for(const t of Object.entries(e)){const e=t[0],n=t[1];r[e]===n&&delete r[e]}Object.keys(r).length||(r=void 0)}},getFieldTimestampSnapshot:function(){if(r)return{...r}},getIsApplyingRemote:()=>o,getSessionId:()=>t,getTimestamp:()=>n,mergeFieldTimestamps:function(e){if(r)for(const t of Object.entries(e)){const e=t[0],n=t[1],o=r[e];(void 0===o||n>o)&&(r[e]=n)}else r={...e}},onHydrationComplete:void 0,onHydrationFlushEnd:void 0,setIsApplyingRemote:e=>o=e,setSessionId:e=>t=e,setTimestamp:e=>n=e,setWithoutPersist:void 0}}(r);return{stateCreator:(s,c,a)=>{const l=new Map,f=[],d=[];let y=null,h=!1,p=!1,g=0,m=null,v=[],w=Promise.resolve(),O=!r;function j(e,t){if(i?.setSessionId&&i?.setTimestamp&&o.sessionId&&(i.setSessionId(o.sessionId),i.setTimestamp(e),i.mergeFieldTimestamps&&t.length>0)){const n=u();for(const r of t)n[String(r)]=e;i.mergeFieldTimestamps(n)}}function F(e,t){if(h||!m)return t?s(e,t):s(e);const r=function(){const e=Date.now(),t=e>g?e:g+1;return g=t,t}();let i=[],c=u();const a=n=>{const o=U(n,e,t);for(const e of v)Object.is(o[e],n[e])||(i.push(e),c[e]=o[e]);return i.length&&j(r,i),o},f=t?s(a,!0):s(a);function b(){i.length&&function(e){const t=o.sessionId;for(const n of e.keys)l.set(n,[e.timestamp,t]);y&&p?y.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values}):d.push(e)}({keys:i,replace:t??!1,values:c,timestamp:r})}return n(f)?f.finally(b):(b(),f)}const k=a.setState;a.setState=F;const I=e(F,c,a);if(v=t.fields??function(e){const t=[];for(const n of Object.entries(e)){if("function"==typeof n[1])continue;const e=n[0];t.push(e)}return t}(I),!v.length)return I;async function C(e){g=Math.max(g,e.timestamp);const n=u(),r=c(),o=e.timestamp;let s;if(e.replace)for(const t of v)_e(t,e.values)||Qe(l.get(t),o,e.sessionId)&&(s??(s=[])).push(t);for(const i of v){if(!_e(i,e.values))continue;if(!m?.has(i))continue;if(!Qe(l.get(i),o,e.sessionId))continue;const s=t.merge?.[i];if(s){const t=e.values[i],c=r[i];if(void 0!==t){const a=s(t,c,r,e.values),u=void 0!==c?c:t;if(!Ye(a,u))return void b.error(new S(`[sync] Merge function for field "${String(i)}" returned ${Ze(a)} but expected ${Ze(u)}`));n[i]=a,l.set(i,[o,e.sessionId])}}else n[i]=e.values[i],l.set(i,[o,e.sessionId])}if(Object.keys(n).length>0||s?.length){h=!0,i&&i.setIsApplyingRemote(!0);try{if(e.replace){const e={...r};let t=!1;if(s?.length){t=!0;for(const t of s)delete e[t],l.delete(t)}for(const r in n){if(!Object.prototype.hasOwnProperty.call(n,r))continue;const o=n[r];void 0!==o&&(Object.is(e[r],o)||(t=!0),e[r]=o)}if(!t)return;await(i.setWithoutPersist??k)(e,!0)}else await(i.setWithoutPersist??k)(n)}finally{h=!1,i&&i.setIsApplyingRemote(!1)}}}function q(e){r?w=w.then(()=>C(e)):C(e)}if(m=new Set(v),y=o.register({apply:e=>{O?q(e):f.push(e)},fields:v,getState:c,key:t.key}),y?.onFirstSubscribe||y?.onLastUnsubscribe){let e=0;const t=a.subscribe;a.subscribe=(...n)=>{e||y.onFirstSubscribe?.(),e+=1;const r=1===n.length?t(n[0]):t(n[0],n[1],n[2]);return()=>{r(),e-=1,e||queueMicrotask(()=>{e||y.onLastUnsubscribe?.()})}}}function T(){p=!0,function(){if(y&&d.length){for(const e of d){const t=o.sessionId;for(const n of e.keys)l.set(n,[e.timestamp,t]);j(e.timestamp,e.keys),y.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values})}d.length=0}}()}function z(){O=!0,function(){if(!f.length)return;const e=f.slice();f.length=0;for(const t of e)q(t)}()}return r?(i.onHydrationComplete=T,i.onHydrationFlushEnd=z):y.onHydrated?(y.onHydrated(T),z()):(T(),z()),I},syncContext:i}}(e,s,i?.async??!1):void 0,a=c?.stateCreator??e;if(!o)return Ce(a);const l=function(e,t,n){const r=t??e.storage??M().storage,o=(e.sync?void 0:e.persistThrottleMs??$e)||void 0,i=e.version??0;return r.async?{async:!0,persistStorage:Re(r,e,o,n),version:i}:{async:!1,persistStorage:xe(r,e,o,n),version:i}}(t,i,c?.syncContext),f=l.async?function(e){let t,n,r,o=!1;return{hydrationPromise:()=>o?t?.promise??n??(n=Promise.resolve()):(t||(t=ze()),t.promise),stateCreator:(n,i,s)=>{let c;return r=()=>{if(c?.length){for(const e of c)W(s.setState,e);c=void 0}},e(function(...e){return o?W(n,e):(t||(t=ze()),c||(c=[]),c.push(e),t.promise)},i,s)},wrapOnRehydrateStorage:(e,n)=>i=>{const s=e?.(i);return(e,i)=>{o=!0,n?.onHydrationComplete?.(),r&&r(),n?.onHydrationFlushEnd?.(),i?t?.fail(v(i)):t?.complete(),s?.(e,i)}}}}(a):void 0,d=f?f.wrapOnRehydrateStorage(t.onRehydrateStorage,c?.syncContext):t.onRehydrateStorage,y=Ce(function(e,t){return(r,o,i)=>{let s,c,a,u=qe(t),l=!1,f=0;function d(){return u.storage.setItem(u.name,o(),u.version)}const y=i.setState;i.setState=function(...e){return W(y,e),d()};const h=e(function(...e){return W(r,e),d()},o,i);function p(){const e=function(){const e=++f;return l=!1,c?.forEach(e=>e(o()??h)),e}(),t=u.onRehydrateStorage?.(o()??h);try{const r=u.storage.getItem(u.name);return n(r)?r.then(n=>g(e,n,t)).catch(n=>S(e,t,n)):g(e,r,t)}catch(n){S(e,t,n)}}return i.getInitialState=()=>h,Object.assign(i,{persist:{clearStorage:()=>{u.storage.removeItem(u.name)},getOptions:()=>u,hasHydrated:()=>l,onFinishHydration:e=>(a??(a=new Set),a.add(e),()=>{a?.delete(e),0===a?.size&&(a=void 0)}),onHydrate:e=>(c??(c=new Set),c.add(e),()=>{c?.delete(e),0===c?.size&&(c=void 0)}),rehydrate:p,setOptions:e=>{u=qe({...u,...e,storage:e.storage??u.storage})}}}),u.skipHydration||p(),s??h;function g(e,t,r){const o=function(e,t){if(!t)return{migrated:!1,state:void 0};if("number"!=typeof t.version||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"),{migrated:!1,state:void 0};const r=e.migrate(t.state,t.version);return n(r)?r.then(e=>({migrated:!0,state:e})):{migrated:!0,state:r}}(u,t);return n(o)?o.then(t=>b(e,t,r)).catch(t=>S(e,r,t)):b(e,o,r)}function b(e,t,i){const c=function(e,t){if(e!==f)return;const n=u.merge(t.state,o()??h);return s=n,r(n,!0),t.migrated?d():void 0}(e,t);if(n(c))return c.then(()=>m(e,i));m(e,i)}function m(e,t){if(e!==f)return;t?.(s,void 0);const n=o();s=n,l=!0,a?.forEach(e=>e(n))}function S(e,t,n){e===f&&t?.(void 0,n)}}}(f?(e,t,n)=>(c&&(c.syncContext.setWithoutPersist=n.setState),f.stateCreator(e,t,n)):a,{merge:t.merge,migrate:t.migrate,name:r,onRehydrateStorage:d,storage:l.persistStorage,version:l.version}));return f?Object.assign(y,{persist:Object.assign(y.persist,{hydrationPromise:f.hydrationPromise})}):y}function Xe(e,t,n="s"){return 1===t?e:`${e}${n}`}var et=Symbol("stores.deriveProxy.unwrap");function tt(e,t,n){const r=t.get(e);if(void 0!==r)return r;const o=function(e,t,n,r=[]){return e&&"object"==typeof e?nt(e,r,t,n,new WeakSet,new WeakMap):(n(t,r,!0),e)}(G(e)?e.getSnapshot():e.getState(),e,n);return t.set(e,o),o}function nt(e,t,n,r,o,i){return new Proxy(e,{get(s,c,a){if(c===et)return r(n,t,!0),s;if(o.has(s))return Reflect.get(s,c,a);if("__proto__"===c||"symbol"==typeof c)return c===Symbol.iterator&&(r(n,t,!0),o.add(s)),Reflect.get(s,c,a);const u=Reflect.get(s,c,s),l=String(c),f=t.concat(l);if("function"==typeof u)return Object.prototype.hasOwnProperty.call(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));const d=!!u&&"object"==typeof u;return r(n,f,!d),d?(i.has(u)||i.set(u,nt(u,f,n,r,o,i)),i.get(u)):u},getOwnPropertyDescriptor:(e,i)=>(r(n,t,!0),o.add(e),Reflect.getOwnPropertyDescriptor(e,i)),has:(e,o)=>(r(n,t,!0),Reflect.has(e,o)),ownKeys:e=>(r(n,t,!0),o.add(e),Reflect.ownKeys(e))})}function rt(e,t){if(!e||"object"!=typeof e)return e;const n=function(e){const t=Reflect.get(e,et);return t&&"object"==typeof t?t:void 0}(e);return n||(Array.isArray(e)?function(e,t){const n=it(e,t);if(n)for(let t=0;t<e.length;t++)ot(e,String(t),n)}(e,t):h(e)&&function(e,t){const n=it(e,t);if(n)for(const t of Reflect.ownKeys(e))ot(e,t,n)}(e,t),e)}function ot(e,t,n){const r=Reflect.getOwnPropertyDescriptor(e,t);if(!r||!("value"in r))return;const o=rt(r.value,n);o!==r.value&&(r.value=o,Reflect.defineProperty(e,t,r))}function it(e,t){const n=t??new WeakSet;return n.has(e)?null:(n.add(e),n)}var st=Object.freeze([]);function ct(){const e=new Map;return{buildProxySubscriptions(t,n,r,o){const i=new Set;for(const t of e)lt(t[1],t[0],[],0,i,r);!1!==o?.(i)&&function(e,t,n){for(const n of e){const e=n.invocation?ht(n.path,n.invocation):yt(n.path);t(n.store,e,n.path)}n&&function(e){const t=e.size;console.log(`[📡 ${t} ${Xe("Proxy Subscription",t)} 📡]:`,JSON.stringify(Array.from(e).map(e=>{const t="name"in(n=e.store)&&"string"==typeof n.name?n.name:"store";var n;const r=e.path.join(".");if(!e.invocation)return r?`$(${t}).${r}`:`$(${t})`;const o=e.invocation.args?.length??0;return`$(${t}).${r}${o?`(${o}_${Xe("arg",o)})`:"()"}`}),null,2))}(e)}(i,t,n)},reset(){e.clear()},trackPath(t,n,r,o){let i=e.get(t);i||(i=at(),e.set(t,i)),ut(i,n,0,r,o)}}}function at(){return u()}function ut(e,t,n,r,o){if(n===t.length)return r&&(e.isLeaf=!0),void(o&&function(e,t){const n=e.invocation;if(!n)return void(e.invocation=t);if(ft(n,t))return;const r=e.extraInvocations;if(r){for(let e=0;e<r.length;e++)if(ft(r[e],t))return;r.push(t)}else e.extraInvocations=[t]}(e,o));e.children||(e.children=at());const i=t[n];let s=e.children?.[i];s||(s=at(),e.children[i]=s),ut(s,t,n+1,r,o)}function lt(e,t,n,r,o,i=2){const s=e.children;if(!s)return void dt(e,t,n,o);const c=Object.keys(s),a=c.length;if(0!==a)if(e.isLeaf||r>=i&&a>1){dt(e,t,n,o);for(const e of c){const c=s[e];c.invocation&&lt(c,t,[...n,e],r+1,o,i)}}else if(r<i&&a>1&&!e.isLeaf)for(const e of c)lt(s[e],t,[...n,e],r+1,o,i);else{if(1===a){const e=c[0];return void lt(s[e],t,[...n,e],r+1,o,i)}dt(e,t,n,o)}else dt(e,t,n,o)}function ft(e,t){const n=e.args,r=t.args,o=n?.length??0;if(o!==(r?.length??0))return!1;if(!n||!r)return!0;for(let e=0;e<o;e++)if(!Object.is(n[e],r[e]))return!1;return!0}function dt(e,t,n,r){const o=e.isLeaf??!1,i=e.invocation;if(!i)return void r.add({store:t,path:n,isLeaf:o});r.add({store:t,path:n,invocation:i,isLeaf:o});const s=e.extraInvocations;if(s)for(let e=0;e<s.length;e++)r.add({store:t,path:n,invocation:s[e],isLeaf:o})}function yt(e){return t=>pt(t,e)}function ht(e,t){const n=e.slice(0,-1),r=e[e.length-1];return e=>{const o=pt(e,n),i=o&&"object"==typeof o?Reflect.get(o,r):void 0;return"function"==typeof i?Reflect.apply(i,o,t.args??st):void 0}}function pt(e,t){let n=e;for(const e of t){if(!n||"object"!=typeof n)return n;n=Reflect.get(n,e)}return n}var gt=Symbol(),bt=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});function mt(e,t=Object.is){const{debounceOptions:n,debugMode:r,equalityFn:o,keepAlive:s,lockDependencies:c}="function"==typeof(u=t)?{debounceOptions:void 0,debugMode:!1,equalityFn:u,keepAlive:!1,lockDependencies:!1}:{debounceOptions:u.debounce,debugMode:(i&&u.debugMode)??!1,equalityFn:u.equalityFn??Object.is,keepAlive:u.keepAlive??!1,lockDependencies:u.lockDependencies??!1},a=new Set;var u;s&&a.add(St);const l=new Set;let f,d,y=gt,h=!1,g=!1,b=!0,m=!0,S=0,v=!1,w=null,O=gt;function j(e,t,n){if(!m||!a.size)return(t??p)(e.getState());if(!t)return f||(f=new WeakMap),d||(d=ct()),tt(e,f,d.trackPath);const r=n?{equalityFn:n,isCascadeParticipant:!0}:bt;return l.add(e.subscribe(t,E,r)),t(G(e)?e.getSnapshot():e.getState())}function F(e){for(const t of l)t(e);l.clear()}let k=!0;function I(){if(!b&&vt(y))return y;b=!1,m&&F(!0);const t=y,n=vt(t);g=!0;try{y=function(t){k=!0;const n=y,i=e(t),s=d?rt(i):i;return vt(n)&&o(n,s)?(r&&console.log("[🥷 Derive Complete 🥷]: No change detected"),k=!1,n):s}(j)}finally{g=!1}const i=r&&(!n||"verbose"===r&&m);if(i){n?"verbose"===r&&console.log("[🌀 Rebuilding Subscriptions 🌀]: Created…"):console.log("[🌀 Initial Derive Complete 🌀]: Created…");const e=l.size;console.log(`[🎯 ${e} ${Xe("Selector Subscription",e)} 🎯]`)}return d&&m&&(d.buildProxySubscriptions((e,t)=>{l.add(e.subscribe(t,E,bt))},i),f=void 0,d.reset(),c&&(d=void 0)),k&&n&&function(e,t){const n=function(){const e=a.has(St)?a.size-1:a.size;return S>0&&S<e}(),o=(!S||n)&&(n||null!==Se()||me());n&&ve(),r&&console.log(`[📻 Derive Complete 📻]: Notifying ${a.size} ${Xe("watcher",a.size)}`);for(const t of a){if("function"==typeof t||!t.isCascadeParticipant)continue;const n=t.selector(e);if(!t.equalityFn(t.currentSlice,n)){const e=t.currentSlice;t.currentSlice=n,t.listener(n,e)}}if(o)return vt(O)||(O=t),void(v||(v=!0,Oe(q)));C(e,t)}(y,t),c&&(m=!1),y}function C(e,t){for(const n of a)if("function"==typeof n)n(e,t);else if(!n.isCascadeParticipant){const t=n.selector(e);if(!n.equalityFn(n.currentSlice,t)){const e=n.currentSlice;n.currentSlice=t,n.listener(t,e)}}}function q(){a.size&&b&&!S&&I();const e=O;v=!1,O=gt,a.size&&vt(y)&&vt(e)&&C(y,e)}const T=n?Pe(A,"number"==typeof n?n:n.delay,"number"==typeof n?{leading:!1,maxWait:n,trailing:!0}:n):void 0,z=T??(()=>{h||(h=!0,queueMicrotask(A))});function A(){h=!1,a.size?b&&I():$()}function K(e){e||T&&b?queueMicrotask(()=>{a.size||$()}):$()}function P(){A(),w=null}function E(){if(!g&&!b){if(b=!0,!T){if(S){ve();const e=Se(),t=null===e?0:e+1;if(null!==w&&t<=w)return;return w=t,void function(e,t){if(!le)return;const n=t<0?0:0|t,r=he.get(e);if(void 0===r){he.set(e,n);let t=pe.get(n);return t||(t=new Set,pe.set(n,t)),t.add(e),void(n<be&&(be=n))}if(n>r){const t=pe.get(r);if(t&&(t.delete(e),0===t.size&&(pe.delete(r),r===be))){be=1/0;for(const e of pe.keys())e<be&&(be=e)}he.set(e,n);let o=pe.get(n);o||(o=new Set,pe.set(n,o)),o.add(e),n<be&&(be=n)}}(P,t)}if(me())return void(v||(v=!0,Oe(q)))}w=null,z()}}function D(e){a.add(St);try{return e()}finally{a.delete(St)}}function M(){return me()&&function(){if(le)if(fe)null===ge&&Fe();else{fe=!0;try{Fe()}catch(e){throw Ie(),e}finally{fe=!1,ge=null}}}(),b||!vt(y)?a.size>0?I():e(j):y}function $(e=!0){s&&e||(T?.cancel(),F(),a.clear(),S=0,d=void 0,f=void 0,m=!0,h=!1,g=!1,b=!0,y=gt,v=!1,O=gt,w=null)}return{destroy:()=>$(!1),flushUpdates:function(){a.size&&(T?T.flush():b&&I())},getSnapshot:function(){return vt(y)?(h&&A(),y):a.size?I():D(I)},getState:M,subscribe:function(...e){if(1===e.length){const t=e[0];return a.add(t),vt(y)||M(),()=>{a.delete(t),a.size||K(!1)}}const[t,n,r]=e,o=r?.equalityFn??Object.is,i=r?.isCascadeParticipant??!1,s=function(e){return e(a.size?M():D(M))}(t),c={currentSlice:s,equalityFn:o,isCascadeParticipant:i,listener:n,selector:t};return a.add(c),i&&(S+=1),r?.fireImmediately&&n(s,s),()=>{a.delete(c),i&&(S-=1),a.size||K(i)}},getInitialState:()=>{throw new Error("[createDerivedStore]: getInitialState() is not available on derived stores.")},setState:()=>{throw new Error("[createDerivedStore]: setState() is not available on derived stores.")}}}function St(){}function vt(e){return e!==gt}var wt=class{constructor(e){this.count=0,this.lastSubscriptionTime=null,this.fetchThrottleMs=null,this.onSubscribe=null,this.onLastUnsubscribe=null,e&&(this.fetchThrottleMs=N.seconds(5))}init({onSubscribe:e,onLastUnsubscribe:t}){this.onSubscribe=e,this.onLastUnsubscribe=t}hasSubscribers(){return this.count>0}subscribe(){const e=0===this.count,t=null!==this.fetchThrottleMs,n=t&&null!==this.lastSubscriptionTime&&!e&&Date.now()-this.lastSubscriptionTime<=this.fetchThrottleMs;return this.count+=1,this.onSubscribe?.(e,n),t&&(this.lastSubscriptionTime=Date.now()),e=>{const t=1===this.count;this.count=Math.max(this.count-1,0),t&&(this.onLastUnsubscribe?.(e),this.lastSubscriptionTime=null)}}},Ot=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});function jt(t,n,r){const o=u();let i=null,s=!1;if(t)for(const e in t){if(!d(t,e))continue;const r=Ft(o,t[e],e,n);r&&((i??(i=u()))[e]=r,void 0!==r.key&&(s=!0))}return{buildKey:(t=o)=>e(s?function(e,t){const n=u();for(const r in t){if(!d(t,r))continue;const o=e?.[r];if(!1===o?.key)continue;const i=t[r];n[r]=o?.key?o.key(i):i}return n}(i,t):t),complete:e=>e?function(e,t){for(const n of t)if(!(n in e))return!1;return!0}(e,r)?e:{...o,...e}:Ct(o),get:()=>Ct(o),subscribe:e=>function(e,t,n){if(!e)return y;let r;for(const o in e){const i=e[o]?.tracked;i&&(r??(r=[])).push(i.subscribe(e=>{const r=t[o];ae(r,e)||(t[o]=e,n(o,r,e))}))}return r?e=>{for(const t of r)t(e)}:y}(i,o,e)}}function Ft(e,n,r,o){return t(n)?It(e,n.value,r,o,n.key):It(e,n,r,o)}function kt(e,t){const n=[];let r,o;function i(e,t=p){return t(qt(e))}const s=e(function(e,t,i){return t?(n.push(n=>e.subscribe(t,n,function(e){return e?{equalityFn:e,isCascadeParticipant:!0}:Ot}(i))),t(qt(e))):(r??(r=ct()),o??(o=new WeakMap),tt(e,o,r.trackPath))},t),c=r?rt(s):s;return r&&(r.buildProxySubscriptions((e,t)=>{n.push(n=>e.subscribe(t,n,Ot))},!1),r.reset()),o=void 0,{initialValue:c,subscribe(r){const o=()=>r(e(i,t)),s=n.map(e=>e(o));return e=>{for(const t of s)t(e)}}}}function It(e,t,n,r,o){if(function(e){return"function"==typeof e}(t)){const i=kt(t,r);return e[n]=i.initialValue,void 0===o?{tracked:i}:{key:o,tracked:i}}return e[n]=t,void 0===o?null:{key:o}}function Ct(e){const t=u();for(const n in e)d(e,n)&&(t[n]=e[n]);return t}function qt(e){return G(e)?e.getSnapshot():e.getState()}var Tt={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},zt=Object.freeze({force:!0}),At=Object.freeze({once:!0}),Kt=new Set,Pt=!1;function Et(e){Kt.add(e),Pt||(Pt=!0,queueMicrotask(()=>{Pt=!1,ue(Dt)}))}function Dt(){for(const e of Kt)Kt.delete(e),e()}function Mt(e,t,n){$();const r="function"==typeof t?t:Rt,o="object"==typeof t?t:n,c=function(e){return"string"==typeof e?.storageKey}(o)?o:void 0,a=R??(R=function(){const e={abortInterruptedFetches:!0,cacheTime:N.days(7),debugMode:!1,disableAutoRefetching:!1,keepPreviousData:!1,maxRetries:5,minStaleTime:!1,paramChangeThrottle:!1,retryDelay:H,staleTime:N.minutes(2),suppressStaleTimeWarning:!1},t=D()?.queryStoreDefaults;return t?{...e,...t}:e}()),u=a.minStaleTime,{fetcher:l,onError:d,onFetched:y,setData:h,transform:p,abortInterruptedFetches:g=a.abortInterruptedFetches,cacheTime:m=a.cacheTime,debugMode:w=a.debugMode,disableAutoRefetching:O=a.disableAutoRefetching,disableCache:j=!1,enabled:F=!0,keepPreviousData:k=a.keepPreviousData,maxRetries:I=a.maxRetries,paramChangeThrottle:C=a.paramChangeThrottle,params:q,retryDelay:T=a.retryDelay,staleTime:z=a.staleTime,suppressStaleTimeWarning:A=a.suppressStaleTimeWarning}=e;let K="function"==typeof z?a.staleTime:z;i&&!1!==u&&!O&&!A&&K<u&&console.warn(`[createQueryStore${c?.storageKey?`: ${c.storageKey}`:""}] ❌ Stale times under ${u/1e3} seconds are not recommended. Provided staleTime: ${K/1e3} seconds`);const P=new Error("[createQueryStore: AbortError] Fetch interrupted"),E="function"==typeof m,M=i&&w,x=e.params?Object.keys(e.params):[];let W,U=!1,V=[],Q=null,_=null,Y=null,Z=null,G=null,X=null,ee=null;const te={enabled:"function"!=typeof F&&F,error:null,lastFetchedAt:null,queryCache:{},queryKey:"",status:L.Idle},ne=new wt(O);function re(){Y&&(Z=null,Y.abort(),Y=null)}function oe(){G&&(clearTimeout(G),G=null)}function ie(e,t,n){const o=n.setState;function i(e){const t="function"==typeof e;if(t||void 0!==e.enabled){let n;const r=o(r=>{const o=t?e(r):e,i=void 0!==o.enabled?o.enabled:r.enabled;return i!==r.enabled&&(n=()=>function(e,t){e!==t&&ee!==t&&(ee=t,t&&ne.hasSubscribers()?queueMicrotask(()=>a.fetch(void 0,void 0,!0)):(G||g)&&(g&&re(),oe()))}(r.enabled,i)),o});return n?.(),r}return o(e)}function s(e){if(O||K<=0||K===1/0)return;if(!ne.hasSubscribers())return;oe();const n=t();if(!n.enabled)return;const r=W.buildKey(e),o=(j?X===r&&n.lastFetchedAt:n.queryCache[r]?.lastFetchedAt)||null,i=o?K-(Date.now()-o):K;G=setTimeout(()=>{t().enabled&&a.fetch(e,zt,!0)},i)}n.setState=i,ne.init({onSubscribe:(n,r)=>{const o=t();if(o.enabled)if(n){const t=W.get(),n=W.buildKey(t);o.queryKey!==n&&e({queryKey:n}),o.isStale()?a.fetch(t,void 0,!0):s(t)}else O&&!r&&a.fetch(void 0,void 0,!0)},onLastUnsubscribe:e=>{oe(),g&&!e&&re()}});const a={...r(i,t,n),...te,async fetch(n,r,o=!1){const u=!!r?.skipStoreUpdates,f=t();if(!u){if(!f.enabled&&!r?.force)return null;if(o&&!ne.hasSubscribers())return null}const w=f.error,O=f.queryKey,F=f.status===L.Loading,C=W.complete(n),q=W.buildKey(C);if(F&&Z?.promise&&Z.key===q)return M&&console.log("[🔄 Using Active Fetch 🔄] for params:",JSON.stringify(C)),Z.promise;const z=r?.staleTime??K,A="boolean"==typeof r?.updateQueryKey?r.updateQueryKey:!!o&&k,D=(o||O===q||A)&&!u,$=null!==Z;if(g&&D&&re(),!r?.force){const t=f.lastFetchedAt,n=f.queryCache[q],r=n?.lastFetchedAt,o=n?.errorInfo,i=o&&o.retryCount>=I,c=(j?X===q&&t:r)||null;if(c&&!(Date.now()-c>=z)&&(!o||i||u))return D&&!G&&0!==K&&K!==1/0&&s(C),A&&e(e=>e.queryKey!==q?{queryKey:q}:e),M&&console.log("[💾 Returning Cached Data 💾] for params:",JSON.stringify(C)),n?.data??null}const R=D?{key:q}:null,N=r?.cacheTime??(E?m(C):m);async function H(){const f=c?.storageKey||q;try{M&&(!o&&n&&x.some(e=>!(e in n))?console.log("[🔄 Fetching with Partial Params 🔄]\n","- Provided params:",`${JSON.stringify(n)}\n`,"- Filled in params:",`${JSON.stringify(Object.fromEntries(Object.keys(C).filter(e=>!(e in n)).map(e=>[e,C[e]])))}`):console.log("[🔄 Fetching 🔄] for params:",JSON.stringify(C)));const t=await(g&&D?async function(e){const t=new AbortController;Y=t;try{return await new Promise((n,r)=>{t.signal.addEventListener("abort",()=>r(P),At),Promise.resolve(l(e,t)).then(n,r)})}finally{Y===t&&(Y=null)}}(C):l(C,null)),c=Date.now();let d;M&&console.log("[✅ Fetch Successful ✅] for params:",JSON.stringify(C));try{d=function(e,t,n){return n?n(e,t):e}(t,C,p)}catch(e){throw Lt(f,"transform",e)}if(u)return M&&console.log("[🥷 Successful Parallel Fetch 🥷] for params:",JSON.stringify(C)),"withCache"===r.skipStoreUpdates&&e(e=>{if(!h)return j?e:{queryCache:{...e.queryCache,[q]:{cacheTime:N,data:d,errorInfo:null,lastFetchedAt:c}}};let t=e;const n=t.queryCache[q];try{h({data:d,params:C,queryKey:q,set:e=>{t="function"==typeof e?{...t,...e(t)}:{...t,...e}}})}catch(e){throw Lt(f,"setData",e)}return!j&&Object.is(n,t.queryCache[q])&&(t={...t,queryCache:{...t.queryCache,[q]:{cacheTime:N,data:null,errorInfo:null,lastFetchedAt:c}}}),t}),d;if((h?i:e)(e=>{let t={...e,error:null,lastFetchedAt:c,queryKey:A?q:e.queryKey,status:L.Success};if(h||j){if(h){M&&console.log("[💾 Setting Data 💾] for params:",JSON.stringify(C));const e=t.queryCache[q];try{h({data:d,params:C,queryKey:q,set:e=>{t="function"==typeof e?{...t,...e(t)}:{...t,...e}}})}catch(e){throw Lt(f,"setData",e)}!j&&Object.is(e,t.queryCache[q])&&(t.queryCache={...t.queryCache,[q]:{cacheTime:N,data:null,errorInfo:null,lastFetchedAt:c}})}}else M&&console.log("[💾 Setting Cache 💾] for params:",JSON.stringify(C),"| Has previous data?:",!!t.queryCache[q]?.data),t.queryCache={...t.queryCache,[q]:{cacheTime:N,data:d,errorInfo:null,lastFetchedAt:c}};return j||m===1/0?t:xt(k,q,t)}),D&&(X=q,s(C)),y)try{y({data:d,fetch:a.fetch,params:C,set:i})}catch(e){b.error(Lt(f,"onFetched callback",e))}return d??null}catch(n){if(n===P)return M&&console.log("[❌ Fetch Aborted ❌] for params:",JSON.stringify(C)),null;const i=!o&&!0===r?.throwOnError,s=v(n);if(s instanceof S&&b.error(s),!D){if(i)throw s;return null}const c=j?void 0:t().queryCache[q],u=c?.errorInfo?.retryCount??0,l=u+1;try{d?.(s,u)}catch(e){b.error(Lt(f,"onError callback",e))}if(u<I){if(t().enabled&&ne.hasSubscribers()){const e="function"==typeof T?T(l,s):T;e!==1/0&&(oe(),G=setTimeout(()=>{t().enabled&&a.fetch(C,zt,!0)},e))}e(e=>({error:s,queryCache:{...e.queryCache,[q]:{cacheTime:c?.cacheTime??N,data:c?.data??null,lastFetchedAt:c?.lastFetchedAt??null,errorInfo:{error:s,lastFailedAt:Date.now(),retryCount:l}}},queryKey:A?q:e.queryKey,status:L.Error}))}else e(e=>({error:s,queryCache:{...e.queryCache,[q]:{cacheTime:c?.cacheTime??N,data:c?.data??null,lastFetchedAt:c?.lastFetchedAt??null,errorInfo:{error:s,lastFailedAt:Date.now(),retryCount:I}}},queryKey:A?q:e.queryKey,status:L.Error}));if(i)throw s;return null}finally{Z===R&&(Z=null)}}return R&&(oe(),A&&!$&&null===f.lastFetchedAt&&O!==q?e({error:null,queryKey:q,status:L.Loading}):!w&&F||e({error:null,status:L.Loading}),Z=R),R?(R.promise=H(),R.promise):H()},getCacheEntry(e){if(j)return null;const n=t(),r=e?"string"==typeof e?e:W.buildKey(W.complete(e)):n.queryKey;return n.queryCache[r]??null},getData(e){if(j)return null;const n=t().getCacheEntry(e);return n&&null!==n.data?k?n.data:n.lastFetchedAt&&Date.now()-n.lastFetchedAt>=n.cacheTime?null:n.data:null},getStatus:function(e){const n=t(),r=n.status;switch(e){case"isIdle":return r===L.Idle;case"isLoading":return r===L.Loading;case"isError":case"isInitialLoad":case"isSuccess":case void 0:{const t=n.queryKey,o=n.queryCache[t],i=j?r===L.Error:"number"==typeof o?.errorInfo?.lastFailedAt;if("isError"===e)return i;const s=null!==((j?X===t&&n.lastFetchedAt:o?.lastFetchedAt)||null),c=!s&&!i&&n.enabled;if("isInitialLoad"===e)return c;const a=s&&!i;return"isSuccess"===e?a:{isError:i,isIdle:r===L.Idle,isLoading:r===L.Loading,isInitialLoad:c,isSuccess:a}}}},isDataExpired(e){const n=t(),r=n.queryCache[n.queryKey],o=n.queryKey,i=n.lastFetchedAt,s=(j?X===o&&i:r?.lastFetchedAt)||null;if(!s)return!0;const c=e??r?.cacheTime;return void 0===c||Date.now()-s>=c},isStale(e){const n=t(),r=n.queryKey,o=(j?X===r&&n.lastFetchedAt:n.queryCache[r]?.lastFetchedAt)||null;if(!o)return!0;const i=e??K;return Date.now()-o>=i},reset(t=!1){for(const e of V)e();V=[],W=jt(void 0,se,x),Q=null,_=null,re(),oe(),Z=null,X=null,t&&e(te)}},u=n.subscribe;return n.subscribe=(...e)=>{const t=U?void 0:ne.subscribe(),n=1===e.length?u(e[0]):u(e[0],e[1],e[2]);return e=>{t?.(e),n()}},a}const se=c?.storageKey?Ge(ie,f(c,{partialize:$t(k,c.partialize)})):o&&!("storageKey"in o)?Ge(ie,o):Ge(ie),ce=se.getState(),ae=ce.error,ue=ce.enabled,le=ce.queryKey,fe=ce.fetch;le&&!ae&&(X=le),U=!0,W=jt(q,se,x),"function"==typeof F&&(Q=kt(F,se)),"function"==typeof e.staleTime&&(_=kt(e.staleTime,se),K=_.initialValue);const de=function(e,t=queueMicrotask){let n,r=!1;function o(){r=!1,e(...n)}return function(...e){n=e,r||(r=!0,t(o))}}(e=>{fe(e,void 0,!0)},Et);function ye(){if(k)de(void 0);else{const e=W.get();se.setState({queryKey:W.buildKey(e)}),de(e)}}const he=s||!C?void 0:Pe(ye,"number"==typeof C?C:C.delay,"number"==typeof C?{leading:!1,maxWait:C,trailing:!0}:C);if(V.push(W.subscribe((e,t,n)=>{M&&console.log("[🌀 Param Change 🌀] -",e,"- [Old]:",`${t?.toString()},`,"[New]:",n?.toString()),function(){if(oe(),he){const e=se.getState();return void(k&&Z?.key===e.queryKey&&null===e.lastFetchedAt?ye():he())}ye()}()})),_){let e=_.initialValue;M&&console.log("[🌀 StaleTime Subscription 🌀] Initial value:",e),V.push(_.subscribe(t=>{t!==e&&(M&&console.log("[🌀 StaleTime Change 🌀] - [Old]:",`${e},`,"[New]:",t),e=t,K=t,oe(),fe(void 0,void 0,!0))}))}let pe;if(Q){let e=Q.initialValue;ue!==e&&((pe??(pe={})).enabled=e),M&&console.log("[🌀 Enabled Subscription 🌀] Initial value:",e),V.push(Q.subscribe(t=>{t!==e&&(M&&console.log("[🌀 Enabled Change 🌀] - [Old]:",`${e},`,"[New]:",t),e=t,se.setState({enabled:t}))}))}else ue!==te.enabled&&((pe??(pe={})).enabled=te.enabled);const ge=W.buildKey();return ge!==le&&((pe??(pe={})).queryKey=ge),pe&&se.setState(pe),U=!1,J(se,B.QueryStore)}function $t(e,t){return n=>{const r={...n},o=u();for(const e in r)d(r,e)&&e in Tt&&(Tt[e]&&(o[e]=r[e]),delete r[e]);return{...t?t(r):Me(r),...xt(e,null,o)}}}function xt(e,t,n){if(!n.queryCache)return n;const r=Date.now(),o=t??(e&&n.queryKey||null),i=u();let s=!1;for(const e in n.queryCache){if(!d(n.queryCache,e))continue;const c=n.queryCache[e];c&&(r-(c.lastFetchedAt??c.errorInfo.lastFailedAt)<c.cacheTime||e===o)?!t&&c.errorInfo&&c.errorInfo.retryCount>0?(i[e]={...c,errorInfo:{...c.errorInfo,retryCount:0}},s=!0):i[e]=c:s=!0}return s?{...n,queryCache:i}:n}function Rt(){return Object.create(null)}function Lt(e,t,n){return new S(`[createQueryStore: ${e}]: ${t} failed`,n)}function Nt(e,t,n){const r="function"==typeof t,o=r?t:void 0,i=r?n:t,s=new Set;let c;function a(e,t,n,r){u(e,t,n,r)&&ve()}function u(e,t,n,r){e.unsubscribe();const o=e.args;if(1===o.length){const i=o[0],s=t.subscribe(i);e.unsubscribe=s;const c=!Object.is(r,n);return c&&i(r,n),c}const i=o[0],s=o[1];let c=o[2];c?.fireImmediately&&(c={...c,fireImmediately:!1});const a=i(n),u=i(r),l=t.subscribe(i,s,c);return e.unsubscribe=l,!(c?.equalityFn??Object.is)(a,u)&&(s(u,a),!0)}function l(e,t){!function(e,t){const n=e.getState(),r=t.getState();if(c)for(const e of c)a(e,t,n,r);s.size&&we();for(const e of s)u(e,t,n,r)}(t,e),Q(t)}const f=mt(e,{debugMode:i?.debugMode??!1,lockDependencies:i?.lockDependencies??!0});let d;function h(){return d??(d=f.subscribe(l)),f.getState()}const p=Object.assign({[B.VirtualStore]:!0,destroy:()=>{d?.(),d=void 0,f.destroy()},getInitialState:()=>h().getInitialState(),getState:()=>h().getState(),persist:(g=h,{clearStorage:()=>g().persist?.clearStorage(),getOptions:()=>g().persist?.getOptions()??{},hasHydrated:()=>g().persist?.hasHydrated()??!0,hydrationPromise:()=>g().persist?.hydrationPromise?.()??Promise.resolve(),onFinishHydration:e=>g().persist?.onFinishHydration(e)??y,onHydrate:e=>g().persist?.onHydrate(e)??y,rehydrate:()=>g().persist?.rehydrate(),setOptions:e=>g().persist?.setOptions(e)}),setState:Ht(h),subscribe:function(...e){const t=h(),n={args:e,unsubscribe:1===e.length?t.subscribe(e[0]):t.subscribe(e[0],e[1],e[2])},r=e[2]?.isCascadeParticipant??!1;return r?(c??(c=new Set)).add(n):s.add(n),()=>{n.unsubscribe(),r?c?.delete(n)&&0===c.size&&(c=void 0):s.delete(n)}}},o?.(h));var g;return p}function Ht(e){return function(...t){return!0===t[1]?e().setState(t[0],!0):e().setState(t[0])}}export{K as DEFAULT_STORAGE_KEY_PREFIX,L as QueryStatuses,B as StoreTags,S as StoresError,U as applyStateUpdate,J as assignStoreTag,Ge as baseStore,E as configureStores,re as createStoreActions,se as deepEqual,H as defaultRetryDelay,mt as derivedStore,Q as destroyStore,_ as destroyStores,v as ensureError,D as getOptions,M as getStorageConfig,Y as getStoreName,Z as hasDestroy,G as hasGetSnapshot,ee as isDerivedStore,te as isPersistedStore,X as isQueryStore,ne as isVirtualStore,b as logger,$ as markStoreCreated,Mt as queryStore,m as setLogger,ce as shallowEqual,N as time,Nt as virtualStore};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storesjs/stores",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "repository": {
@@ -1,12 +0,0 @@
1
- import type { AttachValue } from '../queryStore/signalTypes';
2
- import type { StoreApi } from '../store/types';
3
- import type { EqualityFn, Selector, UnsubscribeFn } from '../types/subscribe';
4
- export declare const attachValueSubscriptionMap: WeakMap<AttachValue<unknown>, Subscribe>;
5
- export type Subscribe = (callback: () => void) => UnsubscribeFn;
6
- export type GetValue = () => unknown;
7
- export type SetValue = (path: unknown[], value: unknown) => void;
8
- export declare function $<T>(store: StoreApi<T>): AttachValue<T>;
9
- export declare function $<T, S>(store: StoreApi<T>, selector: Selector<T, S>, equalityFn?: EqualityFn<S>): AttachValue<S>;
10
- export declare const createSignal: <T, S>(store: StoreApi<T>, selector: Selector<T, S>, equalityFn: EqualityFn<S>) => [Subscribe, GetValue, SetValue];
11
- export declare function getAttachValueSubscribeFn<AttachVal extends AttachValue<unknown>>(attachVal: AttachVal): Subscribe | undefined;
12
- //# sourceMappingURL=signal.d.ts.map
@@ -1,14 +0,0 @@
1
- import type { StoreApi } from '../store/types';
2
- import type { EqualityFn, Selector } from '../types/subscribe';
3
- type NestedAttachValue<T> = T extends object ? {
4
- readonly [K in keyof T]: AttachValue<T[K]>;
5
- } : Record<string, never>;
6
- export type AttachValue<T> = {
7
- readonly value: T;
8
- } & NestedAttachValue<T>;
9
- export type SignalFunction = {
10
- <T>(store: StoreApi<T>): AttachValue<T>;
11
- <T, S>(store: StoreApi<T>, selector: Selector<T, S>, equalityFn?: EqualityFn<S>): AttachValue<S>;
12
- };
13
- export {};
14
- //# sourceMappingURL=signalTypes.d.ts.map
@@ -1,11 +0,0 @@
1
- import type { AttachValue } from '../queryStore/signalTypes';
2
- import type { StoreApi } from '../store/types';
3
- import type { EqualityFn, Selector, UnsubscribeFn } from '../types/subscribe';
4
- export declare const attachValueSubscriptionMap: WeakMap<AttachValue<unknown>, Subscribe>;
5
- export type Subscribe = (callback: () => void) => UnsubscribeFn;
6
- export type GetValue = () => unknown;
7
- export type SetValue = (path: unknown[], value: unknown) => void;
8
- export declare function $<T>(store: StoreApi<T>): AttachValue<T>;
9
- export declare function $<T, S>(store: StoreApi<T>, selector: Selector<T, S>, equalityFn?: EqualityFn<S>): AttachValue<S>;
10
- export declare const createSignal: <T, S>(store: StoreApi<T>, selector: Selector<T, S>, equalityFn: EqualityFn<S>) => [Subscribe, GetValue, SetValue];
11
- export declare function getAttachValueSubscribeFn<AttachVal extends AttachValue<unknown>>(attachVal: AttachVal): Subscribe | undefined;
@@ -1,13 +0,0 @@
1
- import type { StoreApi } from '../store/types';
2
- import type { EqualityFn, Selector } from '../types/subscribe';
3
- type NestedAttachValue<T> = T extends object ? {
4
- readonly [K in keyof T]: AttachValue<T[K]>;
5
- } : Record<string, never>;
6
- export type AttachValue<T> = {
7
- readonly value: T;
8
- } & NestedAttachValue<T>;
9
- export type SignalFunction = {
10
- <T>(store: StoreApi<T>): AttachValue<T>;
11
- <T, S>(store: StoreApi<T>, selector: Selector<T, S>, equalityFn?: EqualityFn<S>): AttachValue<S>;
12
- };
13
- export {};
@@ -1 +0,0 @@
1
- function t(t,e){return e instanceof Map?{__type:"Map",entries:Array.from(e.entries())}:e instanceof Set?{__type:"Set",values:Array.from(e)}:e}function e(t,e){return function(t){return"object"==typeof t&&null!==t&&"__type"in t&&"Map"===t.__type}(e)?new Map(e.entries):function(t){return"object"==typeof t&&null!==t&&"__type"in t&&"Set"===t.__type}(e)?new Set(e.values):e}var n=Object.prototype.hasOwnProperty;function r(t,e){return n.call(t,e)}function o(t){if("object"!=typeof t||null===t)return!1;const e=Object.getPrototypeOf(t);return null===e||e===Object.prototype}function u(t){return null!==t&&"object"==typeof t&&!Array.isArray(t)}function p(t){return!!t&&"object"==typeof t&&"then"in t&&"function"==typeof t.then}export{r as hasOwn,o as isPlainObject,p as isPromiseLike,u as isRecordLike,t as replacer,e as reviver};
@@ -1 +0,0 @@
1
- var e="undefined"!=typeof window&&"undefined"!=typeof document,n=!1,t="development"===process.env.NODE_ENV,c="test"===process.env.NODE_ENV,o=Object.freeze(Object.create(null));function r(e){return e}function u(){return Object.create(o)}function i(e,n){return void 0===n?Object.assign(u(),e):Object.assign(u(),e,n)}function f(){}export{e as IS_BROWSER,t as IS_DEV,n as IS_IOS,c as IS_TEST,i as buildNullObject,r as identity,f as noop,u as nullObject};