@storesjs/stores 0.11.0 β 0.12.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.
- package/dist/index.d.ts +1583 -4
- package/dist/native/index.js +7 -1
- package/dist/native/index.mjs +7 -1
- package/dist/plugins/chrome/index.d.ts +186 -4
- package/dist/vanilla/index.js +1 -1
- package/dist/vanilla/index.mjs +1 -1
- package/dist/vanilla/index.vanilla.d.ts +1469 -1
- package/dist/web/chrome.js +1 -1
- package/dist/web/chrome.mjs +1 -1
- package/dist/web/index.js +1 -1
- package/dist/web/index.mjs +1 -1
- package/dist/web/internal/runtime.js +2 -1
- package/dist/web/internal/runtime.mjs +2 -1
- package/dist/web/queryParam-Ckp7Zi5t.mjs +1 -0
- package/dist/web/queryParam-Ctnhipnd.js +1 -0
- package/dist/web/serialization-BgaGfw_1.mjs +1 -0
- package/dist/web/serialization-Dau9pNHc.js +1 -0
- package/dist/web/utils-Ba1RIeAA.mjs +1 -0
- package/dist/web/utils-CwejruRb.js +1 -0
- package/package.json +7 -7
- package/dist/createBaseStore.d.ts +0 -36
- package/dist/createDerivedStore.d.ts +0 -63
- package/dist/createQueryStore.d.ts +0 -111
- package/dist/createVirtualStore.d.ts +0 -40
- package/dist/env.native.d.ts +0 -7
- package/dist/env.web.d.ts +0 -7
- package/dist/hooks/useLazyRef.d.ts +0 -13
- package/dist/hooks/useListen.d.ts +0 -98
- package/dist/hooks/useStableValue.d.ts +0 -16
- package/dist/hooks/useSyncExternalStoreWithSelector.d.ts +0 -5
- package/dist/index.shared.d.ts +0 -14
- package/dist/index.vanilla.d.ts +0 -2
- package/dist/internal/baseStore.d.ts +0 -2
- package/dist/internal/config.d.ts +0 -64
- package/dist/internal/createStoreActions.d.ts +0 -24
- package/dist/internal/derivedStore/deriveProxy.d.ts +0 -15
- package/dist/internal/derivedStore/pathFinder.d.ts +0 -26
- package/dist/internal/derivedStore.d.ts +0 -2
- package/dist/internal/errors.d.ts +0 -10
- package/dist/internal/logger.d.ts +0 -10
- package/dist/internal/middleware/createHydrationGate.d.ts +0 -20
- package/dist/internal/queryStore/queryParams.d.ts +0 -18
- package/dist/internal/queryStore/queryStoreDefaults.d.ts +0 -8
- package/dist/internal/queryStore.d.ts +0 -2
- package/dist/internal/runtime.d.ts +0 -12
- package/dist/internal/storage/storageCreators.d.ts +0 -12
- package/dist/internal/storeUtils.d.ts +0 -46
- package/dist/internal/sync/browserSyncEngine.d.ts +0 -3
- package/dist/internal/sync/noopSyncEngine.d.ts +0 -3
- package/dist/internal/sync/syncEnhancer.d.ts +0 -26
- package/dist/internal/sync/syncUtils.d.ts +0 -6
- package/dist/internal/types/internalSubscribeTypes.d.ts +0 -16
- package/dist/internal/utils/persistUtils.d.ts +0 -9
- package/dist/internal/virtualStore.d.ts +0 -2
- package/dist/plugins/chrome/chromeExtensionSyncEngine.d.ts +0 -30
- package/dist/plugins/chrome/chromeStorageAdapter.d.ts +0 -31
- package/dist/plugins/chrome/createSyncedChromeStorage.d.ts +0 -14
- package/dist/queryStore/classes/SubscriptionManager.d.ts +0 -39
- package/dist/queryStore/queryKey.d.ts +0 -10
- package/dist/queryStore/queryParam.d.ts +0 -37
- package/dist/queryStore/types.d.ts +0 -361
- package/dist/storage/storageTypes.d.ts +0 -13
- package/dist/store/attachStoreHook.react.d.ts +0 -5
- package/dist/store/attachStoreHook.vanilla.d.ts +0 -6
- package/dist/store/batchStoreNotifications.native.d.ts +0 -3
- package/dist/store/batchStoreNotifications.web.d.ts +0 -2
- package/dist/store/cascadeScheduler.d.ts +0 -38
- package/dist/store/createStore.d.ts +0 -6
- package/dist/store/persist.d.ts +0 -14
- package/dist/store/stateUpdate.d.ts +0 -10
- package/dist/store/types.d.ts +0 -108
- package/dist/storesStorage.native.d.ts +0 -3
- package/dist/storesStorage.web.d.ts +0 -3
- package/dist/sync/types.d.ts +0 -115
- package/dist/types/functions.d.ts +0 -24
- package/dist/types/objects.d.ts +0 -11
- package/dist/types/setState.d.ts +0 -22
- package/dist/types/subscribe.d.ts +0 -27
- package/dist/types/useStoreCallSignatures.d.ts +0 -2
- package/dist/types/useStoreCallSignatures.react.d.ts +0 -6
- package/dist/types/useStoreCallSignatures.vanilla.d.ts +0 -2
- package/dist/types/utils.d.ts +0 -13
- package/dist/types.d.ts +0 -288
- package/dist/utils/core.d.ts +0 -26
- package/dist/utils/createAsyncMicrotaskScheduler.d.ts +0 -35
- package/dist/utils/createMicrotaskScheduler.d.ts +0 -29
- package/dist/utils/debounce.d.ts +0 -22
- package/dist/utils/equality.d.ts +0 -38
- package/dist/utils/hydrationCoordinator.d.ts +0 -13
- package/dist/utils/promiseUtils.d.ts +0 -2
- package/dist/utils/serialization.d.ts +0 -14
- package/dist/utils/stringUtils.d.ts +0 -7
- package/dist/utils/time.d.ts +0 -37
- package/dist/vanilla/createBaseStore.d.ts +0 -35
- package/dist/vanilla/createDerivedStore.d.ts +0 -62
- package/dist/vanilla/createQueryStore.d.ts +0 -110
- package/dist/vanilla/createVirtualStore.d.ts +0 -39
- package/dist/vanilla/env.web.d.ts +0 -6
- package/dist/vanilla/index.d.ts +0 -1
- package/dist/vanilla/index.shared.d.ts +0 -13
- package/dist/vanilla/internal/baseStore.d.ts +0 -1
- package/dist/vanilla/internal/config.d.ts +0 -63
- package/dist/vanilla/internal/createStoreActions.d.ts +0 -23
- package/dist/vanilla/internal/derivedStore/deriveProxy.d.ts +0 -14
- package/dist/vanilla/internal/derivedStore/pathFinder.d.ts +0 -25
- package/dist/vanilla/internal/derivedStore.d.ts +0 -1
- package/dist/vanilla/internal/errors.d.ts +0 -9
- package/dist/vanilla/internal/logger.d.ts +0 -9
- package/dist/vanilla/internal/middleware/createHydrationGate.d.ts +0 -19
- package/dist/vanilla/internal/queryStore/queryParams.d.ts +0 -17
- package/dist/vanilla/internal/queryStore/queryStoreDefaults.d.ts +0 -7
- package/dist/vanilla/internal/queryStore.d.ts +0 -1
- package/dist/vanilla/internal/runtime.d.ts +0 -11
- package/dist/vanilla/internal/storage/storageCreators.d.ts +0 -11
- package/dist/vanilla/internal/storeUtils.d.ts +0 -45
- package/dist/vanilla/internal/sync/browserSyncEngine.d.ts +0 -2
- package/dist/vanilla/internal/sync/noopSyncEngine.d.ts +0 -2
- package/dist/vanilla/internal/sync/syncEnhancer.d.ts +0 -25
- package/dist/vanilla/internal/types/internalSubscribeTypes.d.ts +0 -15
- package/dist/vanilla/internal/utils/persistUtils.d.ts +0 -8
- package/dist/vanilla/internal/virtualStore.d.ts +0 -1
- package/dist/vanilla/queryStore/classes/SubscriptionManager.d.ts +0 -38
- package/dist/vanilla/queryStore/queryKey.d.ts +0 -9
- package/dist/vanilla/queryStore/queryParam.d.ts +0 -36
- package/dist/vanilla/queryStore/types.d.ts +0 -360
- package/dist/vanilla/storage/storageTypes.d.ts +0 -12
- package/dist/vanilla/store/attachStoreHook.d.ts +0 -5
- package/dist/vanilla/store/attachStoreHook.vanilla.d.ts +0 -5
- package/dist/vanilla/store/batchStoreNotifications.web.d.ts +0 -1
- package/dist/vanilla/store/cascadeScheduler.d.ts +0 -37
- package/dist/vanilla/store/createStore.d.ts +0 -5
- package/dist/vanilla/store/persist.d.ts +0 -13
- package/dist/vanilla/store/stateUpdate.d.ts +0 -9
- package/dist/vanilla/store/types.d.ts +0 -107
- package/dist/vanilla/storesStorage.web.d.ts +0 -2
- package/dist/vanilla/sync/types.d.ts +0 -114
- package/dist/vanilla/types/functions.d.ts +0 -23
- package/dist/vanilla/types/objects.d.ts +0 -10
- package/dist/vanilla/types/setState.d.ts +0 -21
- package/dist/vanilla/types/subscribe.d.ts +0 -26
- package/dist/vanilla/types/useStoreCallSignatures.d.ts +0 -1
- package/dist/vanilla/types/useStoreCallSignatures.vanilla.d.ts +0 -1
- package/dist/vanilla/types/utils.d.ts +0 -12
- package/dist/vanilla/types.d.ts +0 -287
- package/dist/vanilla/utils/core.d.ts +0 -25
- package/dist/vanilla/utils/createAsyncMicrotaskScheduler.d.ts +0 -34
- package/dist/vanilla/utils/createMicrotaskScheduler.d.ts +0 -28
- package/dist/vanilla/utils/debounce.d.ts +0 -21
- package/dist/vanilla/utils/equality.d.ts +0 -37
- package/dist/vanilla/utils/hydrationCoordinator.d.ts +0 -12
- package/dist/vanilla/utils/promiseUtils.d.ts +0 -1
- package/dist/vanilla/utils/serialization.d.ts +0 -13
- package/dist/vanilla/utils/stringUtils.d.ts +0 -6
- package/dist/vanilla/utils/time.d.ts +0 -36
- package/dist/web/chunk-FENSEQ3V.mjs +0 -1
- package/dist/web/chunk-FPYZVFBM.mjs +0 -1
- package/dist/web/chunk-PLDNKWGX.mjs +0 -1
package/dist/native/index.js
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
var e=require("react"),t=require("react-native"),n=(e=>"undefined"!=typeof require?require:"undefined"!=typeof Proxy?new Proxy(e,{get:(e,t)=>("undefined"!=typeof require?require:e)[t]}):e)(function(e){if("undefined"!=typeof require)return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')}),r="ios"===t.Platform.OS;t.Platform.OS;var o="development"===process.env.NODE_ENV,i="test"===process.env.NODE_ENV;function s(e){return e}function c(){return{__proto__:null}}function a(){}Object.freeze(Object.create(null));var u=Symbol("empty selection"),l=Object.is;function f(e,t){return n=>(function(e){e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedSource=e.source,e.committedValue=e.value===u?d(e):e.value}(e),t(r=>{e.latestSnapshot=r,e.latestSource=t;const o=e.committedValue;if(o===u||e.committedSource!==t)return void n();const i=e.committedSelector,s=e.committedEqualityFn;if(e.selector===i&&e.equalityFn===s){const t=i(r);if(s===l?l(o,t):s(o,t))return;return e.committedValue=t,e.value=t,e.valueEqualityFn=s,e.valueSelector=i,e.valueSnapshot=r,void n()}if(e.source!==t)return void n();const c=e.value;if(c===u)return;const a=e.selector(r),f=e.equalityFn(c,a);e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedValue=p(e,r,f?c:a),f||n()}))}function d(e){const t=function(e){if(e.latestSource===e.source&&e.latestSnapshot!==u)return e.latestSnapshot;const t=e.getStoreSnapshot();return e.latestSnapshot=t,e.latestSource=e.source,t}(e);return y(e,t)}function y(e,t){const n=e.value;if(n!==u&&l(e.valueSnapshot,t)&&e.valueSelector===e.selector&&e.valueEqualityFn===e.equalityFn)return n;const r=e.selector(t);if(n!==u&&(e.equalityFn===l?l(n,r):e.equalityFn(n,r)))return p(e,t,n);const o=e.committedValue;return o!==u&&o!==n&&e.committedSource===e.source&&(e.equalityFn===l?l(o,r):e.equalityFn(o,r))?p(e,t,o):p(e,t,r)}function p(e,t,n){return e.value=n,e.valueEqualityFn=e.equalityFn,e.valueSelector=e.selector,e.valueSnapshot=t,n}function h(t,n,r,o){return Object.assign(function(i,s){return function(t,n,r,o,i=l){const s=e.useRef(null);let c=t,p=n,h=r;if(o){let e=s.current;null===e&&(e=function(e,t,n,r,o){const i={committedEqualityFn:o,committedSelector:r,committedSource:e,committedValue:u,equalityFn:o,getSelectedServerSnapshot:()=>function(e){return y(e,(e.getServerStoreSnapshot??e.getStoreSnapshot)())}(i),getSelectedSnapshot:()=>d(i),getServerStoreSnapshot:n,getStoreSnapshot:t,latestSnapshot:u,latestSource:u,selector:r,selectedSource:e,selectedSubscribe:()=>a,source:e,value:u,valueEqualityFn:o,valueSelector:r,valueSnapshot:u};return i.selectedSubscribe=f(i,e),i}(t,n,r,o,i),s.current=e),function(e,t,n,r,o,i){e.source===t&&e.getStoreSnapshot===n||(e.latestSnapshot=u),e.source=t,e.getStoreSnapshot=n,e.getServerStoreSnapshot=r,e.selector=o,e.equalityFn=i,e.selectedSource!==t&&(e.selectedSource=t,e.selectedSubscribe=f(e,t))}(e,t,n,r,o,i),c=e.selectedSubscribe,p=e.getSelectedSnapshot,h=void 0===r?void 0:e.getSelectedServerSnapshot}const g=e.useSyncExternalStore(c,p,h);return e.useDebugValue(g),g}(t.subscribe,n,r,i,s??o)},t)}function g(e){let t;function r(){if(t)return t;try{const r=function(e){const{createMMKV:t,MMKV:r}=n("react-native-mmkv");if("function"==typeof t)return t({id:e});if("function"==typeof r)return new r({id:e});throw new Error("[stores]: react-native-mmkv module does not export MMKV/createMMKV.")}(e);let o;if("function"==typeof r.delete?o=r.delete.bind(r):"function"==typeof r.remove&&(o=r.remove.bind(r)),"function"!=typeof o)throw new Error("[stores]: Storage instance does not conform to expected interface");const i={clearAll:r.clearAll.bind(r),contains:r.contains.bind(r),delete:o,get:r.getString.bind(r),getAllKeys:r.getAllKeys.bind(r),set:r.set.bind(r)};t=i}catch(e){throw new Error("[stores] react-native-mmkv could not be loaded.\n\nPersisted stores require a storage backend. Either:\n - Install MMKV (the default): yarn add react-native-mmkv\n - Or provide a custom adapter via configureStores()\n"+(e instanceof Error?`\n${e.message}`:""))}return function(e){if(!e||"function"!=typeof e.get||"function"!=typeof e.set||"function"!=typeof e.delete||"function"!=typeof e.clearAll)throw new Error("[stores]: Storage instance does not conform to expected interface")}(t),t}return{clearAll:()=>r().clearAll(),contains:e=>r().contains(e),delete:e=>r().delete(e),get:e=>r().get(e),getAllKeys:()=>r().getAllKeys(),set:(e,t)=>r().set(e,t)}}var b={debug:(e,t)=>{o&&console.debug(e,t)},error:(e,t)=>{o&&!i&&console.error(e,t)},info:(e,t)=>{o&&console.info(e,t)},warn:(e,t)=>{o&&console.warn(e,t)}},m=Object.prototype.hasOwnProperty;function S(e,t){return m.call(e,t)}function v(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}function w(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}var O=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 q(e){return e instanceof Error?e:new Error(String(e))}var j,F,_,k=class{destroy(){}publish(){}},A=class{constructor(){this.sessionId="noop"}register(e){return new k}},I=!1;function C(){return _??(_=z(void 0))}function x(){I=!0}function z(e){return{storage:e?.storage??g(e?.storageKeyPrefix??"stores:"),syncEngine:e?.syncEngine??(j||(j=new A),j)}}var E,T={Error:"error",Idle:"idle",Loading:"loading",Success:"success"},P={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??P.seconds(5),r=t?.maxDelay??P.minutes(5);return Math.min(n*Math.pow(2,e),r)}function D(e,t){return!0===t[1]?e(t[0],!0):e(t[0])}function K(e,t,n){if(!0===n)return R(t)?t(e):t;const r=R(t)?t(e):t;return Object.is(r,e)?e:w(e)&&w(r)?{...e,...r}:r}function R(e){return"function"==typeof e}function $(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 V(e,t){W(e)?e.getState().reset(t?.clearQueryCache):function(e){return"destroy"in e}(e)&&e.destroy()}function H(e){return"getSnapshot"in e}function W(e){return N.QueryStore in e}function U(e){return!(!("persist"in e)||!e.persist)&&"string"==typeof e.persist.getOptions().name}function J(e){return N.VirtualStore in e}function B(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 Q(e,t){return"function"==typeof e[t]}function G(e,t){const n=Object.prototype.hasOwnProperty;function r(e,t){for(const n of e.keys())if(G(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--&&G(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(!G(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)||!G(e[r],t[r]))return!1}return Object.keys(t).length===i}}return e!=e&&t!=t}var X=t.unstable_batchedUpdates,Y=!1,Z=!1,ee=!1,te=new Set,ne=new Map,re=new Map,oe=null,ie=1/0;function se(){return Y}function ce(){return oe}function ae(){Y||(Y=!0,ee||(ee=!0,queueMicrotask(()=>{ee=!1,ue()})))}function ue(){if(Y)if(Z)fe();else{Z=!0;try{X(fe)}finally{pe()}}}function le(e){Y&&te.add(e)}function fe(){for(;ne.size>0||te.size>0;)de(),ye()}function de(){for(;ne.size>0;){const e=ie,t=re.get(e);if(t){re.delete(e);for(const e of t)ne.delete(e);oe=e;for(const e of t)e();oe=null,ie=1/0;for(const e of re.keys())e<ie&&(ie=e)}else{ie=1/0;for(const e of re.keys())e<ie&&(ie=e)}}}function ye(){for(const e of te)te.delete(e),e()}function pe(){Y=!1,Z=!1,oe=null,te.clear(),ne.clear(),re.clear(),ie=1/0}function he(e){let t;const n=new Set;let r;function o(...e){const o=K(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&&ue();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&&ae(),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 ge(e){return!!e&&"object"==typeof e&&"then"in e&&"function"==typeof e.then}function be(e){return{...e,merge:e.merge??me,skipHydration:e.skipHydration??!1}}function me(e,t){return void 0===e?t:{...t,...e}}function Se(){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 ve=Math.max,we=Math.min;function Oe(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 p(e){const n=e-(a??0);return void 0===a||n>=t||n<0||f&&void 0!==i&&e-u>=i}function h(){const e=qe();if(p(e))return g(e);c=setTimeout(h,function(e){const n=t-(e-(a??0));return f&&void 0!==i?we(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=qe(),i=p(n);if(r=e,o=this,a=n,i){if(void 0===c)return function(e){return u=e,c=setTimeout(h,t),l?y(e):s}(a);if(f)return clearTimeout(c),c=setTimeout(h,t),y(a)}return void 0===c&&(c=setTimeout(h,t)),s}return t=je(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?ve(je(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(qe())},b}function qe(){return"undefined"!=typeof performance&&"function"==typeof performance.now?performance.now():Date.now()}function je(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 Fe(e){if(!v(e))return e;const t={__proto__:null},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=i?0:P.seconds(r?3:5);function ke(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??Fe,c=t.deserializer??e.deserializer??Ie(o),a=t.serializer??e.serializer??Ce(o);function u(t,n,o){try{if(Te(r))return;const c={state:s(n),version:o},u=ze(r,i,c),l=a(c);try{e.set(t,l),Ee(r,u)}catch(e){b.error(new O("[createBaseStore]: Failed to persist store data",e))}}catch(e){b.error(new O("[createBaseStore]: Failed to persist store data",e))}}const l=void 0!==n?Oe(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 O("[createBaseStore]: Failed to delete persisted store data",e))}}}}function Ae(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??Fe,c=t.deserializer??e.deserializer??Ie(o),a=t.serializer??e.serializer??Ce(o);async function u(t,n,o){try{if(Te(r))return;const c={state:s(n),version:o},u=ze(r,i,c),l=a(c);try{await e.set(t,l),Ee(r,u)}catch(e){b.error(new O("[createBaseStore]: Failed to persist store data",e))}}catch(e){b.error(new O("[createBaseStore]: Failed to serialize persisted store data",e))}}const l=void 0!==n?Oe(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 O("[createBaseStore]: Failed to delete persisted store data",e))}}}}function Ie(e){return t=>{if("string"!=typeof t)throw new O("[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 b.error(new O("[createBaseStore]: Failed to deserialize persisted store data",e)),e}}(t,e)}}function Ce(e){return t=>function(e,t){try{return JSON.stringify(e,t?$:void 0)}catch(e){throw b.error(new O("[createBaseStore]: Failed to serialize store data",e)),e}}(t,e)}var xe=Object.freeze({shouldClear:!1});function ze(e,t,n){if(!t||!e)return xe;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 Ee(e,t){e&&t.shouldClear&&t.fieldSnapshot&&Object.keys(t.fieldSnapshot).length&&e.clearFieldTimestamps(t.fieldSnapshot)}function Te(e){return!!e&&!!e.getIsApplyingRemote()}var[Pe,Me]=[0,1];function De(e,t,n){if(!e)return!0;const r=e[Pe],o=e[Me];return!(t<r)&&(t>r||n>o)}function Ke(e,t){return Object.prototype.hasOwnProperty.call(t,e)}function Re(e,t){if(!o)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 $e(e){if(null===e)return"null";const t=typeof e;return"object"===t?Object.prototype.toString.call(e):t}function Le(e,t){if(x(),!t)return he(e);const n=t.storageKey,r="string"==typeof n,o=r?t.storage??C().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 O("[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??C().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,c)=>{const a=new Map,u=[],l=[];let f=null,d=!1,y=!1,p=0,h=null,g=[],m=Promise.resolve(),S=!n;function v(e,t){if(o?.setSessionId&&o?.setTimestamp&&r.sessionId&&(o.setSessionId(r.sessionId),o.setTimestamp(e),o.mergeFieldTimestamps&&t.length>0)){const n={__proto__:null};for(const r of t)n[String(r)]=e;o.mergeFieldTimestamps(n)}}function w(e,t){if(d||!h)return t?i(e,t):i(e);const n=function(){const e=Date.now(),t=e>p?e:p+1;return p=t,t}();let o=[],s={__proto__:null};const c=r=>{const i=K(r,e,t);for(const e of g)Object.is(i[e],r[e])||(o.push(e),s[e]=i[e]);return o.length&&v(n,o),i},u=t?i(c,!0):i(c);function b(){o.length&&function(e){const t=r.sessionId;for(const n of e.keys)a.set(n,[e.timestamp,t]);f&&y?f.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 ge(u)?u.finally(b):(b(),u)}const q=c.setState;c.setState=w;const j=e(w,s,c);if(g=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}(j),!g.length)return j;async function F(e){p=Math.max(p,e.timestamp);const n={__proto__:null},r=s(),i=e.timestamp;let c;if(e.replace)for(const t of g)Ke(t,e.values)||De(a.get(t),i,e.sessionId)&&(c??(c=[])).push(t);for(const o of g){if(!Ke(o,e.values))continue;if(!h?.has(o))continue;if(!De(a.get(o),i,e.sessionId))continue;const s=t.merge?.[o];if(s){const t=e.values[o],c=r[o];if(void 0!==t){const u=s(t,c,r,e.values),l=void 0!==c?c:t;if(!Re(u,l))return void b.error(new O(`[sync] Merge function for field "${String(o)}" returned ${$e(u)} but expected ${$e(l)}`));n[o]=u,a.set(o,[i,e.sessionId])}}else n[o]=e.values[o],a.set(o,[i,e.sessionId])}if(Object.keys(n).length>0||c?.length){d=!0,o&&o.setIsApplyingRemote(!0);try{if(e.replace){const e={...r};let t=!1;if(c?.length){t=!0;for(const t of c)delete e[t],a.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??q)(e,!0)}else await(o.setWithoutPersist??q)(n)}finally{d=!1,o&&o.setIsApplyingRemote(!1)}}}function _(e){n?m=m.then(()=>F(e)):F(e)}if(h=new Set(g),f=r.register({apply:e=>{S?_(e):u.push(e)},fields:g,getState:s,key:t.key}),f?.onFirstSubscribe||f?.onLastUnsubscribe){let e=0;const t=c.subscribe;c.subscribe=(...n)=>{e||f.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||f.onLastUnsubscribe?.()})}}}function k(){y=!0,function(){if(f&&l.length){for(const e of l){const t=r.sessionId;for(const n of e.keys)a.set(n,[e.timestamp,t]);v(e.timestamp,e.keys),f.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values})}l.length=0}}()}function A(){S=!0,function(){if(!u.length)return;const e=u.slice();u.length=0;for(const t of e)_(t)}()}return n?(o.onHydrationComplete=k,o.onHydrationFlushEnd=A):f.onHydrated?(f.onHydrated(k),A()):(k(),A()),j},syncContext:o}}(e,i,o?.async??!1):void 0,c=s?.stateCreator??e;if(!r)return he(c);const a=function(e,t,n){const r=t??e.storage??C().storage,o=(e.sync?void 0:e.persistThrottleMs??_e)||void 0,i=e.version??0;return r.async?{async:!0,persistStorage:Ae(r,e,o,n),version:i}:{async:!1,persistStorage:ke(r,e,o,n),version:i}}(t,o,s?.syncContext),u=a.async?function(e){let t,n,r,o=!1;return{hydrationPromise:()=>o?t?.promise??n??(n=Promise.resolve()):(t||(t=Se()),t.promise),stateCreator:(n,i,s)=>{let c;return r=()=>{if(c?.length){for(const e of c)D(s.setState,e);c=void 0}},e(function(...e){return o?D(n,e):(t||(t=Se()),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(q(i)):t?.complete(),s?.(e,i)}}}}(c):void 0,l=u?u.wrapOnRehydrateStorage(t.onRehydrateStorage,s?.syncContext):t.onRehydrateStorage,f=he(function(e,t){return(n,r,o)=>{let i,s,c,a=be(t),u=!1,l=0;function f(){return a.storage.setItem(a.name,r(),a.version)}const d=o.setState;o.setState=function(...e){return D(d,e),f()};const y=e(function(...e){return D(n,e),f()},r,o);function p(){const e=function(){const e=++l;return u=!1,s?.forEach(e=>e(r()??y)),e}(),t=a.onRehydrateStorage?.(r()??y);try{const n=a.storage.getItem(a.name);return ge(n)?n.then(n=>h(e,n,t)).catch(n=>m(e,t,n)):h(e,n,t)}catch(n){m(e,t,n)}}return o.getInitialState=()=>y,Object.assign(o,{persist:{clearStorage:()=>{a.storage.removeItem(a.name)},getOptions:()=>a,hasHydrated:()=>u,onFinishHydration:e=>(c??(c=new Set),c.add(e),()=>{c?.delete(e),0===c?.size&&(c=void 0)}),onHydrate:e=>(s??(s=new Set),s.add(e),()=>{s?.delete(e),0===s?.size&&(s=void 0)}),rehydrate:p,setOptions:e=>{a=be({...a,...e,storage:e.storage??a.storage})}}}),a.skipHydration||p(),i??y;function h(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 ge(n)?n.then(e=>({migrated:!0,state:e})):{migrated:!0,state:n}}(a,t);return ge(r)?r.then(t=>g(e,t,n)).catch(t=>m(e,n,t)):g(e,r,n)}function g(e,t,o){const s=function(e,t){if(e!==l)return;const o=a.merge(t.state,r()??y);return i=o,n(o,!0),t.migrated?f():void 0}(e,t);if(ge(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,c?.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)):c,{merge:t.merge,migrate:t.migrate,name:n,onRehydrateStorage:l,storage:a.persistStorage,version:a.version}));return u?Object.assign(f,{persist:Object.assign(f.persist,{hydrationPromise:u.hydrationPromise})}):f}function Ne(e,t,n="s"){return 1===t?e:`${e}${n}`}var Ve=Symbol("stores.deriveProxy.unwrap");function He(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?We(e,r,t,n,new WeakSet,new WeakMap):(n(t,r,!0),e)}(H(e)?e.getSnapshot():e.getState(),e,n);return t.set(e,o),o}function We(e,t,n,r,o,i){return new Proxy(e,{get(s,c,a){if(c===Ve)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,We(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 Ue(e,t){if(!e||"object"!=typeof e)return e;const n=function(e){const t=Reflect.get(e,Ve);return t&&"object"==typeof t?t:void 0}(e);return n||(Array.isArray(e)?function(e,t){const n=Be(e,t);if(n)for(let t=0;t<e.length;t++)Je(e,String(t),n)}(e,t):v(e)&&function(e,t){const n=Be(e,t);if(n)for(const t of Reflect.ownKeys(e))Je(e,t,n)}(e,t),e)}function Je(e,t,n){const r=Reflect.getOwnPropertyDescriptor(e,t);if(!r||!("value"in r))return;const o=Ue(r.value,n);o!==r.value&&(r.value=o,Reflect.defineProperty(e,t,r))}function Be(e,t){const n=t??new WeakSet;return n.has(e)?null:(n.add(e),n)}var Qe=Object.freeze([]);function Ge(){const e=new Map;return{buildProxySubscriptions(t,n,r,o){const i=new Set;for(const t of e)Ye(t[1],t[0],[],0,i,r);!1!==o?.(i)&&function(e,t,n){for(const n of e){const e=n.invocation?nt(n.path,n.invocation):tt(n.path);t(n.store,e,n.path)}n&&function(e){const t=e.size;console.log(`[π‘ ${t} ${Ne("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}_${Ne("arg",o)})`:"()"}`}),null,2))}(e)}(i,t,n)},reset(){e.clear()},trackPath(t,n,r,o){let i=e.get(t);i||(i={__proto__:null},e.set(t,i)),Xe(i,n,0,r,o)}}}function Xe(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(Ze(n,t))return;const r=e.extraInvocations;if(r){for(let e=0;e<r.length;e++)if(Ze(r[e],t))return;r.push(t)}else e.extraInvocations=[t]}(e,o));e.children||(e.children={__proto__:null});const i=t[n];let s=e.children?.[i];s||(s={__proto__:null},e.children[i]=s),Xe(s,t,n+1,r,o)}function Ye(e,t,n,r,o,i=2){const s=e.children;if(!s)return void et(e,t,n,o);const c=Object.keys(s),a=c.length;if(0!==a)if(e.isLeaf||r>=i&&a>1){et(e,t,n,o);for(const e of c){const c=s[e];c.invocation&&Ye(c,t,[...n,e],r+1,o,i)}}else if(r<i&&a>1&&!e.isLeaf)for(const e of c)Ye(s[e],t,[...n,e],r+1,o,i);else{if(1===a){const e=c[0];return void Ye(s[e],t,[...n,e],r+1,o,i)}et(e,t,n,o)}else et(e,t,n,o)}function Ze(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 et(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 tt(e){return t=>rt(t,e)}function nt(e,t){const n=e.slice(0,-1),r=e[e.length-1];return e=>{const o=rt(e,n),i=o&&"object"==typeof o?Reflect.get(o,r):void 0;return"function"==typeof i?Reflect.apply(i,o,t.args??Qe):void 0}}function rt(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 ot=Symbol(),it=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});function st(e,t=Object.is){const{debounceOptions:n,debugMode:r,equalityFn:i,keepAlive:c,lockDependencies:a}="function"==typeof(l=t)?{debounceOptions:void 0,debugMode:!1,equalityFn:l,keepAlive:!1,lockDependencies:!1}:{debounceOptions:l.debounce,debugMode:(o&&l.debugMode)??!1,equalityFn:l.equalityFn??Object.is,keepAlive:l.keepAlive??!1,lockDependencies:l.lockDependencies??!1},u=new Set;var l;c&&u.add(ct);const f=new Set;let d,y,p=ot,h=!1,g=!1,b=!0,m=!0,S=0,v=!1,w=null,O=ot;function q(e,t,n){if(!m||!u.size)return(t??s)(e.getState());if(!t)return d||(d=new WeakMap),y||(y=Ge()),He(e,d,y.trackPath);const r=n?{equalityFn:n,isCascadeParticipant:!0}:it;return f.add(e.subscribe(t,T,r)),t(H(e)?e.getSnapshot():e.getState())}function j(e){for(const t of f)t(e);f.clear()}let F=!0;function _(){if(!b&&at(p))return p;b=!1,m&&j(!0);const t=p,n=at(t);g=!0;try{p=function(t){F=!0;const n=p,o=e(t),s=y?Ue(o):o;return at(n)&&i(n,s)?(r&&console.log("[π₯· Derive Complete π₯·]: No change detected"),F=!1,n):s}(q)}finally{g=!1}const o=r&&(!n||"verbose"===r&&m);if(o){n?"verbose"===r&&console.log("[π Rebuilding Subscriptions π]: Createdβ¦"):console.log("[π Initial Derive Complete π]: Createdβ¦");const e=f.size;console.log(`[π― ${e} ${Ne("Selector Subscription",e)} π―]`)}return y&&m&&(y.buildProxySubscriptions((e,t)=>{f.add(e.subscribe(t,T,it))},o),d=void 0,y.reset(),a&&(y=void 0)),F&&n&&function(e,t){const n=function(){const e=u.has(ct)?u.size-1:u.size;return S>0&&S<e}(),o=(!S||n)&&(n||null!==ce()||se());n&&ae(),r&&console.log(`[π» Derive Complete π»]: Notifying ${u.size} ${Ne("watcher",u.size)}`);for(const t of u){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 at(O)||(O=t),void(v||(v=!0,le(A)));k(e,t)}(p,t),a&&(m=!1),p}function k(e,t){for(const n of u)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 A(){u.size&&b&&!S&&_();const e=O;v=!1,O=ot,u.size&&at(p)&&at(e)&&k(p,e)}const I=n?Oe(x,"number"==typeof n?n:n.delay,"number"==typeof n?{leading:!1,maxWait:n,trailing:!0}:n):void 0,C=I??(()=>{h||(h=!0,queueMicrotask(x))});function x(){h=!1,u.size?b&&_():D()}function z(e){e||I&&b?queueMicrotask(()=>{u.size||D()}):D()}function E(){x(),w=null}function T(){if(!g&&!b){if(b=!0,!I){if(S){ae();const e=ce(),t=null===e?0:e+1;if(null!==w&&t<=w)return;return w=t,void function(e,t){if(!Y)return;const n=t<0?0:0|t,r=ne.get(e);if(void 0===r){ne.set(e,n);let t=re.get(n);return t||(t=new Set,re.set(n,t)),t.add(e),void(n<ie&&(ie=n))}if(n>r){const t=re.get(r);if(t&&(t.delete(e),0===t.size&&(re.delete(r),r===ie))){ie=1/0;for(const e of re.keys())e<ie&&(ie=e)}ne.set(e,n);let o=re.get(n);o||(o=new Set,re.set(n,o)),o.add(e),n<ie&&(ie=n)}}(E,t)}if(se())return void(v||(v=!0,le(A)))}w=null,C()}}function P(e){u.add(ct);try{return e()}finally{u.delete(ct)}}function M(){return se()&&function(){if(Y)if(Z)null===oe&&de();else{Z=!0;try{de()}catch(e){throw pe(),e}finally{Z=!1,oe=null}}}(),b||!at(p)?u.size>0?_():e(q):p}function D(e=!0){c&&e||(I?.cancel(),j(),u.clear(),S=0,y=void 0,d=void 0,m=!0,h=!1,g=!1,b=!0,p=ot,v=!1,O=ot,w=null)}return{destroy:()=>D(!1),flushUpdates:function(){u.size&&(I?I.flush():b&&_())},getSnapshot:function(){return at(p)?(h&&x(),p):u.size?_():P(_)},getState:M,subscribe:function(...e){if(1===e.length){const t=e[0];return u.add(t),at(p)||M(),()=>{u.delete(t),u.size||z(!1)}}const[t,n,r]=e,o=r?.equalityFn??Object.is,i=r?.isCascadeParticipant??!1,s=function(e){return e(u.size?M():P(M))}(t),c={currentSlice:s,equalityFn:o,isCascadeParticipant:i,listener:n,selector:t};return u.add(c),i&&(S+=1),r?.fireImmediately&&n(s,s),()=>{u.delete(c),i&&(S-=1),u.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 ct(){}function at(e){return e!==ot}var ut=class{constructor(e){this.count=0,this.lastSubscriptionTime=null,this.fetchThrottleMs=null,this.onSubscribe=null,this.onLastUnsubscribe=null,e&&(this.fetchThrottleMs=P.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)}}},lt=Symbol("stores.queryParamConfig");function ft(e){return JSON.stringify(dt(e))}function dt(e){return"object"!=typeof e||null===e?e:Object.keys(e).sort().reduce((t,n)=>{const r=e[n];return t[n]=v(r)?dt(r):r,t},{__proto__:null})}var yt=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});function pt(e,t,n){const r={__proto__:null};let o=null,i=!1;if(e)for(const n in e){if(!S(e,n))continue;const s=ht(r,e[n],n,t);s&&((o??(o=c()))[n]=s,void 0!==s.key&&(i=!0))}return{buildKey:(e=r)=>ft(i?function(e,t){const n={__proto__:null};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}:mt(r),get:()=>mt(r),subscribe:e=>function(e,t,n){if(!e)return a;let r;for(const o in e){const i=e[o]?.tracked;i&&(r??(r=[])).push(i.subscribe(e=>{const r=t[o];G(r,e)||(t[o]=e,n(o,r,e))}))}return r?e=>{for(const t of r)t(e)}:a}(o,r,e)}}function ht(e,t,n,r){return(o=t)&&"object"==typeof o&< in o?bt(e,t.value,n,r,t.key):bt(e,t,n,r);var o}function gt(e,t){const n=[];let r,o;function i(e,t=s){return t(St(e))}const c=e(function(e,t,i){return t?(n.push(n=>e.subscribe(t,n,function(e){return e?{equalityFn:e,isCascadeParticipant:!0}:yt}(i))),t(St(e))):(r??(r=Ge()),o??(o=new WeakMap),He(e,o,r.trackPath))},t),a=r?Ue(c):c;return r&&(r.buildProxySubscriptions((e,t)=>{n.push(n=>e.subscribe(t,n,yt))},!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 bt(e,t,n,r,o){if(function(e){return"function"==typeof e}(t)){const i=gt(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 mt(e){const t={__proto__:null};for(const n in e)S(e,n)&&(t[n]=e[n]);return t}function St(e){return H(e)?e.getSnapshot():e.getState()}var vt={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},wt=Object.freeze({force:!0}),Ot=Object.freeze({once:!0}),qt=new Set,jt=!1;function Ft(e){qt.add(e),jt||(jt=!0,queueMicrotask(()=>{jt=!1,X(_t)}))}function _t(){for(const e of qt)qt.delete(e),e()}function kt(e,t){return n=>{const r={...n},o={__proto__:null};for(const e in r)S(r,e)&&e in vt&&(vt[e]&&(o[e]=r[e]),delete r[e]);return{...t?t(r):Fe(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={__proto__:null};let s=!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}},s=!0):i[e]=c:s=!0}return s?{...n,queryCache:i}:n}function It(){return Object.create(null)}function Ct(e,t,n){return new O(`[createQueryStore: ${e}]: ${t} failed`,n)}function xt(e){return function(...t){return!0===t[1]?e().setState(t[0],!0):e().setState(t[0])}}var zt=Symbol(),Et=Object.freeze({debugMode:!1,enabled:!0,equalityFn:Object.is,fireImmediately:!1}),Tt=Object.freeze({fireImmediately:!1,forceResubscribe:!1});function Pt(e,t,n=Tt){if(t.current.isActive){if(!n?.forceResubscribe)return;t.current.unsubscribe()}t.current.options.debugMode&&console.log("[π‘ useListen π‘] Attaching listener"),t.current.isActive=!0,t.current.resubscribe=(n=Tt)=>Pt(e,t,n);const r=e.subscribe(e=>t.current.selector(e),(e,n)=>t.current.react(e,n,()=>{r(),t.current.isActive=!1}),n.fireImmediately?{...t.current.options,fireImmediately:!0}:t.current.options);t.current.unsubscribe=()=>{t.current.isActive&&(r(),t.current.isActive=!1)}}function Mt(e){return"function"==typeof e?{equalityFn:e}:e??Et}var Dt=Symbol();exports.QueryStatuses=T,exports.StoresError=O,exports.applyStateUpdate=K,exports.configureStores=function(e){var t;o&&function(){if(I)throw new Error("[stores]: configureStores() called after first store creation. Call it earlier before creating any stores.")}(),e.logger&&(t=e.logger,b=t),F??(F=function(e){return e?.queryStoreDefaults?{queryStoreDefaults:e.queryStoreDefaults}:void 0}(e)),_??(_=z(e))},exports.createBaseStore=function(e,t){const n=Le(e,t);return h(n,n.getState,n.getInitialState,Object.is)},exports.createDerivedStore=function(e,t=Object.is){const n=st(e,t);return h(n,n.getSnapshot)},exports.createQueryStore=function(e,t,n){const r=function(e,t,n){x();const r="function"==typeof t?t:It,s="object"==typeof t?t:n,c=function(e){return"string"==typeof e?.storageKey}(s)?s:void 0,a=E??(E=function(){const e={abortInterruptedFetches:!0,cacheTime:P.days(7),debugMode:!1,disableAutoRefetching:!1,keepPreviousData:!1,maxRetries:5,minStaleTime:!1,paramChangeThrottle:!1,retryDelay:M,staleTime:P.minutes(2),suppressStaleTimeWarning:!1},t=function(){if(F)return F}()?.queryStoreDefaults;return t?{...e,...t}:e}()),u=a.minStaleTime,{fetcher:l,onError:f,onFetched:d,setData:y,transform:p,abortInterruptedFetches:h=a.abortInterruptedFetches,cacheTime:g=a.cacheTime,debugMode:m=a.debugMode,disableAutoRefetching:S=a.disableAutoRefetching,disableCache:v=!1,enabled:w=!0,keepPreviousData:j=a.keepPreviousData,maxRetries:_=a.maxRetries,paramChangeThrottle:k=a.paramChangeThrottle,params:A,retryDelay:I=a.retryDelay,staleTime:C=a.staleTime,suppressStaleTimeWarning:z=a.suppressStaleTimeWarning}=e;let D="function"==typeof C?a.staleTime:C;o&&!1!==u&&!S&&!z&&D<u&&console.warn(`[createQueryStore${c?.storageKey?`: ${c.storageKey}`:""}] β Stale times under ${u/1e3} seconds are not recommended. Provided staleTime: ${D/1e3} seconds`);const K=new Error("[createQueryStore: AbortError] Fetch interrupted"),R="function"==typeof g,$=o&&m,L=e.params?Object.keys(e.params):[];let V,H=!1,W=[],U=null,J=null,B=null,Q=null,G=null,X=null,Y=null;const Z={enabled:"function"!=typeof w&&w,error:null,lastFetchedAt:null,queryCache:{},queryKey:"",status:T.Idle},ee=new ut(S);function te(){B&&(Q=null,B.abort(),B=null)}function ne(){G&&(clearTimeout(G),G=null)}function re(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&&Y!==t&&(Y=t,t&&ee.hasSubscribers()?queueMicrotask(()=>a.fetch(void 0,void 0,!0)):(G||h)&&(h&&te(),ne()))}(r.enabled,i)),o});return n?.(),r}return o(e)}function s(e){if(S||D<=0||D===1/0)return;if(!ee.hasSubscribers())return;ne();const n=t();if(!n.enabled)return;const r=V.buildKey(e),o=(v?X===r&&n.lastFetchedAt:n.queryCache[r]?.lastFetchedAt)||null,i=o?D-(Date.now()-o):D;G=setTimeout(()=>{t().enabled&&a.fetch(e,wt,!0)},i)}n.setState=i,ee.init({onSubscribe:(n,r)=>{const o=t();if(o.enabled)if(n){const t=V.get(),n=V.buildKey(t);o.queryKey!==n&&e({queryKey:n}),o.isStale()?a.fetch(t,void 0,!0):s(t)}else S&&!r&&a.fetch(void 0,void 0,!0)},onLastUnsubscribe:e=>{ne(),h&&!e&&te()}});const a={...r(i,t,n),...Z,async fetch(n,r,o=!1){const u=!!r?.skipStoreUpdates,m=t();if(!u){if(!m.enabled&&!r?.force)return null;if(o&&!ee.hasSubscribers())return null}const S=m.error,w=m.queryKey,F=m.status===T.Loading,k=V.complete(n),A=V.buildKey(k);if(F&&Q?.promise&&Q.key===A)return $&&console.log("[π Using Active Fetch π] for params:",JSON.stringify(k)),Q.promise;const C=r?.staleTime??D,x="boolean"==typeof r?.updateQueryKey?r.updateQueryKey:!!o&&j,z=(o||w===A||x)&&!u,E=null!==Q;if(h&&z&&te(),!r?.force){const t=m.lastFetchedAt,n=m.queryCache[A],r=n?.lastFetchedAt,o=n?.errorInfo,i=o&&o.retryCount>=_,c=(v?X===A&&t:r)||null;if(c&&!(Date.now()-c>=C)&&(!o||i||u))return z&&!G&&0!==D&&D!==1/0&&s(k),x&&e(e=>e.queryKey!==A?{queryKey:A}:e),$&&console.log("[πΎ Returning Cached Data πΎ] for params:",JSON.stringify(k)),n?.data??null}const P=z?{key:A}:null,M=r?.cacheTime??(R?g(k):g);async function N(){const m=c?.storageKey||A;try{$&&(!o&&n&&L.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(k).filter(e=>!(e in n)).map(e=>[e,k[e]])))}`):console.log("[π Fetching π] for params:",JSON.stringify(k)));const t=await(h&&z?async function(e){const t=new AbortController;B=t;try{return await new Promise((n,r)=>{t.signal.addEventListener("abort",()=>r(K),Ot),Promise.resolve(l(e,t)).then(n,r)})}finally{B===t&&(B=null)}}(k):l(k,null)),c=Date.now();let f;$&&console.log("[β
Fetch Successful β
] for params:",JSON.stringify(k));try{f=function(e,t,n){return n?n(e,t):e}(t,k,p)}catch(e){throw Ct(m,"transform",e)}if(u)return $&&console.log("[π₯· Successful Parallel Fetch π₯·] for params:",JSON.stringify(k)),"withCache"===r.skipStoreUpdates&&e(e=>{if(!y)return v?e:{queryCache:{...e.queryCache,[A]:{cacheTime:M,data:f,errorInfo:null,lastFetchedAt:c}}};let t=e;const n=t.queryCache[A];try{y({data:f,params:k,queryKey:A,set:e=>{t="function"==typeof e?{...t,...e(t)}:{...t,...e}}})}catch(e){throw Ct(m,"setData",e)}return!v&&Object.is(n,t.queryCache[A])&&(t={...t,queryCache:{...t.queryCache,[A]:{cacheTime:M,data:null,errorInfo:null,lastFetchedAt:c}}}),t}),f;if((y?i:e)(e=>{let t={...e,error:null,lastFetchedAt:c,queryKey:x?A:e.queryKey,status:T.Success};if(y||v){if(y){$&&console.log("[πΎ Setting Data πΎ] for params:",JSON.stringify(k));const e=t.queryCache[A];try{y({data:f,params:k,queryKey:A,set:e=>{t="function"==typeof e?{...t,...e(t)}:{...t,...e}}})}catch(e){throw Ct(m,"setData",e)}!v&&Object.is(e,t.queryCache[A])&&(t.queryCache={...t.queryCache,[A]:{cacheTime:M,data:null,errorInfo:null,lastFetchedAt:c}})}}else $&&console.log("[πΎ Setting Cache πΎ] for params:",JSON.stringify(k),"| Has previous data?:",!!t.queryCache[A]?.data),t.queryCache={...t.queryCache,[A]:{cacheTime:M,data:f,errorInfo:null,lastFetchedAt:c}};return v||g===1/0?t:At(j,A,t)}),z&&(X=A,s(k)),d)try{d({data:f,fetch:a.fetch,params:k,set:i})}catch(e){b.error(Ct(m,"onFetched callback",e))}return f??null}catch(n){if(n===K)return $&&console.log("[β Fetch Aborted β] for params:",JSON.stringify(k)),null;const i=!o&&!0===r?.throwOnError,s=q(n);if(s instanceof O&&b.error(s),!z){if(i)throw s;return null}const c=v?void 0:t().queryCache[A],u=c?.errorInfo?.retryCount??0,l=u+1;try{f?.(s,u)}catch(e){b.error(Ct(m,"onError callback",e))}if(u<_){if(t().enabled&&ee.hasSubscribers()){const e="function"==typeof I?I(l,s):I;e!==1/0&&(ne(),G=setTimeout(()=>{t().enabled&&a.fetch(k,wt,!0)},e))}e(e=>({error:s,queryCache:{...e.queryCache,[A]:{cacheTime:c?.cacheTime??M,data:c?.data??null,lastFetchedAt:c?.lastFetchedAt??null,errorInfo:{error:s,lastFailedAt:Date.now(),retryCount:l}}},queryKey:x?A:e.queryKey,status:T.Error}))}else e(e=>({error:s,queryCache:{...e.queryCache,[A]:{cacheTime:c?.cacheTime??M,data:c?.data??null,lastFetchedAt:c?.lastFetchedAt??null,errorInfo:{error:s,lastFailedAt:Date.now(),retryCount:_}}},queryKey:x?A:e.queryKey,status:T.Error}));if(i)throw s;return null}finally{Q===P&&(Q=null)}}return P&&(ne(),x&&!E&&null===m.lastFetchedAt&&w!==A?e({error:null,queryKey:A,status:T.Loading}):!S&&F||e({error:null,status:T.Loading}),Q=P),P?(P.promise=N(),P.promise):N()},getCacheEntry(e){if(v)return null;const n=t(),r=e?"string"==typeof e?e:V.buildKey(V.complete(e)):n.queryKey;return n.queryCache[r]??null},getData(e){if(v)return null;const n=t().getCacheEntry(e);return n&&null!==n.data?j?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===T.Idle;case"isLoading":return r===T.Loading;case"isError":case"isInitialLoad":case"isSuccess":case void 0:{const t=n.queryKey,o=n.queryCache[t],i=v?r===T.Error:"number"==typeof o?.errorInfo?.lastFailedAt;if("isError"===e)return i;const s=null!==((v?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===T.Idle,isLoading:r===T.Loading,isInitialLoad:c,isSuccess:a}}}},isDataExpired(e){const n=t(),r=n.queryCache[n.queryKey],o=n.queryKey,i=n.lastFetchedAt,s=(v?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=(v?X===r&&n.lastFetchedAt:n.queryCache[r]?.lastFetchedAt)||null;if(!o)return!0;const i=e??D;return Date.now()-o>=i},reset(t=!1){for(const e of W)e();W=[],V=pt(void 0,oe,L),U=null,J=null,te(),ne(),Q=null,X=null,t&&e(Z)}},u=n.subscribe;return n.subscribe=(...e)=>{const t=H?void 0:ee.subscribe(),n=1===e.length?u(e[0]):u(e[0],e[1],e[2]);return e=>{t?.(e),n()}},a}const oe=c?.storageKey?Le(re,(ie=c,void 0===(se={partialize:kt(j,c.partialize)})?Object.assign({__proto__:null},ie):Object.assign({__proto__:null},ie,se))):s&&!("storageKey"in s)?Le(re,s):Le(re);var ie,se;const ce=oe.getState(),ae=ce.error,ue=ce.enabled,le=ce.queryKey,fe=ce.fetch;le&&!ae&&(X=le),H=!0,V=pt(A,oe,L),"function"==typeof w&&(U=gt(w,oe)),"function"==typeof e.staleTime&&(J=gt(e.staleTime,oe),D=J.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)},Ft);function ye(){if(j)de(void 0);else{const e=V.get();oe.setState({queryKey:V.buildKey(e)}),de(e)}}const pe=i||!k?void 0:Oe(ye,"number"==typeof k?k:k.delay,"number"==typeof k?{leading:!1,maxWait:k,trailing:!0}:k);if(W.push(V.subscribe((e,t,n)=>{$&&console.log("[π Param Change π] -",e,"- [Old]:",`${t?.toString()},`,"[New]:",n?.toString()),function(){if(ne(),pe){const e=oe.getState();return void(j&&Q?.key===e.queryKey&&null===e.lastFetchedAt?ye():pe())}ye()}()})),J){let e=J.initialValue;$&&console.log("[π StaleTime Subscription π] Initial value:",e),W.push(J.subscribe(t=>{t!==e&&($&&console.log("[π StaleTime Change π] - [Old]:",`${e},`,"[New]:",t),e=t,D=t,ne(),fe(void 0,void 0,!0))}))}let he;if(U){let e=U.initialValue;ue!==e&&((he??(he={})).enabled=e),$&&console.log("[π Enabled Subscription π] Initial value:",e),W.push(U.subscribe(t=>{t!==e&&($&&console.log("[π Enabled Change π] - [Old]:",`${e},`,"[New]:",t),e=t,oe.setState({enabled:t}))}))}else ue!==Z.enabled&&((he??(he={})).enabled=Z.enabled);const ge=V.buildKey();return ge!==le&&((he??(he={})).queryKey=ge),he&&oe.setState(he),H=!1,be=oe,me=N.QueryStore,Object.assign(be,{[me]:!0});var be,me}(e,t,n);return h(r,r.getState,r.getInitialState,Object.is)},exports.createStoreActions=function(e,t){const n=function(e){const t=e.getState(),n={__proto__:null},r=n;if(o&&("object"!=typeof t||null===t))throw new Error("[createStoreActions]: State is not an object");if(J(e))for(const n in t)Q(t,n)&&(r[n]=B(e,n));else for(const e in t)Q(t,e)&&(r[e]=t[e]);return n}(e);return t?Object.assign(n,t):n},exports.createVirtualStore=function(e,t,n){const r=function(e,t,n){const r="function"==typeof t,o=r?t:void 0,i=r?n:t,s=new Set;let c;function u(e,t,n,r){l(e,t,n,r)&&ae()}function l(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 f(e,t){!function(e,t){const n=e.getState(),r=t.getState();if(c)for(const e of c)u(e,t,n,r);s.size&&ue();for(const e of s)l(e,t,n,r)}(t,e),V(t)}const d=st(e,{debugMode:i?.debugMode??!1,lockDependencies:i?.lockDependencies??!0});let y;function p(){return y??(y=d.subscribe(f)),d.getState()}const h=Object.assign({[N.VirtualStore]:!0,destroy:()=>{y?.(),y=void 0,d.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)??a,onHydrate:e=>g().persist?.onHydrate(e)??a,rehydrate:()=>g().persist?.rehydrate(),setOptions:e=>g().persist?.setOptions(e)}),setState:xt(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?(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?.(p));var g;return h}(e,t,n);return h(r,r.getState,r.getInitialState)},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.destroyStore=V,exports.destroyStores=function(e,t){for(const n of Array.isArray(e)?e:Object.values(e))n&&!t?.skipDestroy?.(n)&&V(n,t)},exports.getQueryKey=ft,exports.getStoreName=function(e){const t="function"==typeof(n=e)?n.name:"";var n;return U(e)?e.persist.getOptions().name??t:t},exports.hasGetSnapshot=H,exports.identity=s,exports.isDerivedStore=function(e){return"flushUpdates"in e},exports.isPersistedStore=U,exports.isQueryStore=W,exports.isVirtualStore=J,exports.nullObject=c,exports.parseQueryKey=function(e){return JSON.parse(e)},exports.queryParam=function(e,t){return{[lt]:!0,key:t.key,value:e}},exports.replacer=$,exports.reviver=L,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=P,exports.useListen=function(t,n,r,o=Et){const i=function(){const t=e.useRef(zt);return t.current===zt&&(t.current=function(e,t,n){return{selector:e,react:t,isActive:!1,options:Mt(n),resubscribe:a,unsubscribe:a}}(n,r,o)),t}(),s=function(e){return"function"==typeof e?Et.enabled:e?.enabled??Et.enabled}(o);return i.current.react=r,i.current.selector=n,function(e,t){"function"==typeof t?e.current.options.equalityFn=t:t&&(e.current.options=t??Et)}(i,o),e.useLayoutEffect(()=>{if(s)return Pt(t,i),()=>function(e){e.current.options.debugMode&&console.log("[ποΈ useListen ποΈ] Detaching listener"),e.current.resubscribe=a,e.current.unsubscribe(),e.current.unsubscribe=a,e.current.isActive=!1}(i)},[s,t]),i},exports.useStableValue=function(t){const n=e.useRef(Dt);return n.current===Dt&&(n.current=t()),n.current};
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("react"),t=require("react-native");const n=t.Platform.OS===`ios`;t.Platform.OS;const r=process.env.NODE_ENV===`development`,i=process.env.NODE_ENV===`test`;Object.freeze(Object.create(null));function a(e){return e}function o(){return{__proto__:null}}function s(e,t){return t===void 0?Object.assign(o(),e):Object.assign(o(),e,t)}function c(){}function l(e,t,n){e(t,n)}const u=Symbol(`empty selection`),d=Object.is;function f(t,n,r,i,a=d){let o=(0,e.useRef)(null),s=t,c=n,l=r;if(i){let e=o.current;e===null&&(e=p(t,n,r,i,a),o.current=e),m(e,t,n,r,i,a),s=e.selectedSubscribe,c=e.getSelectedSnapshot,l=r===void 0?void 0:e.getSelectedServerSnapshot}let u=(0,e.useSyncExternalStore)(s,c,l);return(0,e.useDebugValue)(u),u}function p(e,t,n,r,i){let a={committedEqualityFn:i,committedSelector:r,committedSource:e,committedValue:u,equalityFn:i,getSelectedServerSnapshot:()=>_(a),getSelectedSnapshot:()=>g(a),getServerStoreSnapshot:n,getStoreSnapshot:t,selector:r,selectedSource:e,selectedSubscribe:()=>c,source:e,value:u,valueEqualityFn:i,valueSelector:r,valueSnapshot:u};return a.selectedSubscribe=h(a,e),a}function m(e,t,n,r,i,a){e.source=t,e.getStoreSnapshot=n,e.getServerStoreSnapshot=r,e.selector=i,e.equalityFn=a,e.selectedSource!==t&&(e.selectedSource=t,e.selectedSubscribe=h(e,t))}function h(e,t){return n=>(b(e),t(r=>{let i=e.committedValue;if(i===u||e.committedSource!==t){n();return}let a=e.committedSelector,o=e.committedEqualityFn;if(e.selector===a&&e.equalityFn===o){let t=a(r);if(o===d?d(i,t):o(i,t))return;e.committedValue=t,e.value=t,e.valueEqualityFn=o,e.valueSelector=a,e.valueSnapshot=r,n();return}if(e.source!==t){n();return}let s=e.value;if(s===u)return;let c=e.selector(r),l=e.equalityFn(s,c);e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedValue=y(e,r,l?s:c),l||n()}))}function g(e){return v(e,e.getStoreSnapshot())}function _(e){return v(e,(e.getServerStoreSnapshot??e.getStoreSnapshot)())}function v(e,t){let n=e.value;if(n!==u&&d(e.valueSnapshot,t)&&e.valueSelector===e.selector&&e.valueEqualityFn===e.equalityFn)return n;let r=e.selector(t);if(n!==u&&(e.equalityFn===d?d(n,r):e.equalityFn(n,r)))return y(e,t,n);let i=e.committedValue;return i!==u&&i!==n&&e.committedSource===e.source&&(e.equalityFn===d?d(i,r):e.equalityFn(i,r))?y(e,t,i):y(e,t,r)}function y(e,t,n){return e.value=n,e.valueEqualityFn=e.equalityFn,e.valueSelector=e.selector,e.valueSnapshot=t,n}function b(e){e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedSource=e.source,e.committedValue=e.value===u?g(e):e.value}function x(e,t,n,r){let i=e.subscribe;function a(e,a){return f(i,t,n,e,a??r)}return Object.assign(a,e)}function S(e){let t;function n(){if(t)return t;try{let n=C(e),r;if(typeof n.delete==`function`?r=n.delete.bind(n):typeof n.remove==`function`&&(r=n.remove.bind(n)),typeof r!=`function`)throw Error(`[stores]: Storage instance does not conform to expected interface`);t={clearAll:n.clearAll.bind(n),contains:n.contains.bind(n),delete:r,get:n.getString.bind(n),getAllKeys:n.getAllKeys.bind(n),set:n.set.bind(n)}}catch(e){throw Error(`[stores] react-native-mmkv could not be loaded.
|
|
2
|
+
|
|
3
|
+
Persisted stores require a storage backend. Either:
|
|
4
|
+
- Install MMKV (the default): yarn add react-native-mmkv
|
|
5
|
+
- Or provide a custom adapter via configureStores()
|
|
6
|
+
`+(e instanceof Error?`\n${e.message}`:``))}return w(t),t}return{clearAll:()=>n().clearAll(),contains:e=>n().contains(e),delete:e=>n().delete(e),get:e=>n().get(e),getAllKeys:()=>n().getAllKeys(),set:(e,t)=>n().set(e,t)}}function C(e){let{createMMKV:t,MMKV:n}=require("react-native-mmkv");if(typeof t==`function`)return t({id:e});if(typeof n==`function`)return new n({id:e});throw Error(`[stores]: react-native-mmkv module does not export MMKV/createMMKV.`)}function w(e){if(!e||typeof e.get!=`function`||typeof e.set!=`function`||typeof e.delete!=`function`||typeof e.clearAll!=`function`)throw Error(`[stores]: Storage instance does not conform to expected interface`)}let T={debug:(e,t)=>{r&&console.debug(e,t)},error:(e,t)=>{r&&!i&&console.error(e,t)},info:(e,t)=>{r&&console.info(e,t)},warn:(e,t)=>{r&&console.warn(e,t)}};function E(e){T=e}const D=Object.prototype.hasOwnProperty;function O(e,t){return D.call(e,t)}function ee(e){let t=e.charCodeAt(0);if(t<48||t>57)return!1;let n=Number(e);return Number.isInteger(n)&&n<4294967295&&String(n)===e}function k(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function A(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var j=class extends Error{constructor(e,t){super(e),this.name=`StoresError`,t!==void 0&&Object.defineProperty(this,"cause",{configurable:!0,value:t,writable:!0})}};function M(e){return e instanceof Error?e:Error(String(e))}var te=class{destroy(){}publish(){}},N=class{constructor(){this.sessionId=`noop`}register(e){return new te}};let ne;function P(){return ne||(ne=new N),ne}let F,I,L=!1;function R(e){r&&ie(),e.logger&&E(e.logger),F??(F=V(e)),I??(I=H(e))}function z(){if(F)return F}function B(){return I??(I=H(void 0))}function re(){L=!0}function V(e){if(e?.queryStoreDefaults)return{queryStoreDefaults:e.queryStoreDefaults}}function H(e){return{storage:e?.storage??S(e?.storageKeyPrefix??`stores:`),syncEngine:e?.syncEngine??P()}}function ie(){if(L)throw Error(`[stores]: configureStores() called after first store creation. Call it earlier before creating any stores.`)}const U={Error:`error`,Idle:`idle`,Loading:`loading`,Success:`success`},W={ms:e=>{"worklet";return e},seconds:e=>{"worklet";return e*1e3},minutes:e=>{"worklet";return e*6e4},hours:e=>{"worklet";return e*36e5},days:e=>{"worklet";return e*864e5},weeks:e=>{"worklet";return e*6048e5},infinity:1/0,zero:0};let G;function ae(){return G??(G=oe())}function oe(){let e=z()?.queryStoreDefaults;return{abortInterruptedFetches:e?.abortInterruptedFetches??!0,cacheTime:e?.cacheTime??W.days(7),debugMode:e?.debugMode??!1,disableAutoRefetching:e?.disableAutoRefetching??!1,keepPreviousData:e?.keepPreviousData??!1,minStaleTime:e?.minStaleTime??!1,onError:e?.onError,paramChangeThrottle:e?.paramChangeThrottle??!1,retry:e?.retry??5,retryDelay:e?.retryDelay,staleTime:e?.staleTime??W.minutes(2),suppressStaleTimeWarning:e?.suppressStaleTimeWarning??!1}}function se(e,t){let n=t?.baseDelay??W.seconds(5),r=t?.maxDelay??W.minutes(5);return Math.min(n*2**e,r)}function K(e,t){return t[1]===!0?e(t[0],!0):e(t[0])}function ce(e,t,n){if(n===!0)return le(t)?t(e):t;let r=le(t)?t(e):t;return Object.is(r,e)?e:!A(e)||!A(r)?r:{...e,...r}}function le(e){return typeof e==`function`}function q(e){return typeof e==`object`&&!!e&&`__type`in e&&e.__type===`Map`}function ue(e){return typeof e==`object`&&!!e&&`__type`in e&&e.__type===`Set`}function de(e,t){return t instanceof Map?{__type:`Map`,entries:Array.from(t.entries())}:t instanceof Set?{__type:`Set`,values:Array.from(t)}:t}function fe(e,t){return q(t)?new Map(t.entries):ue(t)?new Set(t.values):t}const pe=Object.freeze({QueryStore:Symbol(`queryStore`),VirtualStore:Symbol(`virtualStore`)});function me(e,t){return Object.assign(e,{[t]:!0})}function he(e,t){J(e)?e.getState().reset(t?.clearQueryCache):ye(e)&&e.destroy()}function ge(e,t){for(let n of Array.isArray(e)?e:Object.values(e))!n||t?.skipDestroy?.(n)||he(n,t)}function _e(e){let t=ve(e);return Se(e)?e.persist.getOptions().name??t:t}function ve(e){return typeof e==`function`?e.name:``}function ye(e){return`destroy`in e}function be(e){return`getSnapshot`in e}function J(e){return pe.QueryStore in e}function xe(e){return`flushUpdates`in e}function Se(e){return!(`persist`in e)||!e.persist?!1:typeof e.persist.getOptions().name==`string`}function Ce(e){return pe.VirtualStore in e}function we(e,t){let n=Te(e);return t?Object.assign(n,t):n}function Te(e){let t=e.getState(),n=o(),i=n;if(r&&!(typeof t==`object`&&t))throw Error(`[createStoreActions]: State is not an object`);if(Ce(e))for(let n in t)De(t,n)&&(i[n]=Ee(e,n));else for(let e in t)De(t,e)&&(i[e]=t[e]);return n}function Ee(e,t){return function(...n){let r=e.getState()[t];if(typeof r==`function`)return r(...n);throw Error(`[createVirtualStoreAction]: Method ${String(t)} is not a function`)}}function De(e,t){return typeof e[t]==`function`}function Oe(e,t){"worklet";if(typeof e!=`object`||!e||e===void 0||typeof t!=`object`||!t||t===void 0)return e===t;if(Object.is(e,t))return!0;let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let r of n)if(!(r in t)||!Oe(e[r],t[r]))return!1;return!0}function ke(e,t){"worklet";if(typeof e!=`object`||!e||e===void 0||typeof t!=`object`||!t||t===void 0)return e===t;if(Object.is(e,t))return!0;let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let r of n)if(!Object.is(e[r],t[r]))return!1;return!0}function Ae(e,t){let n=Object.prototype.hasOwnProperty;function r(e,t){for(let n of e.keys())if(Ae(n,t))return n}let i,a,o;if(e===t)return!0;if(e&&t&&(i=e.constructor)===t.constructor){if(i===Date)return e.getTime()===t.getTime();if(i===RegExp)return e.toString()===t.toString();if(i===Array){if((a=e.length)===t.length)for(;a--&&Ae(e[a],t[a]););return a===-1}if(i===Set){if(e.size!==t.size)return!1;for(let n of e)if(o=n,o&&typeof o==`object`&&(o=r(t,o),!o)||!t.has(o))return!1;return!0}if(i===Map){if(e.size!==t.size)return!1;for(let n of e)if(o=n[0],o&&typeof o==`object`&&(o=r(t,o),!o)||!Ae(n[1],t.get(o)))return!1;return!0}if(i===ArrayBuffer)e=new Uint8Array(e),t=new Uint8Array(t);else if(i===DataView){if((a=e.byteLength)===t.byteLength)for(;a--&&e.getInt8(a)===t.getInt8(a););return a===-1}if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(t)){let n=e,r=t;if((a=n.byteLength)===r.byteLength)for(;a--&&n[a]===r[a];);return a===-1}if(!i||typeof e==`object`){a=0;for(let r in e)if(n.call(e,r)&&++a&&!n.call(t,r)||!(r in t)||!Ae(e[r],t[r]))return!1;return Object.keys(t).length===a}}return e!==e&&t!==t}function je(e,t,n){if(t===0)return n;if(t===1){if(e===n)return null;let t=new Set;return t.add(e),t.add(n),t}return e.add(n),e.size===t?null:e}function Me(e,t,n){if(t===0)return null;if(t===1)return e===n?void 0:null;if(!e.delete(n))return null;if(t!==2)return e;for(let t of e)return t}function Ne(e,t,n,r,i){if(t!==0){if(t===1){n(e,r,i);return}for(let t of e)n(t,r,i)}}function Pe(e,t){t>1&&e.clear()}const Fe=t.unstable_batchedUpdates;let Y=!1,Ie=!1,Le=!1,X,Re,ze=0;const Be=new Map;let Ve=0,He=null,Z=1/0;function Ue(){return Y}function We(){return He}function Ge(){Y||(Y=!0,!Le&&(Le=!0,queueMicrotask(()=>{Le=!1,Ke()})))}function Ke(){if(Y){if(Ie){Xe();return}Ie=!0;try{Fe(Xe)}finally{et()}}}function qe(){if(Y){if(Ie){He===null&&Ze();return}Ie=!0;try{Ze()}catch(e){throw et(),e}finally{Ie=!1,He=null}}}function Je(e){if(Y){if(Re){Re.push(e);return}if(!X){X=e;return}Re=[X,e],X=void 0}}function Ye(e,t){if(!Y)return;let n=t<0?0:t|0,r=Be.get(n);r||(r=[],Be.set(n,r)),r.push(e),Ve+=1,n<Z&&(Z=n)}function Xe(){for(;Ve>0||tt();)Ze(),$e()}function Ze(){for(;Ve>0;){let e=Z,t=Be.get(e);if(!t){Z=1/0;for(let e of Be.keys())e<Z&&(Z=e);continue}Be.delete(e),Ve-=t.length,Qe(),He=e;for(let e=0;e<t.length;e++)t[e]();He=null}}function Qe(){Z=1/0;for(let e of Be.keys())e<Z&&(Z=e)}function $e(){for(;;){let e=X;if(e){X=void 0,e();continue}let t=Re;if(!t)return;for(;ze<t.length;)t[ze++]();Re=void 0,ze=0;return}}function et(){Y=!1,Ie=!1,He=null,X=void 0,Re=void 0,ze=0,Be.clear(),Ve=0,Z=1/0}function tt(){return!!X||!!Re}const Q=Symbol(`stores.subscribeCascadeState`);function nt(e){return Q in e}function rt(e,t){nt(e)&&(e[Q]=t(e[Q]))}const it=Symbol(),at=Symbol();function ot(e){let t,n,r,i=0;function a(e,a,o){let s=ce(t,e,a);if(Object.is(s,t))return o===it?at:void 0;let c=t;if(t=s,Ne(r,i,l,t,c),n){Ke();for(let e of n)e(t,c)}}function o(){return t}function s(){return d}function c(e,t,n){return t?g(e,t,n):f(e)}let u={[Q]:m,getInitialState:s,getState:o,setState:a,subscribe:c},d=t=st(e)?e(a,o,u):e;return u;function f(e){return(n??(n=new Set)).add(e),()=>{n?.delete(e),n?.size===0&&(n=void 0)}}function p(e){let t=je(r,i,e);return t!==null&&(r=t,i+=1),()=>h(e)}function m(e){function t(t,n){Ge(),e(t,n)}return p(t)}function h(e){let t=Me(r,i,e);t!==null&&(r=t,--i)}function g(e,n,r){let i=r?.equalityFn??Object.is,a=r?.isCascadeParticipant??!1,o=e(t);function s(t){let r=e(t);if(i(o,r))return;let s=o;o=r,a&&Ge(),n(r,s)}return r?.fireImmediately&&n(o,o),a?p(s):f(s)}}function st(e){return typeof e==`function`}function ct(e){return!!e&&typeof e==`object`&&`then`in e&&typeof e.then==`function`}const lt=Object.freeze({migrated:!1,state:void 0});function ut(e,t,n){return(r,i,a)=>{let o=ft(t),s,c=!1,l=0,u,d,f;function p(e){return o.storage.setItem(o.name,e,o.version)}function m(e,t){return(t===!0?r(e,t,it):r(e,!1,it))===at?n?s??(s=Promise.resolve()):void 0:p(i())}a.setState=m;let h=e(m,i,a);a.getInitialState=()=>h;function g(){let e=x(),t=o.onRehydrateStorage?.(i()??h);try{let n=o.storage.getItem(o.name);return ct(n)?n.then(n=>_(e,n,t)).catch(n=>C(e,t,n)):_(e,n,t)}catch(n){C(e,t,n)}}return Object.assign(a,{persist:b()}),o.skipHydration||g(),u??h;function _(e,t,n){let r=dt(o,t);return ct(r)?r.then(t=>v(e,t,n)).catch(t=>C(e,n,t)):v(e,r,n)}function v(e,t,n){let r=y(e,t);if(ct(r))return r.then(()=>S(e,n));S(e,n)}function y(e,t){if(e!==l)return;let n=o.merge(t.state,i()??h);if(u=n,r(n,!0),t.migrated)return p(i())}function b(){return{clearStorage:()=>{o.storage.removeItem(o.name)},getOptions:()=>o,hasHydrated:()=>c,onFinishHydration:e=>(f??(f=new Set),f.add(e),()=>{f?.delete(e),f?.size===0&&(f=void 0)}),onHydrate:e=>(d??(d=new Set),d.add(e),()=>{d?.delete(e),d?.size===0&&(d=void 0)}),rehydrate:g,setOptions:e=>{o=ft({...o,...e,storage:e.storage??o.storage})}}}function x(){let e=++l;return c=!1,d?.forEach(e=>e(i()??h)),e}function S(e,t){if(e!==l)return;t?.(u,void 0);let n=i();u=n,c=!0,f?.forEach(e=>e(n))}function C(e,t,n){e===l&&t?.(void 0,n)}}}function dt(e,t){if(!t)return lt;if(typeof t.version!=`number`||t.version===e.version)return{migrated:!1,state:t.state};if(!e.migrate)return console.error(`State loaded from storage couldn't be migrated since no migrate function was provided`),lt;let n=e.migrate(t.state,t.version);return ct(n)?n.then(e=>({migrated:!0,state:e})):{migrated:!0,state:n}}function ft(e){return{...e,merge:e.merge??pt,skipHydration:e.skipHydration??!1}}function pt(e,t){return e===void 0?t:{...t,...e}}function mt(){let e=!1,t,n,r=new Promise((e,r)=>{t=e,n=r});function i(){e||!t||(e=!0,t(),t=void 0,n=void 0)}function a(r){e||!n||(e=!0,n(r),n=void 0,t=void 0)}function o(){return e}return{complete:i,isHydrated:o,fail:a,promise:r}}function ht(e){let t,n=!1,r,i;return{hydrationPromise:()=>n?t?.promise??r??(r=Promise.resolve()):(t||(t=mt()),t.promise),stateCreator:(r,a,o)=>{let s;function c(...e){return n?K(r,e):(t||(t=mt()),s||(s=[]),s.push(e),t.promise)}return i=()=>{if(s?.length){for(let e of s)K(o.setState,e);s=void 0}},e(c,a,o)},wrapOnRehydrateStorage:(e,r)=>a=>{let o=e?.(a);return(e,a)=>{n=!0,r?.onHydrationComplete?.(),i&&i(),r?.onHydrationFlushEnd?.(),a?t?.fail(M(a)):t?.complete(),o?.(e,a)}}}}function gt(e){let t,n=null;function r(...r){return t=r,n||(n=new Promise(r=>{queueMicrotask(async()=>{try{await e(...t)}finally{n=null,r()}})})),n}return r}const _t=Math.max,vt=Math.min;function yt(e,t=0,n={}){let r,i,a,o,s,c,l=0,u=!1,d=!1,f=!0;if(typeof e!=`function`)throw TypeError(`Expected a function`);t=xt(t)||0,St(n)&&(u=!!n.leading,d=`maxWait`in n,a=d?_t(xt(n.maxWait)||0,t):void 0,f=`trailing`in n?!!n.trailing:f);function p(t){let n=r,a=i;return r=i=void 0,l=t,o=n?e.apply(a,n):e.apply(a),o}function m(e){return l=e,s=setTimeout(_,t),u?p(e):o}function h(e){let n=e-(c??0),r=e-l,i=t-n;return d&&a!==void 0?vt(i,a-r):i}function g(e){let n=e-(c??0),r=e-l;return c===void 0||n>=t||n<0||d&&a!==void 0&&r>=a}function _(){let e=bt();if(g(e))return v(e);s=setTimeout(_,h(e))}function v(e){return s=void 0,f&&r?p(e):(r=i=void 0,o)}function y(){s!==void 0&&clearTimeout(s),l=0,r=c=i=s=void 0}function b(){return s===void 0?o:v(bt())}function x(...e){let n=bt(),a=g(n);if(r=e,i=this,c=n,a){if(s===void 0)return m(c);if(d)return clearTimeout(s),s=setTimeout(_,t),p(c)}return s===void 0&&(s=setTimeout(_,t)),o}return x.cancel=y,x.flush=b,x}function bt(){return typeof performance<`u`&&typeof performance.now==`function`?performance.now():Date.now()}function xt(e){if(typeof e==`number`)return e;if(typeof e==`symbol`||e===void 0)return NaN;if(typeof e==`object`&&e){let t=typeof e.valueOf==`function`?e.valueOf():e;e=typeof t==`object`?t+``:t}return typeof e==`string`?(e=e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,``),/^0b[01]+$/i.test(e)?parseInt(e.slice(2),2):/^0o[0-7]+$/i.test(e)?parseInt(e.slice(2),8):/^[-+]0x[0-9a-f]+$/i.test(e)?NaN:+e):e===0?e:+e}function St(e){let t=typeof e;return e!==null&&(t===`object`||t===`function`)}function Ct(e){if(!k(e))return e;let t=o(),n=Object.keys(e);for(let r=0;r<n.length;r++){let i=n[r],a=e[i];typeof a!=`function`&&(t[i]=a)}return t}function wt(e,t){try{return JSON.stringify(e,t?de:void 0)}catch(e){throw T.error(new j(`[createBaseStore]: Failed to serialize store data`,e)),e}}function Tt(e,t){try{return JSON.parse(e,t?fe:void 0)}catch(e){throw T.error(new j(`[createBaseStore]: Failed to deserialize persisted store data`,e)),e}}const Et=i?0:n?W.seconds(3):W.seconds(5);function Dt(e,t,n){let r=t??e.storage??B().storage,i=(e.sync?void 0:e.persistThrottleMs??Et)||void 0,a=e.version??0;return r.async?{async:!0,persistStorage:kt(r,e,i,n),version:a}:{async:!1,persistStorage:Ot(r,e,i,n),version:a}}function Ot(e,t,n,r){let i=!t.deserializer&&!t.serializer&&!e.deserializer&&!e.serializer,a=typeof t.sync==`object`&&(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata)===!0,o=t.partialize??Ct,s=t.deserializer??e.deserializer??At(i),c=t.serializer??e.serializer??jt(i);function l(t,n,i){try{if(It(r))return;let s={state:o(n),version:i},l=Nt(r,a,s),u=c(s);try{e.set(t,u),Pt(r,l)}catch(e){T.error(new j(`[createBaseStore]: Failed to persist store data`,e))}}catch(e){T.error(new j(`[createBaseStore]: Failed to persist store data`,e))}}let u=n===void 0?l:yt(l,n,{leading:!1,maxWait:n,trailing:!0});return{getItem:t=>{let n=e.get(t);return n===void 0?null:s(n)},setItem:(e,t,n)=>{r?.getIsApplyingRemote()||u(e,t,n)},removeItem:t=>{try{e.delete(t)}catch(e){T.error(new j(`[createBaseStore]: Failed to delete persisted store data`,e))}}}}function kt(e,t,n,r){let i=!t.deserializer&&!t.serializer&&!e.deserializer&&!e.serializer,a=typeof t.sync==`object`&&(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata)===!0,o=t.partialize??Ct,s=t.deserializer??e.deserializer??At(i),c=t.serializer??e.serializer??jt(i);async function l(t,n,i){try{if(It(r))return;let s={state:o(n),version:i},l=Nt(r,a,s),u=c(s);try{await e.set(t,u),Pt(r,l)}catch(e){T.error(new j(`[createBaseStore]: Failed to persist store data`,e))}}catch(e){T.error(new j(`[createBaseStore]: Failed to serialize persisted store data`,e))}}let u=n===void 0?gt(l):yt(l,n,{leading:!1,maxWait:n,trailing:!0});return{getItem:async t=>{let n=await e.get(t);return n===void 0?null:s(n)},setItem:async(e,t,n)=>{if(!r?.getIsApplyingRemote())return await u(e,t,n)},removeItem:async t=>{try{await e.delete(t)}catch(e){T.error(new j(`[createBaseStore]: Failed to delete persisted store data`,e))}}}}function At(e){return t=>{if(typeof t!=`string`)throw new j(`[createBaseStore]: Received non-string serialized state without a custom deserializer. Provide a deserializer on the store or storage adapter.`);return Tt(t,e)}}function jt(e){return t=>wt(t,e)}const Mt=Object.freeze({shouldClear:!1});function Nt(e,t,n){if(!t||!e)return Mt;let r=e.getFieldTimestampSnapshot();return Ft(e,n),n.syncMetadata?r&&Object.keys(r).length>0?(n.syncMetadata.fields=r,{fieldSnapshot:r,shouldClear:!0}):(delete n.syncMetadata.fields,{fieldSnapshot:r,shouldClear:!1}):{fieldSnapshot:r,shouldClear:!1}}function Pt(e,t){!e||!t.shouldClear||!t.fieldSnapshot||!Object.keys(t.fieldSnapshot).length||e.clearFieldTimestamps(t.fieldSnapshot)}function Ft(e,t){let n=e.getSessionId(),r=e.getTimestamp();n!==void 0&&r!==void 0&&(t.syncMetadata={origin:n,timestamp:r})}function It(e){return e?!!e.getIsApplyingRemote():!1}function Lt(e,t,n){let r=t.engine??B().syncEngine;return(i,a,s)=>{let c=new Map,l=[],u=[],d=null,f=!1,p=!1,m=0,h=null,g=[],_=Promise.resolve(),v=!n?.isAsync;function y(){let e=Date.now(),t=e>m?e:m+1;return m=t,t}function b(e,t){if(!(!n||!r.sessionId)&&(n.setSessionId(r.sessionId),n.setTimestamp(e),t.length>0)){let r=o();for(let n of t)r[String(n)]=e;n.mergeFieldTimestamps(r)}}function x(e,t,n,i=!1){let a=r.sessionId;for(let t of e)c.set(t,[n,a]);!d||!p?u.push({keys:e,replace:i,timestamp:n,values:t}):d.publish?.({replace:i,sessionId:a,timestamp:n,values:t})}function S(){if(!(!d||!u.length)){for(let e of u){let t=r.sessionId;for(let n of e.keys)c.set(n,[e.timestamp,t]);b(e.timestamp,e.keys),d.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values})}u.length=0}}function C(e,t){if(f||!h)return t?i(e,t):i(e);let n=y(),r,a,s=t?i(c,!0):i(c);if(!r||!a)return s;function c(i){let s=ce(i,e,t);for(let e of g)Object.is(s[e],i[e])||((r??(r=[])).push(e),(a??(a=o()))[e]=s[e]);return r&&b(n,r),s}return ct(s)?s.finally(x.bind(void 0,r,a,n,t)):(x(r,a,n,t),s)}let w=s.setState;s.setState=C;let E=e(C,a,s);if(g=t.fields??Bt(E),!g.length)return E;h=new Set(g);async function D(e){m=Math.max(m,e.timestamp);let r=o(),i=a(),s=e.timestamp,l;if(e.replace)for(let t of g)O(e.values,t)||zt(c.get(t),s,e.sessionId)&&(l??(l=[])).push(t);for(let n of g){if(!Ut(e.values,n)||!h?.has(n)||!zt(c.get(n),s,e.sessionId))continue;let a=t.merge?.[n];if(a){let t=e.values[n],o=i[n];if(t!==void 0){let l=a(t,o,i,e.values),u=o===void 0?t:o;if(!Ht(l,u)){T.error(new j(`[sync] Merge function for field "${String(n)}" returned ${Vt(l)} but expected ${Vt(u)}`));return}r[n]=l,c.set(n,[s,e.sessionId])}}else r[n]=e.values[n],c.set(n,[s,e.sessionId])}if(!(!(Object.keys(r).length>0)&&!l?.length)){f=!0,n?.setIsApplyingRemote(!0);try{if(e.replace){let e={...i},t=!1;if(l?.length){t=!0;for(let t of l)delete e[t],c.delete(t)}for(let n in r){if(!O(r,n))continue;let i=r[n];if(i===void 0)continue;Object.is(e[n],i)||(t=!0);let a=e;a[n]=i}if(!t)return;await(n?.setWithoutPersist??w)(e,!0)}else await(n?.setWithoutPersist??w)(r)}finally{f=!1,n?.setIsApplyingRemote(!1)}}}function ee(e){n?.isAsync?_=_.then(()=>D(e)):D(e)}function k(){if(!l.length)return;let e=l.slice();l.length=0;for(let t of e)ee(t)}if(d=r.register({apply:e=>{if(!v){l.push(e);return}ee(e)},fields:g,getState:a,key:t.key}),d?.onFirstSubscribe||d?.onLastUnsubscribe){let e=d,t=0,n=s.subscribe;function A(n){return t++===0&&e.onFirstSubscribe?.(),r=>{n(r),--t,t||queueMicrotask(()=>{t||e.onLastUnsubscribe?.()})}}s.subscribe=(...e)=>A(e.length===1?n(e[0]):n(e[0],e[1],e[2])),rt(s,e=>t=>A(e(t)))}function M(){p=!0,S()}function te(){v=!0,k()}return n?.isAsync?(n.onHydrationComplete=M,n.onHydrationFlushEnd=te):d.onHydrated?(d.onHydrated(M),te()):(M(),te()),E}}function Rt(e){let t,n,r,i=!1;function a(e){if(!(!e||!r)){for(let t of Object.entries(e)){let e=t[0],n=t[1];r[e]===n&&delete r[e]}Object.keys(r).length||(r=void 0)}}function o(){if(r)return{...r}}function s(e){if(!r){r={...e};return}for(let t of Object.entries(e)){let e=t[0],n=t[1],i=r[e];(i===void 0||n>i)&&(r[e]=n)}}return{isAsync:e,clearFieldTimestamps:a,getFieldTimestampSnapshot:o,getIsApplyingRemote:()=>i,getSessionId:()=>t,getTimestamp:()=>n,mergeFieldTimestamps:s,onHydrationComplete:void 0,onHydrationFlushEnd:void 0,setIsApplyingRemote:e=>i=e,setSessionId:e=>t=e,setTimestamp:e=>n=e,setWithoutPersist:void 0}}function zt(e,t,n){if(!e)return!0;let r=e[0],i=e[1];return t<r?!1:t>r?!0:n>i}function Bt(e){let t=[];for(let n of Object.keys(e))Wt(e,n)&&t.push(n);return t}function Vt(e){if(e===null)return`null`;let t=typeof e;return t===`object`?Object.prototype.toString.call(e):t}function Ht(e,t){if(!r)return!0;if(e===null||t===null)return e===t;let n=typeof e;return n===typeof t?n===`object`?Object.prototype.toString.call(e)===Object.prototype.toString.call(t):!0:!1}function Ut(e,t){return O(e,t)}function Wt(e,t){return typeof e[t]!=`function`}function Gt(e,t){if(re(),!t)return ot(e);let n=t.storageKey,r=typeof n==`string`,i=r?t.storage??B().storage:void 0,a=Kt(t.sync,n),o=!i||!a?void 0:Rt(i.async??!1),s=a?Lt(e,a,o):e;if(!r)return ot(s);let c=Dt(t,i,o),l=c.async?ht(s):void 0,u=l?l.wrapOnRehydrateStorage(t.onRehydrateStorage,o):t.onRehydrateStorage,d=ot(ut(l?(e,t,n)=>(o&&(o.setWithoutPersist=n.setState),l.stateCreator(e,t,n)):s,{merge:t.merge,migrate:t.migrate,name:n,onRehydrateStorage:u,storage:c.persistStorage,version:c.version},c.async));return l?Object.assign(d,{persist:Object.assign(d.persist,{hydrationPromise:l.hydrationPromise})}):d}function Kt(e,t){if(!e)return null;let n=typeof e==`object`,r=n?e.key??t:e===!0?t:e;if(!r)throw new j(`[createBaseStore]: sync requires a key to be specified either directly or via storageKey`);return n?{...e,key:r}:{key:r}}function qt(e,t,n=`s`){return t===1?e:`${e}${n}`}const Jt=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});var Yt=class{constructor(e){this.invalidate=e,this.stateDependencyRevisionStamp=0,this.stateDependencyRevision=0}beginRebuild(e){this.clearSelectors(e),this.stateDependencyRevision+=1}addSelector(e){let t=this.selectorUnsubscribes;if(!t){this.selectorUnsubscribes=e;return}if(typeof t==`function`){this.selectorUnsubscribes=[t,e];return}t.push(e)}retainState(e){let t=this.stateDependencies;if(t){let n=t.get(e);if(n){n.revision=this.stateDependencyRevision;return}t.set(e,this.createStateDependency(e));return}let n=this.stateDependencyStore;if(!n){this.stateDependencyStore=e,this.stateDependencyRevisionStamp=this.stateDependencyRevision,this.stateDependencyUnsubscribe=this.subscribeState(e);return}if(n===e){this.stateDependencyRevisionStamp=this.stateDependencyRevision;return}let r=this.stateDependencyUnsubscribe;this.stateDependencyStore=void 0,this.stateDependencyUnsubscribe=void 0,this.stateDependencies=new Map,r&&this.stateDependencies.set(n,{revision:this.stateDependencyRevisionStamp,unsubscribe:r}),this.stateDependencies.set(e,this.createStateDependency(e))}finishRebuild(e){this.stateDependencyStore&&this.stateDependencyRevisionStamp!==this.stateDependencyRevision&&(this.stateDependencyUnsubscribe?.(e),this.stateDependencyStore=void 0,this.stateDependencyUnsubscribe=void 0);let t=this.stateDependencies;if(t){for(let n of t){let r=n[1];r.revision!==this.stateDependencyRevision&&(r.unsubscribe(e),t.delete(n[0]))}if(!t.size){this.stateDependencies=void 0;return}if(t.size===1){for(let e of t){this.stateDependencyStore=e[0],this.stateDependencyRevisionStamp=e[1].revision,this.stateDependencyUnsubscribe=e[1].unsubscribe;break}this.stateDependencies=void 0}}}clear(e){this.clearSelectors(e),this.stateDependencyUnsubscribe?.(e),this.stateDependencyStore=void 0,this.stateDependencyUnsubscribe=void 0;let t=this.stateDependencies;if(t){for(let n of t)n[1].unsubscribe(e);this.stateDependencies=void 0}}get size(){let e=this.selectorUnsubscribes;return(typeof e==`function`?1:e?.length??0)+ +!!this.stateDependencyStore+(this.stateDependencies?.size??0)}clearSelectors(e){let t=this.selectorUnsubscribes;if(this.selectorUnsubscribes=void 0,t){if(typeof t==`function`){t(e);return}for(let n=0;n<t.length;n++)t[n](e)}}createStateDependency(e){return{revision:this.stateDependencyRevision,unsubscribe:this.subscribeState(e)}}subscribeState(e){return nt(e)?e[Q](this.invalidate):e.subscribe(a,this.invalidate,Jt)}},Xt=class{constructor(){this.watcherCount=0,this.ordinaryWatcherCount=0,this.cascadeParticipantCount=0,this.cascadeStateListenerCount=0}addWatcher(e){let t=je(this.watchers,this.watcherCount,e);return t===null?!1:(this.watchers=t,this.watcherCount+=1,en(e)?this.cascadeParticipantCount+=1:this.ordinaryWatcherCount+=1,!0)}deleteWatcher(e){let t=Me(this.watchers,this.watcherCount,e);return t===null?!1:(this.watchers=t,--this.watcherCount,en(e)?--this.cascadeParticipantCount:--this.ordinaryWatcherCount,!0)}addCascadeStateListener(e){let t=je(this.cascadeStateListeners,this.cascadeStateListenerCount,e);return t===null?!1:(this.cascadeStateListeners=t,this.cascadeParticipantCount+=1,this.cascadeStateListenerCount+=1,!0)}deleteCascadeStateListener(e){let t=Me(this.cascadeStateListeners,this.cascadeStateListenerCount,e);return t===null?!1:(this.cascadeStateListeners=t,--this.cascadeParticipantCount,--this.cascadeStateListenerCount,!0)}notifyCascade(e,t){Ne(this.cascadeStateListeners,this.cascadeStateListenerCount,l,e,t),this.cascadeParticipantCount!==this.cascadeStateListenerCount&&Ne(this.watchers,this.watcherCount,Zt,e,t)}notifyOrdinary(e,t){Ne(this.watchers,this.watcherCount,Qt,e,t)}clear(){this.watchers=Pe(this.watchers,this.watcherCount),this.cascadeStateListeners=Pe(this.cascadeStateListeners,this.cascadeStateListenerCount),this.watcherCount=0,this.ordinaryWatcherCount=0,this.cascadeParticipantCount=0,this.cascadeStateListenerCount=0}};function Zt(e,t,n){typeof e==`function`||!e.isCascadeParticipant||$t(e,t)}function Qt(e,t,n){if(typeof e==`function`){e(t,n);return}e.isCascadeParticipant||$t(e,t)}function $t(e,t){let n=e.selector(t);if(e.equalityFn(e.currentSlice,n))return;let r=e.currentSlice;e.currentSlice=n,e.listener(n,r)}function en(e){return typeof e!=`function`&&e.isCascadeParticipant}const tn=Symbol(`stores.deriveProxy.unwrap`);function nn(e,t,n,r){let i=n.get(e);if(fn(i))return i;let a=rn(t,e,r);return n.set(e,a),a}function rn(e,t,n,r=[]){return!e||typeof e!=`object`?(n(t,r,!0),e):an(e,r,t,n,new WeakSet,new WeakMap)}function an(e,t,n,r,i,a){let o=Array.isArray(e);return new Proxy(e,{get(s,c,l){if(c===tn)return r(n,t,!0),s;if(i.has(s))return Reflect.get(s,c,l);if(c===`__proto__`||typeof c==`symbol`)return c===Symbol.iterator&&(r(n,t,!0),i.add(s)),Reflect.get(s,c,l);if(o&&ee(c))return r(n,t,!0),i.add(s),Reflect.get(s,c,l);let u=Reflect.get(s,c,s),d=String(c),f=t.concat(d);if(typeof u==`function`)return O(s,c)?function(...e){return r(n,f,!0,{args:e.length?e:void 0}),Reflect.apply(u,s,e)}:(r(n,t,!0),u.bind(e));let p=!!u&&typeof u==`object`;return r(n,f,!p),p?(a.has(u)||a.set(u,an(u,f,n,r,i,a)),a.get(u)):u},getOwnPropertyDescriptor(e,a){return r(n,t,!0),i.add(e),Reflect.getOwnPropertyDescriptor(e,a)},has(e,i){return r(n,t,!0),Reflect.has(e,i)},ownKeys(e){return r(n,t,!0),i.add(e),Reflect.ownKeys(e)}})}function on(e,t){return!e||typeof e!=`object`?e:un(e)||(Array.isArray(e)?sn(e,t):k(e)&&cn(e,t),e)}function sn(e,t){let n=dn(e,t);if(n)for(let t=0;t<e.length;t++)ln(e,String(t),n)}function cn(e,t){let n=dn(e,t);if(n)for(let t of Reflect.ownKeys(e))ln(e,t,n)}function ln(e,t,n){let r=Reflect.getOwnPropertyDescriptor(e,t);if(!r||!(`value`in r))return;let i=on(r.value,n);i!==r.value&&(r.value=i,Reflect.defineProperty(e,t,r))}function un(e){let t=Reflect.get(e,tn);return t&&typeof t==`object`?t:void 0}function dn(e,t){let n=t??new WeakSet;return n.has(e)?null:(n.add(e),n)}function fn(e){return e!==void 0}const pn=Object.freeze([]);function mn(){let e,t,n;return{buildProxySubscriptions(r,i,a){let o=[],s=t,c=e;if(s&&c)_n(s,c,[],0,o,a);else if(n)for(let e of n)_n(e[1],e[0],[],0,o,a);xn(o,r,i)},reset(){e=void 0,t=void 0,n=void 0},trackPath(r,i,a,o){let s=t;if(s){let i=e;if(i!==r)if(!i)e=r;else{let a=n??(n=new Map);a.set(i,s),s=hn(),a.set(r,s),e=void 0,t=void 0}}else{let i=n;i?(s=i.get(r),s||(s=hn(),i.set(r,s))):(s=hn(),e=r,t=s)}gn(s,i,a,o)}}}function hn(){return o()}function gn(e,t,n,r){let i=e;for(let e=0;e<t.length;e++){let n=t[e],r=i.children,a;if(r)a=r[n],a||(a=r[n]=hn());else if(a=i.child,!a)a=hn(),i.child=a,i.childKey=n;else if(i.childKey!==n){let e=i.childKey;if(e===void 0)i.childKey=n;else{let t=hn();t[e]=a,a=t[n]=hn(),i.child=void 0,i.childKey=void 0,i.children=t}}i=a}n&&(i.isLeaf=!0),r&&vn(i,r)}function _n(e,t,n,r,i,a=2){let o=e.child;if(o){let s=e.childKey;if(e.isLeaf){if(bn(e,t,n,i),!o.invocation||s===void 0)return}else if(s===void 0){bn(e,t,n,i);return}n.push(s),_n(o,t,n,r+1,i,a),n.pop();return}let s=e.children;if(!s){bn(e,t,n,i);return}if(e.isLeaf||r>=a){bn(e,t,n,i);for(let e in s){let o=s[e];o.invocation&&(n.push(e),_n(o,t,n,r+1,i,a),n.pop())}return}for(let e in s)n.push(e),_n(s[e],t,n,r+1,i,a),n.pop()}function vn(e,t){let n=e.invocation;if(!n){e.invocation=t;return}if(yn(n,t))return;let r=e.extraInvocations;if(!r){e.extraInvocations=[t];return}for(let e=0;e<r.length;e++)if(yn(r[e],t))return;r.push(t)}function yn(e,t){let n=e.args,r=t.args,i=n?.length??0;if(i!==(r?.length??0))return!1;if(!n||!r)return!0;for(let e=0;e<i;e++)if(!Object.is(n[e],r[e]))return!1;return!0}function bn(e,t,n,r){let i=n.slice(),a=e.invocation;if(!a){r.push({store:t,path:i});return}r.push({store:t,path:i,invocation:a});let o=e.extraInvocations;if(o)for(let e=0;e<o.length;e++)r.push({store:t,path:i,invocation:o[e]})}function xn(e,t,n){for(let n of e){let e=n.invocation?Cn(n.path,n.invocation):Sn(n.path);t(n.store,e,n.path)}n&&Tn(e)}function Sn(e){return e.length?t=>wn(t,e):a}function Cn(e,t){let n=e.slice(0,-1),r=e[e.length-1];return e=>{let i=wn(e,n),a=i&&typeof i==`object`?Reflect.get(i,r):void 0;return typeof a==`function`?Reflect.apply(a,i,t.args??pn):void 0}}function wn(e,t){let n=e;for(let e=0;e<t.length;e++){if(!n||typeof n!=`object`)return n;n=Reflect.get(n,t[e])}return n}function Tn(e){let t=e.length;console.log(`[π‘ ${t} ${qt(`Proxy Subscription`,t)} π‘]:`,JSON.stringify(e.map(e=>{let t=En(e.store),n=e.path.join(`.`);if(!e.invocation)return n?`$(${t}).${n}`:`$(${t})`;let r=e.invocation.args?.length??0;return`$(${t}).${n}${r?`(${r}_${qt(`arg`,r)})`:`()`}`}),null,2))}function En(e){return`name`in e&&typeof e.name==`string`?e.name:`store`}const Dn=Symbol(),On=Symbol(),kn=Symbol(`stores.derivedStore.readDependencyState`);function An(e,t=Object.is){let n,i=!1,o,s=!1,c=!1;typeof t==`function`?o=t:(n=t.debounce,i=r?t.debugMode??!1:!1,o=t.equalityFn??Object.is,s=t.keepAlive??!1,c=t.lockDependencies??!1);let l=new Xt,u=new Yt(k),d=+!!s,f,p,m=Dn,h=!1,g=!1,_=!0,v=!0,y=null,b=On;function x(e,t,n){if(!v)return(t??a)(Nn(e));if(!d)return(t??a)(e.getState());if(!t){let t=Nn(e);return!t||typeof t!=`object`?(u.retainState(e),t):(f||(f=new WeakMap),p||(p=mn()),nn(e,t,f,p.trackPath))}let r=n?{equalityFn:n,isCascadeParticipant:!0}:Jt;return u.addSelector(e.subscribe(t,k,r)),t(Nn(e))}function S(){if(!_&&$(m))return m;_=!1,v&&u.beginRebuild(!0);let t=!0,n=m,r=$(n);g=!0;try{let a=e(x),s=p?on(a):a;r&&o(n,s)?(i&&console.log(`[π₯· Derive Complete π₯·]: No change detected`),t=!1,m=n):m=s}finally{g=!1,v&&u.finishRebuild(!0)}let a=i&&(!r||i===`verbose`&&v);if(a){r?i===`verbose`&&console.log(`[π Rebuilding Subscriptions π]: Createdβ¦`):console.log(`[π Initial Derive Complete π]: Createdβ¦`);let e=u.size;console.log(`[π― ${e} ${qt(`Selector Subscription`,e)} π―]`)}return p&&v&&(p.buildProxySubscriptions((e,t)=>{u.addSelector(e.subscribe(t,k,Jt))},a),f=void 0,c?p=void 0:p.reset()),t&&r&&C(m,n),c&&(v=!1),m}function C(e,t){let n=l.cascadeParticipantCount,r=n>0&&l.ordinaryWatcherCount>0,a=l.ordinaryWatcherCount>0&&(r||We()!==null||Ue());if(r&&Ge(),i){let e=l.ordinaryWatcherCount+n;console.log(`[π» Derive Complete π»]: Notifying ${e} ${qt(`watcher`,e)}`)}if(n&&l.notifyCascade(e,t),l.ordinaryWatcherCount){if(a){b===On?(b=t,Je(w)):$(b)||(b=t);return}l.notifyOrdinary(e,t)}}function w(){d&&_&&!l.cascadeParticipantCount&&S();let e=b;b=On,l.ordinaryWatcherCount&&$(m)&&e!==On&&$(e)&&l.notifyOrdinary(m,e)}let T=n?yt(D,typeof n==`number`?n:n.delay,typeof n==`number`?{leading:!1,maxWait:n,trailing:!0}:n):void 0,E=T??(()=>{h||(h=!0,queueMicrotask(D))});function D(){if(h=!1,!d){s||P();return}_&&S()}function O(e){if(e!==void 0&&(e||T&&_)){queueMicrotask(O);return}!d&&!s&&P()}function ee(){let e=y;e===We()&&(D(),y===e&&(y=null))}function k(){if(!g){if(!T){if(l.cascadeParticipantCount){_=!0,Ge();let e=We(),t=e===null?0:e+1;if(y!==null&&t<=y)return;y=t,Ye(ee,t);return}if(_)return;if(_=!0,Ue()){b===On&&(b=Dn,Je(w));return}}_||(_=!0,y=null,E())}}function A(e){d+=1;try{return e()}finally{--d}}function j(){return _||!$(m)?d?S():A(S):(h&&d&&D(),m)}function M(){return Ue()&&We()===null&&qe(),_||!$(m)?d?S():e(x):m}function te(...e){if(e.length===1){let t=e[0];return l.addWatcher(t)&&(d+=1),$(m)||M(),()=>{l.deleteWatcher(t)&&(--d,d||O(!1))}}let[t,n,r]=e,i=r?.equalityFn??Object.is,a=r?.isCascadeParticipant??!1,o=t(d?M():A(M)),s={currentSlice:o,equalityFn:i,isCascadeParticipant:a,listener:n,selector:t};return l.addWatcher(s),d+=1,r?.fireImmediately&&n(o,o),()=>{l.deleteWatcher(s)&&(--d,d||O(a))}}function N(e){return d?M():A(M),l.addCascadeStateListener(e)&&(d+=1),()=>{l.deleteCascadeStateListener(e)&&(--d,d||O(!0))}}function ne(){d&&(T?T.flush():_&&S())}function P(){T?.cancel(),u.clear(),l.clear(),d=0,p=void 0,f=void 0,v=!0,h=!1,g=!1,_=!0,m=Dn,b=On,y=null}function F(){return _||h||!$(m)?d?S():A(S):m}return{[kn]:F,[Q]:N,destroy:P,flushUpdates:ne,getSnapshot:j,getState:M,subscribe:te,getInitialState:jn,setState:Mn}}function jn(){throw Error(`[createDerivedStore]: getInitialState() is not available on derived stores.`)}function Mn(){throw Error(`[createDerivedStore]: setState() is not available on derived stores.`)}function Nn(e){let t=e[kn];return t?t():e.getState()}function $(e){return e!==Dn}var Pn=class{constructor(e){this.count=0,this.lastSubscriptionTime=null,this.fetchThrottleMs=null,this.onSubscribe=null,this.onLastUnsubscribe=null,e&&(this.fetchThrottleMs=W.seconds(5))}init({onSubscribe:e,onLastUnsubscribe:t}){this.onSubscribe=e,this.onLastUnsubscribe=t}hasSubscribers(){return this.count>0}subscribe(){let e=this.count===0,t=this.fetchThrottleMs!==null,n=t&&this.lastSubscriptionTime!==null&&!e&&Date.now()-this.lastSubscriptionTime<=this.fetchThrottleMs;return this.count+=1,this.onSubscribe?.(e,n),t&&(this.lastSubscriptionTime=Date.now()),e=>{let t=this.count===1;this.count=Math.max(this.count-1,0),t&&(this.onLastUnsubscribe?.(e),this.lastSubscriptionTime=null)}}};function Fn(e,t=queueMicrotask){let n=!1,r;function i(){n=!1,e(...r)}function a(...e){r=e,!n&&(n=!0,t(i))}return a}const In=Symbol(`stores.queryParamConfig`);function Ln(e,t){return{[In]:!0,key:t.key,value:e}}function Rn(e){return!!e&&typeof e==`object`&&In in e}function zn(e){return JSON.stringify(Vn(e))}function Bn(e){return JSON.parse(e)}function Vn(e){return typeof e!=`object`||!e?e:Object.keys(e).sort().reduce((t,n)=>{let r=e[n];return t[n]=k(r)?Vn(r):r,t},o())}const Hn=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});function Un(e,t,n){let r=o(),i=null,a=!1;if(e)for(let n in e){if(!O(e,n))continue;let s=Wn(r,e[n],n,t);s&&((i??(i=o()))[n]=s,s.key!==void 0&&(a=!0))}return{buildKey(e=r){return zn(a?Yn(i,e):e)},complete(e){return e?Qn(e,n)?e:{...r,...e}:qn(r)},get(){return qn(r)},subscribe(e){return Jn(i,r,e)}}}function Wn(e,t,n,r){return Rn(t)?Kn(e,t.value,n,r,t.key):Kn(e,t,n,r)}function Gn(e,t){let n=[],r,i;function o(e,t,a){return t?(n.push(n=>e.subscribe(t,n,Xn(a))),t(Zn(e))):(r??(r=mn()),i??(i=new WeakMap),nn(e,Zn(e),i,r.trackPath))}function s(e,t=a){return t(Zn(e))}let c=e(o,t),l=r?on(c):c;return r&&(r.buildProxySubscriptions((e,t)=>{n.push(n=>e.subscribe(t,n,Hn))},!1),r=void 0),i=void 0,{initialValue:l,subscribe(r){let i=()=>r(e(s,t)),a=n.map(e=>e(i));return e=>{for(let t of a)t(e)}}}}function Kn(e,t,n,r,i){if($n(t)){let a=Gn(t,r);return e[n]=a.initialValue,i===void 0?{tracked:a}:{key:i,tracked:a}}return e[n]=t,i===void 0?null:{key:i}}function qn(e){let t=o();for(let n in e)O(e,n)&&(t[n]=e[n]);return t}function Jn(e,t,n){if(!e)return c;let r;for(let i in e){let a=e[i]?.tracked;a&&(r??(r=[])).push(a.subscribe(e=>{let r=t[i];Ae(r,e)||(t[i]=e,n(i,r,e))}))}return r?e=>{for(let t of r)t(e)}:c}function Yn(e,t){let n=o();for(let r in t){if(!O(t,r))continue;let i=e?.[r];if(i?.key===!1)continue;let a=t[r];n[r]=i?.key?i.key(a):a}return n}function Xn(e){return e?{equalityFn:e,isCascadeParticipant:!0}:Hn}function Zn(e){return be(e)?e.getSnapshot():e.getState()}function Qn(e,t){for(let n of t)if(!(n in e))return!1;return!0}function $n(e){return typeof e==`function`}const er={error:!0,lastFetchedAt:!0,queryCache:!0,queryKey:!0,status:!0,enabled:!1,fetch:!1,getCacheEntry:!1,getData:!1,getStatus:!1,isDataExpired:!1,isStale:!1,reset:!1},tr=Object.freeze({force:!0}),nr=Object.freeze({once:!0}),rr=new Set;let ir=!1;function ar(e){rr.add(e),!ir&&(ir=!0,queueMicrotask(()=>{ir=!1,Fe(or)}))}function or(){for(let e of rr)rr.delete(e),e()}function sr(e,t,n){re();let a=typeof t==`function`?t:dr,o=typeof t==`object`?t:n,c=cr(o)?o:void 0,l=ae(),u=l.minStaleTime,{fetcher:d,onError:f=l.onError,onFetched:p,setData:m,transform:h,abortInterruptedFetches:g=l.abortInterruptedFetches,cacheTime:_=l.cacheTime,debugMode:v=l.debugMode,disableAutoRefetching:y=l.disableAutoRefetching,disableCache:b=!1,enabled:x=!0,keepPreviousData:S=l.keepPreviousData,paramChangeThrottle:C=l.paramChangeThrottle,params:w,retry:E=l.retry,retryDelay:D=l.retryDelay,staleTime:O=l.staleTime,suppressStaleTimeWarning:ee=l.suppressStaleTimeWarning}=e,k=typeof O==`function`?l.staleTime:O;r&&u!==!1&&!y&&!ee&&k<u&&console.warn(`[createQueryStore${c?.storageKey?`: ${c.storageKey}`:``}] β Stale times under ${u/1e3} seconds are not recommended. Provided staleTime: ${k/1e3} seconds`);let A=Error(`[createQueryStore: AbortError] Fetch interrupted`),te=typeof _==`function`,N=r&&v,ne=e.params?Object.keys(e.params):[],P=!1,F,I=[],L=null,R=null,z=null,B=null,V=null,H=null,ie=null,W={enabled:typeof x==`function`?!1:x,error:null,lastFetchedAt:null,queryCache:{},queryKey:``,status:U.Idle},G=new Pn(y);function oe(){z&&(B=null,z.abort(),z=null)}function K(){V&&(clearTimeout(V),V=null)}async function ce(e){let t=new AbortController;z=t;try{return await new Promise((n,r)=>{t.signal.addEventListener(`abort`,()=>r(A),nr),Promise.resolve(d(e,t)).then(n,r)})}finally{z===t&&(z=null)}}function le(e,t,n){let r=n.setState;function i(e,t){e!==t&&ie!==t&&(ie=t,t&&G.hasSubscribers()?queueMicrotask(()=>u.fetch(void 0,void 0,!0)):(V||g)&&(g&&oe(),K()))}function o(e){let t=typeof e==`function`;if(t||e.enabled!==void 0){let n,a=r(r=>{let a=t?e(r):e,o=a.enabled===void 0?r.enabled:a.enabled;return o!==r.enabled&&(n=()=>i(r.enabled,o)),a});return n?.(),a}else return r(e)}n.setState=o,G.init({onSubscribe:(n,r)=>{let i=t();if(i.enabled)if(n){let t=F.get(),n=F.buildKey(t);i.queryKey!==n&&e({queryKey:n}),i.isStale()?u.fetch(t,void 0,!0):s(t)}else y&&!r&&u.fetch(void 0,void 0,!0)},onLastUnsubscribe:e=>{K(),g&&!e&&oe()}});function s(e){if(y||k<=0||k===1/0||!G.hasSubscribers())return;K();let n=t();if(!n.enabled)return;let r=F.buildKey(e),i=(b?H===r&&n.lastFetchedAt:n.queryCache[r]?.lastFetchedAt)||null,a=i?k-(Date.now()-i):k;V=setTimeout(()=>{t().enabled&&u.fetch(e,tr,!0)},a)}function l(e){let n=t(),r=n.status;switch(e){case`isIdle`:return r===U.Idle;case`isLoading`:return r===U.Loading;case`isError`:case`isInitialLoad`:case`isSuccess`:case void 0:{let t=n.queryKey,i=b?void 0:n.queryCache[t],a=b?r===U.Error:typeof i?.errorInfo?.lastFailedAt==`number`;if(e===`isError`)return a;let o=((b?H===t&&n.lastFetchedAt:i?.lastFetchedAt)||null)!==null,s=!o&&!a&&n.enabled;if(e===`isInitialLoad`)return s;let c=o&&!a;return e===`isSuccess`?c:{isError:a,isIdle:r===U.Idle,isLoading:r===U.Loading,isInitialLoad:s,isSuccess:c}}}}let u={...a(o,t,n),...W,async fetch(n,r,i=!1,a=0){let l=!!r?.skipStoreUpdates,v=t();if(!l&&(!v.enabled&&!r?.force||i&&!G.hasSubscribers()))return null;let y=v.error,x=v.queryKey,C=v.status===U.Loading,w=F.complete(n),O=F.buildKey(w);if(C&&B?.promise&&B.key===O)return N&&console.log(`[π Using Active Fetch π] for params:`,JSON.stringify(w)),B.promise;let ee=r?.staleTime??k,P=typeof r?.updateQueryKey==`boolean`?r.updateQueryKey:i?S:!1,I=(i||x===O||P)&&!l,L=B!==null;if(g&&I&&oe(),!r?.force){let t=v.lastFetchedAt,n=b?void 0:v.queryCache[O],r=n?.lastFetchedAt,i=n?.errorInfo,a=(b?H===O&&t:r)||null;if(!(!a||Date.now()-a>=ee)&&(!i||!i.retryAllowed||l))return I&&!V&&k!==0&&k!==1/0&&s(w),P&&e(e=>e.queryKey===O?e:{queryKey:O}),N&&console.log(`[πΎ Returning Cached Data πΎ] for params:`,JSON.stringify(w)),n?.data??null}let R=I?{key:O}:null,z=r?.cacheTime??(te?_(w):_);R&&(K(),P&&!L&&v.lastFetchedAt===null&&x!==O?e({error:null,queryKey:O,status:U.Loading}):(y||!C)&&e({error:null,status:U.Loading}),B=R);async function re(){let v=c?.storageKey||O;try{N&&(!i&&n&&ne.some(e=>!(e in n))?console.log(`[π Fetching with Partial Params π]
|
|
7
|
+
`,`- Provided params:`,`${JSON.stringify(n)}\n`,`- Filled in params:`,`${JSON.stringify(Object.fromEntries(Object.keys(w).filter(e=>!(e in n)).map(e=>[e,w[e]])))}`):console.log(`[π Fetching π] for params:`,JSON.stringify(w)));let t=await(g&&I?ce(w):d(w,null)),a=Date.now();N&&console.log(`[β
Fetch Successful β
] for params:`,JSON.stringify(w));let c;try{c=pr(t,w,h)}catch(e){throw fr(v,`transform`,e)}if(l)return N&&console.log(`[π₯· Successful Parallel Fetch π₯·] for params:`,JSON.stringify(w)),r.skipStoreUpdates===`withCache`&&e(e=>{if(!m)return b?e:{queryCache:{...e.queryCache,[O]:{cacheTime:z,data:c,errorInfo:null,lastFetchedAt:a}}};let t=e,n=b?void 0:t.queryCache[O];try{m({data:c,params:w,queryKey:O,set:e=>{t=typeof e==`function`?{...t,...e(t)}:{...t,...e}}})}catch(e){throw fr(v,`setData`,e)}return!b&&Object.is(n,t.queryCache[O])&&(t={...t,queryCache:{...t.queryCache,[O]:{cacheTime:z,data:null,errorInfo:null,lastFetchedAt:a}}}),t}),c;if((m?o:e)(e=>{let t={...e,error:null,lastFetchedAt:a,queryKey:P?O:e.queryKey,status:U.Success};if(!m&&!b)N&&console.log(`[πΎ Setting Cache πΎ] for params:`,JSON.stringify(w),`| Has previous data?:`,!!t.queryCache[O]?.data),t.queryCache={...t.queryCache,[O]:{cacheTime:z,data:c,errorInfo:null,lastFetchedAt:a}};else if(m){N&&console.log(`[πΎ Setting Data πΎ] for params:`,JSON.stringify(w));let e=b?void 0:t.queryCache[O];try{m({data:c,params:w,queryKey:O,set:e=>{t=typeof e==`function`?{...t,...e(t)}:{...t,...e}}})}catch(e){throw fr(v,`setData`,e)}!b&&Object.is(e,t.queryCache[O])&&(t.queryCache={...t.queryCache,[O]:{cacheTime:z,data:null,errorInfo:null,lastFetchedAt:a}})}return b||_===1/0?t:ur(S,O,t)}),I&&(H=O,s(w)),p)try{p({data:c,fetch:u.fetch,params:w,set:o})}catch(e){T.error(fr(v,`onFetched callback`,e))}return c??null}catch(n){if(n===A)return N&&console.log(`[β Fetch Aborted β] for params:`,JSON.stringify(w)),null;let o=!i&&r?.throwOnError===!0,s=M(n);if(s instanceof j&&T.error(s),!I){if(o)throw s;return null}let c=b?void 0:t().queryCache[O],l,d;if(typeof E==`function`){l={error:s,params:w,queryKey:O,retryCount:a};try{d=E(l)}catch(e){T.error(fr(v,`retry callback`,e)),d=!1}}else d=E!==!1&&a<E;let p;if(d&&t().enabled&&G.hasSubscribers())if(D===void 0)p=se(a);else if(typeof D==`number`)p=D;else{l??(l={error:s,params:w,queryKey:O,retryCount:a});try{p=D(l)}catch(e){T.error(fr(v,`retryDelay callback`,e)),d=!1}}let m=p!==void 0;if(p!==void 0&&(K(),V=setTimeout(()=>{t().enabled&&u.fetch(w,tr,!0,a+1)},p)),e(b?e=>({error:s,queryKey:P?O:e.queryKey,status:U.Error}):e=>({error:s,queryCache:{...e.queryCache,[O]:{cacheTime:c?.cacheTime??z,data:c?.data??null,lastFetchedAt:c?.lastFetchedAt??null,errorInfo:{error:s,lastFailedAt:Date.now(),retryAllowed:d,retryCount:a}}},queryKey:P?O:e.queryKey,status:U.Error})),f)try{f({error:s,params:w,queryKey:O,retryCount:a,willRetry:m})}catch(e){T.error(fr(v,`onError callback`,e))}if(o)throw s;return null}finally{B===R&&(B=null)}}return R?(R.promise=re(),R.promise):re()},getCacheEntry(e){if(b)return null;let n=t(),r=e?typeof e==`string`?e:F.buildKey(F.complete(e)):n.queryKey;return n.queryCache[r]??null},getData(e){if(b)return null;let n=t().getCacheEntry(e);return!n||n.data===null?null:S?n.data:n.lastFetchedAt&&Date.now()-n.lastFetchedAt>=n.cacheTime?null:n.data},getStatus:l,isDataExpired(e){let n=t(),r=n.queryKey,i=b?void 0:n.queryCache[r],a=n.lastFetchedAt,o=(b?H===r&&a:i?.lastFetchedAt)||null;if(!o)return!0;let s=e??i?.cacheTime;return s===void 0||Date.now()-o>=s},isStale(e){let n=t(),r=n.queryKey,i=(b?H===r&&n.lastFetchedAt:n.queryCache[r]?.lastFetchedAt)||null;if(!i)return!0;let a=e??k;return Date.now()-i>=a},reset(t=!1){for(let e of I)e();I=[],F=Un(void 0,q,ne),L=null,R=null,oe(),K(),ye?.cancel(),B=null,H=null,t&&e(W)}},v=n.subscribe;return n.subscribe=(...e)=>{let t=P?void 0:G.subscribe(),n=e.length===1?v(e[0]):v(e[0],e[1],e[2]);return e=>{t?.(e),n(e)}},rt(n,e=>t=>{let n=P?void 0:G.subscribe(),r=e(t);return e=>{n?.(e),r(e)}}),u}let q=c?.storageKey?Gt(le,s(c,{partialize:lr(S,c.partialize)})):o&&!(`storageKey`in o)?Gt(le,o):Gt(le),ue=q.getState(),de=ue.error,fe=ue.enabled,he=ue.queryKey,ge=ue.fetch;he&&!de&&(H=he),P=!0,F=Un(w,q,ne),typeof x==`function`&&(L=Gn(x,q)),typeof e.staleTime==`function`&&(R=Gn(e.staleTime,q),k=R.initialValue);let _e=Fn(e=>{ge(e,void 0,!0)},ar);function ve(){if(S)_e(void 0);else{let e=F.get();q.setState({queryKey:F.buildKey(e)}),_e(e)}}let ye=i||!C?void 0:yt(ve,typeof C==`number`?C:C.delay,typeof C==`number`?{leading:!1,maxWait:C,trailing:!0}:C);function be(){if(K(),ye){let e=q.getState();S&&B?.key===e.queryKey&&e.lastFetchedAt===null?ve():ye();return}ve()}if(I.push(F.subscribe((e,t,n)=>{N&&console.log(`[π Param Change π] -`,e,`- [Old]:`,`${t?.toString()},`,`[New]:`,n?.toString()),be()})),R){let e=R.initialValue;N&&console.log(`[π StaleTime Subscription π] Initial value:`,e),I.push(R.subscribe(t=>{t!==e&&(N&&console.log(`[π StaleTime Change π] - [Old]:`,`${e},`,`[New]:`,t),e=t,k=t,K(),ge(void 0,void 0,!0))}))}let J;if(L){let e=L.initialValue;fe!==e&&((J??(J={})).enabled=e),N&&console.log(`[π Enabled Subscription π] Initial value:`,e),I.push(L.subscribe(t=>{t!==e&&(N&&console.log(`[π Enabled Change π] - [Old]:`,`${e},`,`[New]:`,t),e=t,q.setState({enabled:t}))}))}else fe!==W.enabled&&((J??(J={})).enabled=W.enabled);let xe=F.buildKey();return xe!==he&&((J??(J={})).queryKey=xe),J&&q.setState(J),P=!1,me(q,pe.QueryStore)}function cr(e){return typeof e?.storageKey==`string`}function lr(e,t){return n=>{let r={...n},i=o();for(let e in r)O(r,e)&&e in er&&(er[e]&&(i[e]=r[e]),delete r[e]);return{...t?t(r):Ct(r),...ur(e,null,i)}}}function ur(e,t,n){if(!n.queryCache)return n;let r=Date.now(),i=t??(e&&n.queryKey||null),a=o(),s=!1;for(let e in n.queryCache){if(!O(n.queryCache,e))continue;let t=n.queryCache[e];t&&(r-(t.lastFetchedAt??t.errorInfo.lastFailedAt)<t.cacheTime||e===i)?a[e]=t:s=!0}return s?{...n,queryCache:a}:n}function dr(){return Object.create(null)}function fr(e,t,n){return new j(`[createQueryStore: ${e}]: ${t} failed`,n)}function pr(e,t,n){return n?n(e,t):e}const mr=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});function hr(e,t,n){let r=typeof t==`function`,i=r?t:void 0,a=r?n:t,o=new Set,s,c;function l(e,t){let n=e.getState(),r=t.getState();if(c)for(let e of c)u(e,t,n,r);if(s)for(let e of s)d(e,t,n,r);o.size&&Ke();for(let e of o)f(e,t,n,r)}function u(e,t,n,r){e.unsubscribe(),e.unsubscribe=gr(t,e.listener),!Object.is(r,n)&&(Ge(),e.listener(r,n))}function d(e,t,n,r){f(e,t,n,r)&&Ge()}function f(e,t,n,r){e.unsubscribe();let i=e.args;if(i.length===1){let a=i[0];e.unsubscribe=t.subscribe(a);let o=!Object.is(r,n);return o&&a(r,n),o}let a=i[0],o=i[1],s=i[2];s?.fireImmediately&&(s={...s,fireImmediately:!1});let c=a(n),l=a(r);return e.unsubscribe=t.subscribe(a,o,s),(s?.equalityFn??Object.is)(c,l)?!1:(o(l,c),!0)}function p(e,t){l(t,e),he(t)}let m=An(e,{debugMode:a?.debugMode??!1,lockDependencies:a?.lockDependencies??!0}),h;function g(){return h??(h=m.subscribe(p)),m.getState()}function _(...e){let t=g(),n={args:e,unsubscribe:e.length===1?t.subscribe(e[0]):t.subscribe(e[0],e[1],e[2])},r=e[2]?.isCascadeParticipant??!1;return r?(s??(s=new Set)).add(n):o.add(n),()=>{n.unsubscribe(),r?s?.delete(n)&&s.size===0&&(s=void 0):o.delete(n)}}function v(e){let t={listener:e,unsubscribe:gr(g(),e)};return(c??(c=new Set)).add(t),e=>{t.unsubscribe(e),c?.delete(t)&&c.size===0&&(c=void 0)}}return Object.assign({[Q]:v,[pe.VirtualStore]:!0,destroy:()=>{h?.(),h=void 0,m.destroy()},getInitialState:()=>g().getInitialState(),getState:()=>g().getState(),persist:_r(g),setState:vr(g),subscribe:_},i?.(g))}function gr(e,t){return nt(e)?e[Q](t):e.subscribe(a,t,mr)}function _r(e){return{clearStorage:()=>e().persist?.clearStorage(),getOptions:()=>e().persist?.getOptions()??{},hasHydrated:()=>e().persist?.hasHydrated()??!0,hydrationPromise:()=>e().persist?.hydrationPromise?.()??Promise.resolve(),onFinishHydration:t=>e().persist?.onFinishHydration(t)??c,onHydrate:t=>e().persist?.onHydrate(t)??c,rehydrate:()=>e().persist?.rehydrate(),setOptions:t=>e().persist?.setOptions(t)}}function vr(e){return function(...t){return t[1]===!0?e().setState(t[0],!0):e().setState(t[0])}}function yr(e,t){let n=Gt(e,t);return x(n,n.getState,n.getInitialState)}function br(e,t=Object.is){let n=An(e,t);return x(n,n.getSnapshot,void 0)}function xr(e,t,n){let r=sr(e,t,n);return x(r,r.getState,r.getInitialState)}function Sr(e,t,n){let r=hr(e,t,n);return x(r,r.getState,r.getInitialState)}const Cr=Symbol();function wr(t){let n=(0,e.useRef)(Cr);return n.current===Cr&&(n.current=t()),n}const Tr=Object.freeze({debugMode:!1,enabled:!0,equalityFn:Object.is,fireImmediately:!1});function Er(t,n,r,i=Tr){let a=wr(()=>Ar(n,r,i)),o=Mr(i);return Nr(a,n,r,i),(0,e.useLayoutEffect)(()=>{if(o)return Or(t,a),()=>kr(a)},[o,t]),a}const Dr=Object.freeze({fireImmediately:!1,forceResubscribe:!1});function Or(e,t,n=Dr){if(t.current.isActive){if(!n?.forceResubscribe)return;t.current.unsubscribe()}t.current.options.debugMode&&console.log(`[π‘ useListen π‘] Attaching listener`),t.current.isActive=!0,t.current.resubscribe=(n=Dr)=>Or(e,t,n);let r=e.subscribe(e=>t.current.selector(e),(n,i)=>t.current.react(n,i,e.getState,()=>{r(),t.current.isActive=!1}),n.fireImmediately?{...t.current.options,fireImmediately:!0}:t.current.options);t.current.unsubscribe=()=>{t.current.isActive&&(r(),t.current.isActive=!1)}}function kr(e){e.current.options.debugMode&&console.log(`[ποΈ useListen ποΈ] Detaching listener`),e.current.resubscribe=c,e.current.unsubscribe(),e.current.unsubscribe=c,e.current.isActive=!1}function Ar(e,t,n){return{selector:e,react:t,isActive:!1,options:jr(n),resubscribe:c,unsubscribe:c}}function jr(e){return typeof e==`function`?{equalityFn:e}:e??Tr}function Mr(e){return typeof e==`function`?Tr.enabled:e?.enabled??Tr.enabled}function Nr(e,t,n,r){e.current.selector=t,e.current.react=n,typeof r==`function`?e.current.options.equalityFn=r:r&&(e.current.options=r??Tr)}const Pr=Symbol();function Fr(t){let n=(0,e.useRef)(Pr);return n.current===Pr&&(n.current=t()),n.current}exports.QueryStatuses=U,exports.StoresError=j,exports.applyStateUpdate=ce,exports.configureStores=R,exports.createBaseStore=yr,exports.createDerivedStore=br,exports.createQueryStore=xr,exports.createStoreActions=we,exports.createVirtualStore=Sr,exports.deepEqual=Oe,exports.defaultRetryDelay=se,exports.destroyStore=he,exports.destroyStores=ge,exports.getQueryKey=zn,exports.getStoreName=_e,exports.hasGetSnapshot=be,exports.identity=a,exports.isDerivedStore=xe,exports.isPersistedStore=Se,exports.isQueryStore=J,exports.isVirtualStore=Ce,exports.nullObject=o,exports.parseQueryKey=Bn,exports.queryParam=Ln,exports.replacer=de,exports.reviver=fe,exports.shallowEqual=ke,exports.time=W,exports.useListen=Er,exports.useStableValue=Fr;
|
package/dist/native/index.mjs
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
import{useLayoutEffect as e,useRef as t,useSyncExternalStore as n,useDebugValue as r}from"react";import{Platform as o,unstable_batchedUpdates as i}from"react-native";var s=(e=>"undefined"!=typeof require?require:"undefined"!=typeof Proxy?new Proxy(e,{get:(e,t)=>("undefined"!=typeof require?require:e)[t]}):e)(function(e){if("undefined"!=typeof require)return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')}),c="ios"===o.OS;o.OS;var a="development"===process.env.NODE_ENV,u="test"===process.env.NODE_ENV;function l(e){return e}function f(){return{__proto__:null}}function d(){}Object.freeze(Object.create(null));var y=Symbol("empty selection"),p=Object.is;function h(e,t){return n=>(function(e){e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedSource=e.source,e.committedValue=e.value===y?g(e):e.value}(e),t(r=>{e.latestSnapshot=r,e.latestSource=t;const o=e.committedValue;if(o===y||e.committedSource!==t)return void n();const i=e.committedSelector,s=e.committedEqualityFn;if(e.selector===i&&e.equalityFn===s){const t=i(r);if(s===p?p(o,t):s(o,t))return;return e.committedValue=t,e.value=t,e.valueEqualityFn=s,e.valueSelector=i,e.valueSnapshot=r,void n()}if(e.source!==t)return void n();const c=e.value;if(c===y)return;const a=e.selector(r),u=e.equalityFn(c,a);e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedValue=m(e,r,u?c:a),u||n()}))}function g(e){const t=function(e){if(e.latestSource===e.source&&e.latestSnapshot!==y)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 n=e.value;if(n!==y&&p(e.valueSnapshot,t)&&e.valueSelector===e.selector&&e.valueEqualityFn===e.equalityFn)return n;const r=e.selector(t);if(n!==y&&(e.equalityFn===p?p(n,r):e.equalityFn(n,r)))return m(e,t,n);const o=e.committedValue;return o!==y&&o!==n&&e.committedSource===e.source&&(e.equalityFn===p?p(o,r):e.equalityFn(o,r))?m(e,t,o):m(e,t,r)}function m(e,t,n){return e.value=n,e.valueEqualityFn=e.equalityFn,e.valueSelector=e.selector,e.valueSnapshot=t,n}function S(e,o,i,s){return Object.assign(function(c,a){return function(e,o,i,s,c=p){const a=t(null);let u=e,l=o,f=i;if(s){let t=a.current;null===t&&(t=function(e,t,n,r,o){const i={committedEqualityFn:o,committedSelector:r,committedSource:e,committedValue:y,equalityFn:o,getSelectedServerSnapshot:()=>function(e){return b(e,(e.getServerStoreSnapshot??e.getStoreSnapshot)())}(i),getSelectedSnapshot:()=>g(i),getServerStoreSnapshot:n,getStoreSnapshot:t,latestSnapshot:y,latestSource:y,selector:r,selectedSource:e,selectedSubscribe:()=>d,source:e,value:y,valueEqualityFn:o,valueSelector:r,valueSnapshot:y};return i.selectedSubscribe=h(i,e),i}(e,o,i,s,c),a.current=t),function(e,t,n,r,o,i){e.source===t&&e.getStoreSnapshot===n||(e.latestSnapshot=y),e.source=t,e.getStoreSnapshot=n,e.getServerStoreSnapshot=r,e.selector=o,e.equalityFn=i,e.selectedSource!==t&&(e.selectedSource=t,e.selectedSubscribe=h(e,t))}(t,e,o,i,s,c),u=t.selectedSubscribe,l=t.getSelectedSnapshot,f=void 0===i?void 0:t.getSelectedServerSnapshot}const m=n(u,l,f);return r(m),m}(e.subscribe,o,i,c,a??s)},e)}function v(e){let t;function n(){if(t)return t;try{const n=function(e){const{createMMKV:t,MMKV:n}=s("react-native-mmkv");if("function"==typeof t)return t({id:e});if("function"==typeof n)return new n({id:e});throw new Error("[stores]: react-native-mmkv module does not export MMKV/createMMKV.")}(e);let r;if("function"==typeof n.delete?r=n.delete.bind(n):"function"==typeof n.remove&&(r=n.remove.bind(n)),"function"!=typeof r)throw new Error("[stores]: Storage instance does not conform to expected interface");const o={clearAll:n.clearAll.bind(n),contains:n.contains.bind(n),delete:r,get:n.getString.bind(n),getAllKeys:n.getAllKeys.bind(n),set:n.set.bind(n)};t=o}catch(e){throw new Error("[stores] react-native-mmkv could not be loaded.\n\nPersisted stores require a storage backend. Either:\n - Install MMKV (the default): yarn add react-native-mmkv\n - Or provide a custom adapter via configureStores()\n"+(e instanceof Error?`\n${e.message}`:""))}return function(e){if(!e||"function"!=typeof e.get||"function"!=typeof e.set||"function"!=typeof e.delete||"function"!=typeof e.clearAll)throw new Error("[stores]: Storage instance does not conform to expected interface")}(t),t}return{clearAll:()=>n().clearAll(),contains:e=>n().contains(e),delete:e=>n().delete(e),get:e=>n().get(e),getAllKeys:()=>n().getAllKeys(),set:(e,t)=>n().set(e,t)}}var w={debug:(e,t)=>{a&&console.debug(e,t)},error:(e,t)=>{a&&!u&&console.error(e,t)},info:(e,t)=>{a&&console.info(e,t)},warn:(e,t)=>{a&&console.warn(e,t)}},O=Object.prototype.hasOwnProperty;function q(e,t){return O.call(e,t)}function j(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}function F(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}var _=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 k(e){return e instanceof Error?e:new Error(String(e))}var I,A,C,z=class{destroy(){}publish(){}},T=class{constructor(){this.sessionId="noop"}register(e){return new z}},M=!1;function E(e){var t;a&&function(){if(M)throw new Error("[stores]: configureStores() called after first store creation. Call it earlier before creating any stores.")}(),e.logger&&(t=e.logger,w=t),A??(A=function(e){return e?.queryStoreDefaults?{queryStoreDefaults:e.queryStoreDefaults}:void 0}(e)),C??(C=D(e))}function P(){return C??(C=D(void 0))}function K(){M=!0}function D(e){return{storage:e?.storage??v(e?.storageKeyPrefix??"stores:"),syncEngine:e?.syncEngine??(I||(I=new T),I)}}var x,R={Error:"error",Idle:"idle",Loading:"loading",Success:"success"},$={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??$.seconds(5),r=t?.maxDelay??$.minutes(5);return Math.min(n*Math.pow(2,e),r)}function N(e,t){return!0===t[1]?e(t[0],!0):e(t[0])}function V(e,t,n){if(!0===n)return H(t)?t(e):t;const r=H(t)?t(e):t;return Object.is(r,e)?e:F(e)&&F(r)?{...e,...r}:r}function H(e){return"function"==typeof e}function W(e,t){return t instanceof Map?{__type:"Map",entries:Array.from(t.entries())}:t instanceof Set?{__type:"Set",values:Array.from(t)}:t}function J(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 U=Object.freeze({QueryStore:Symbol("queryStore"),VirtualStore:Symbol("virtualStore")});function B(e,t){Y(e)?e.getState().reset(t?.clearQueryCache):function(e){return"destroy"in e}(e)&&e.destroy()}function Q(e,t){for(const n of Array.isArray(e)?e:Object.values(e))n&&!t?.skipDestroy?.(n)&&B(n,t)}function G(e){const t="function"==typeof(n=e)?n.name:"";var n;return ee(e)?e.persist.getOptions().name??t:t}function X(e){return"getSnapshot"in e}function Y(e){return U.QueryStore in e}function Z(e){return"flushUpdates"in e}function ee(e){return!(!("persist"in e)||!e.persist)&&"string"==typeof e.persist.getOptions().name}function te(e){return U.VirtualStore in e}function ne(e,t){const n=function(e){const t=e.getState(),n={__proto__:null},r=n;if(a&&("object"!=typeof t||null===t))throw new Error("[createStoreActions]: State is not an object");if(te(e))for(const n in t)oe(t,n)&&(r[n]=re(e,n));else for(const e in t)oe(t,e)&&(r[e]=t[e]);return n}(e);return t?Object.assign(n,t):n}function re(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 oe(e,t){return"function"==typeof e[t]}function ie(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)||!ie(e[r],t[r]))return!1;return!0}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(!Object.is(e[r],t[r]))return!1;return!0}function ce(e,t){const n=Object.prototype.hasOwnProperty;function r(e,t){for(const n of e.keys())if(ce(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--&&ce(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(!ce(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)||!ce(e[r],t[r]))return!1}return Object.keys(t).length===i}}return e!=e&&t!=t}var ae=i,ue=!1,le=!1,fe=!1,de=new Set,ye=new Map,pe=new Map,he=null,ge=1/0;function be(){return ue}function me(){return he}function Se(){ue||(ue=!0,fe||(fe=!0,queueMicrotask(()=>{fe=!1,ve()})))}function ve(){if(ue)if(le)Oe();else{le=!0;try{ae(Oe)}finally{Fe()}}}function we(e){ue&&de.add(e)}function Oe(){for(;ye.size>0||de.size>0;)qe(),je()}function qe(){for(;ye.size>0;){const e=ge,t=pe.get(e);if(t){pe.delete(e);for(const e of t)ye.delete(e);he=e;for(const e of t)e();he=null,ge=1/0;for(const e of pe.keys())e<ge&&(ge=e)}else{ge=1/0;for(const e of pe.keys())e<ge&&(ge=e)}}}function je(){for(const e of de)de.delete(e),e()}function Fe(){ue=!1,le=!1,he=null,de.clear(),ye.clear(),pe.clear(),ge=1/0}function _e(e){let t;const n=new Set;let r;function o(...e){const o=V(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&&ve();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&&Se(),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 ke(e){return!!e&&"object"==typeof e&&"then"in e&&"function"==typeof e.then}function Ie(e){return{...e,merge:e.merge??Ae,skipHydration:e.skipHydration??!1}}function Ae(e,t){return void 0===e?t:{...t,...e}}function Ce(){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 ze=Math.max,Te=Math.min;function Me(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 p(e){const n=e-(a??0);return void 0===a||n>=t||n<0||f&&void 0!==i&&e-u>=i}function h(){const e=Ee();if(p(e))return g(e);c=setTimeout(h,function(e){const n=t-(e-(a??0));return f&&void 0!==i?Te(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=p(n);if(r=e,o=this,a=n,i){if(void 0===c)return function(e){return u=e,c=setTimeout(h,t),l?y(e):s}(a);if(f)return clearTimeout(c),c=setTimeout(h,t),y(a)}return void 0===c&&(c=setTimeout(h,t)),s}return t=Pe(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?ze(Pe(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 Pe(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 Ke(e){if(!j(e))return e;const t={__proto__:null},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 De=u?0:$.seconds(c?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??Ke,c=t.deserializer??e.deserializer??$e(o),a=t.serializer??e.serializer??Le(o);function u(t,n,o){try{if(We(r))return;const c={state:s(n),version:o},u=Ve(r,i,c),l=a(c);try{e.set(t,l),He(r,u)}catch(e){w.error(new _("[createBaseStore]: Failed to persist store data",e))}}catch(e){w.error(new _("[createBaseStore]: Failed to persist store data",e))}}const l=void 0!==n?Me(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){w.error(new _("[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??Ke,c=t.deserializer??e.deserializer??$e(o),a=t.serializer??e.serializer??Le(o);async function u(t,n,o){try{if(We(r))return;const c={state:s(n),version:o},u=Ve(r,i,c),l=a(c);try{await e.set(t,l),He(r,u)}catch(e){w.error(new _("[createBaseStore]: Failed to persist store data",e))}}catch(e){w.error(new _("[createBaseStore]: Failed to serialize persisted store data",e))}}const l=void 0!==n?Me(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){w.error(new _("[createBaseStore]: Failed to delete persisted store data",e))}}}}function $e(e){return t=>{if("string"!=typeof t)throw new _("[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?J:void 0)}catch(e){throw w.error(new _("[createBaseStore]: Failed to deserialize persisted store data",e)),e}}(t,e)}}function Le(e){return t=>function(e,t){try{return JSON.stringify(e,t?W:void 0)}catch(e){throw w.error(new _("[createBaseStore]: Failed to serialize store data",e)),e}}(t,e)}var Ne=Object.freeze({shouldClear:!1});function Ve(e,t,n){if(!t||!e)return Ne;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 He(e,t){e&&t.shouldClear&&t.fieldSnapshot&&Object.keys(t.fieldSnapshot).length&&e.clearFieldTimestamps(t.fieldSnapshot)}function We(e){return!!e&&!!e.getIsApplyingRemote()}var[Je,Ue]=[0,1];function Be(e,t,n){if(!e)return!0;const r=e[Je],o=e[Ue];return!(t<r)&&(t>r||n>o)}function Qe(e,t){return Object.prototype.hasOwnProperty.call(t,e)}function Ge(e,t){if(!a)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 Xe(e){if(null===e)return"null";const t=typeof e;return"object"===t?Object.prototype.toString.call(e):t}function Ye(e,t){if(K(),!t)return _e(e);const n=t.storageKey,r="string"==typeof n,o=r?t.storage??P().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 _("[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??P().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,c)=>{const a=new Map,u=[],l=[];let f=null,d=!1,y=!1,p=0,h=null,g=[],b=Promise.resolve(),m=!n;function S(e,t){if(o?.setSessionId&&o?.setTimestamp&&r.sessionId&&(o.setSessionId(r.sessionId),o.setTimestamp(e),o.mergeFieldTimestamps&&t.length>0)){const n={__proto__:null};for(const r of t)n[String(r)]=e;o.mergeFieldTimestamps(n)}}function v(e,t){if(d||!h)return t?i(e,t):i(e);const n=function(){const e=Date.now(),t=e>p?e:p+1;return p=t,t}();let o=[],s={__proto__:null};const c=r=>{const i=V(r,e,t);for(const e of g)Object.is(i[e],r[e])||(o.push(e),s[e]=i[e]);return o.length&&S(n,o),i},u=t?i(c,!0):i(c);function b(){o.length&&function(e){const t=r.sessionId;for(const n of e.keys)a.set(n,[e.timestamp,t]);f&&y?f.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 ke(u)?u.finally(b):(b(),u)}const O=c.setState;c.setState=v;const q=e(v,s,c);if(g=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}(q),!g.length)return q;async function j(e){p=Math.max(p,e.timestamp);const n={__proto__:null},r=s(),i=e.timestamp;let c;if(e.replace)for(const t of g)Qe(t,e.values)||Be(a.get(t),i,e.sessionId)&&(c??(c=[])).push(t);for(const o of g){if(!Qe(o,e.values))continue;if(!h?.has(o))continue;if(!Be(a.get(o),i,e.sessionId))continue;const s=t.merge?.[o];if(s){const t=e.values[o],c=r[o];if(void 0!==t){const u=s(t,c,r,e.values),l=void 0!==c?c:t;if(!Ge(u,l))return void w.error(new _(`[sync] Merge function for field "${String(o)}" returned ${Xe(u)} but expected ${Xe(l)}`));n[o]=u,a.set(o,[i,e.sessionId])}}else n[o]=e.values[o],a.set(o,[i,e.sessionId])}if(Object.keys(n).length>0||c?.length){d=!0,o&&o.setIsApplyingRemote(!0);try{if(e.replace){const e={...r};let t=!1;if(c?.length){t=!0;for(const t of c)delete e[t],a.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??O)(e,!0)}else await(o.setWithoutPersist??O)(n)}finally{d=!1,o&&o.setIsApplyingRemote(!1)}}}function F(e){n?b=b.then(()=>j(e)):j(e)}if(h=new Set(g),f=r.register({apply:e=>{m?F(e):u.push(e)},fields:g,getState:s,key:t.key}),f?.onFirstSubscribe||f?.onLastUnsubscribe){let e=0;const t=c.subscribe;c.subscribe=(...n)=>{e||f.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||f.onLastUnsubscribe?.()})}}}function k(){y=!0,function(){if(f&&l.length){for(const e of l){const t=r.sessionId;for(const n of e.keys)a.set(n,[e.timestamp,t]);S(e.timestamp,e.keys),f.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values})}l.length=0}}()}function I(){m=!0,function(){if(!u.length)return;const e=u.slice();u.length=0;for(const t of e)F(t)}()}return n?(o.onHydrationComplete=k,o.onHydrationFlushEnd=I):f.onHydrated?(f.onHydrated(k),I()):(k(),I()),q},syncContext:o}}(e,i,o?.async??!1):void 0,c=s?.stateCreator??e;if(!r)return _e(c);const a=function(e,t,n){const r=t??e.storage??P().storage,o=(e.sync?void 0:e.persistThrottleMs??De)||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,o,s?.syncContext),u=a.async?function(e){let t,n,r,o=!1;return{hydrationPromise:()=>o?t?.promise??n??(n=Promise.resolve()):(t||(t=Ce()),t.promise),stateCreator:(n,i,s)=>{let c;return r=()=>{if(c?.length){for(const e of c)N(s.setState,e);c=void 0}},e(function(...e){return o?N(n,e):(t||(t=Ce()),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(k(i)):t?.complete(),s?.(e,i)}}}}(c):void 0,l=u?u.wrapOnRehydrateStorage(t.onRehydrateStorage,s?.syncContext):t.onRehydrateStorage,f=_e(function(e,t){return(n,r,o)=>{let i,s,c,a=Ie(t),u=!1,l=0;function f(){return a.storage.setItem(a.name,r(),a.version)}const d=o.setState;o.setState=function(...e){return N(d,e),f()};const y=e(function(...e){return N(n,e),f()},r,o);function p(){const e=function(){const e=++l;return u=!1,s?.forEach(e=>e(r()??y)),e}(),t=a.onRehydrateStorage?.(r()??y);try{const n=a.storage.getItem(a.name);return ke(n)?n.then(n=>h(e,n,t)).catch(n=>m(e,t,n)):h(e,n,t)}catch(n){m(e,t,n)}}return o.getInitialState=()=>y,Object.assign(o,{persist:{clearStorage:()=>{a.storage.removeItem(a.name)},getOptions:()=>a,hasHydrated:()=>u,onFinishHydration:e=>(c??(c=new Set),c.add(e),()=>{c?.delete(e),0===c?.size&&(c=void 0)}),onHydrate:e=>(s??(s=new Set),s.add(e),()=>{s?.delete(e),0===s?.size&&(s=void 0)}),rehydrate:p,setOptions:e=>{a=Ie({...a,...e,storage:e.storage??a.storage})}}}),a.skipHydration||p(),i??y;function h(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 ke(n)?n.then(e=>({migrated:!0,state:e})):{migrated:!0,state:n}}(a,t);return ke(r)?r.then(t=>g(e,t,n)).catch(t=>m(e,n,t)):g(e,r,n)}function g(e,t,o){const s=function(e,t){if(e!==l)return;const o=a.merge(t.state,r()??y);return i=o,n(o,!0),t.migrated?f():void 0}(e,t);if(ke(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,c?.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)):c,{merge:t.merge,migrate:t.migrate,name:n,onRehydrateStorage:l,storage:a.persistStorage,version:a.version}));return u?Object.assign(f,{persist:Object.assign(f.persist,{hydrationPromise:u.hydrationPromise})}):f}function Ze(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)}(X(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):j(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)ut(t[1],t[0],[],0,i,r);!1!==o?.(i)&&function(e,t,n){for(const n of e){const e=n.invocation?yt(n.path,n.invocation):dt(n.path);t(n.store,e,n.path)}n&&function(e){const t=e.size;console.log(`[π‘ ${t} ${Ze("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}_${Ze("arg",o)})`:"()"}`}),null,2))}(e)}(i,t,n)},reset(){e.clear()},trackPath(t,n,r,o){let i=e.get(t);i||(i={__proto__:null},e.set(t,i)),at(i,n,0,r,o)}}}function at(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(lt(n,t))return;const r=e.extraInvocations;if(r){for(let e=0;e<r.length;e++)if(lt(r[e],t))return;r.push(t)}else e.extraInvocations=[t]}(e,o));e.children||(e.children={__proto__:null});const i=t[n];let s=e.children?.[i];s||(s={__proto__:null},e.children[i]=s),at(s,t,n+1,r,o)}function ut(e,t,n,r,o,i=2){const s=e.children;if(!s)return void ft(e,t,n,o);const c=Object.keys(s),a=c.length;if(0!==a)if(e.isLeaf||r>=i&&a>1){ft(e,t,n,o);for(const e of c){const c=s[e];c.invocation&&ut(c,t,[...n,e],r+1,o,i)}}else if(r<i&&a>1&&!e.isLeaf)for(const e of c)ut(s[e],t,[...n,e],r+1,o,i);else{if(1===a){const e=c[0];return void ut(s[e],t,[...n,e],r+1,o,i)}ft(e,t,n,o)}else ft(e,t,n,o)}function lt(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 ft(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 dt(e){return t=>pt(t,e)}function yt(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 ht=Symbol(),gt=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});function bt(e,t=Object.is){const{debounceOptions:n,debugMode:r,equalityFn:o,keepAlive:i,lockDependencies:s}="function"==typeof(u=t)?{debounceOptions:void 0,debugMode:!1,equalityFn:u,keepAlive:!1,lockDependencies:!1}:{debounceOptions:u.debounce,debugMode:(a&&u.debugMode)??!1,equalityFn:u.equalityFn??Object.is,keepAlive:u.keepAlive??!1,lockDependencies:u.lockDependencies??!1},c=new Set;var u;i&&c.add(mt);const f=new Set;let d,y,p=ht,h=!1,g=!1,b=!0,m=!0,S=0,v=!1,w=null,O=ht;function q(e,t,n){if(!m||!c.size)return(t??l)(e.getState());if(!t)return d||(d=new WeakMap),y||(y=ct()),tt(e,d,y.trackPath);const r=n?{equalityFn:n,isCascadeParticipant:!0}:gt;return f.add(e.subscribe(t,E,r)),t(X(e)?e.getSnapshot():e.getState())}function j(e){for(const t of f)t(e);f.clear()}let F=!0;function _(){if(!b&&St(p))return p;b=!1,m&&j(!0);const t=p,n=St(t);g=!0;try{p=function(t){F=!0;const n=p,i=e(t),s=y?rt(i):i;return St(n)&&o(n,s)?(r&&console.log("[π₯· Derive Complete π₯·]: No change detected"),F=!1,n):s}(q)}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=f.size;console.log(`[π― ${e} ${Ze("Selector Subscription",e)} π―]`)}return y&&m&&(y.buildProxySubscriptions((e,t)=>{f.add(e.subscribe(t,E,gt))},i),d=void 0,y.reset(),s&&(y=void 0)),F&&n&&function(e,t){const n=function(){const e=c.has(mt)?c.size-1:c.size;return S>0&&S<e}(),o=(!S||n)&&(n||null!==me()||be());n&&Se(),r&&console.log(`[π» Derive Complete π»]: Notifying ${c.size} ${Ze("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(o)return St(O)||(O=t),void(v||(v=!0,we(I)));k(e,t)}(p,t),s&&(m=!1),p}function k(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 I(){c.size&&b&&!S&&_();const e=O;v=!1,O=ht,c.size&&St(p)&&St(e)&&k(p,e)}const A=n?Me(z,"number"==typeof n?n:n.delay,"number"==typeof n?{leading:!1,maxWait:n,trailing:!0}:n):void 0,C=A??(()=>{h||(h=!0,queueMicrotask(z))});function z(){h=!1,c.size?b&&_():D()}function T(e){e||A&&b?queueMicrotask(()=>{c.size||D()}):D()}function M(){z(),w=null}function E(){if(!g&&!b){if(b=!0,!A){if(S){Se();const e=me(),t=null===e?0:e+1;if(null!==w&&t<=w)return;return w=t,void function(e,t){if(!ue)return;const n=t<0?0:0|t,r=ye.get(e);if(void 0===r){ye.set(e,n);let t=pe.get(n);return t||(t=new Set,pe.set(n,t)),t.add(e),void(n<ge&&(ge=n))}if(n>r){const t=pe.get(r);if(t&&(t.delete(e),0===t.size&&(pe.delete(r),r===ge))){ge=1/0;for(const e of pe.keys())e<ge&&(ge=e)}ye.set(e,n);let o=pe.get(n);o||(o=new Set,pe.set(n,o)),o.add(e),n<ge&&(ge=n)}}(M,t)}if(be())return void(v||(v=!0,we(I)))}w=null,C()}}function P(e){c.add(mt);try{return e()}finally{c.delete(mt)}}function K(){return be()&&function(){if(ue)if(le)null===he&&qe();else{le=!0;try{qe()}catch(e){throw Fe(),e}finally{le=!1,he=null}}}(),b||!St(p)?c.size>0?_():e(q):p}function D(e=!0){i&&e||(A?.cancel(),j(),c.clear(),S=0,y=void 0,d=void 0,m=!0,h=!1,g=!1,b=!0,p=ht,v=!1,O=ht,w=null)}return{destroy:()=>D(!1),flushUpdates:function(){c.size&&(A?A.flush():b&&_())},getSnapshot:function(){return St(p)?(h&&z(),p):c.size?_():P(_)},getState:K,subscribe:function(...e){if(1===e.length){const t=e[0];return c.add(t),St(p)||K(),()=>{c.delete(t),c.size||T(!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||T(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 mt(){}function St(e){return e!==ht}var vt=class{constructor(e){this.count=0,this.lastSubscriptionTime=null,this.fetchThrottleMs=null,this.onSubscribe=null,this.onLastUnsubscribe=null,e&&(this.fetchThrottleMs=$.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)}}},wt=Symbol("stores.queryParamConfig");function Ot(e,t){return{[wt]:!0,key:t.key,value:e}}function qt(e){return JSON.stringify(Ft(e))}function jt(e){return JSON.parse(e)}function Ft(e){return"object"!=typeof e||null===e?e:Object.keys(e).sort().reduce((t,n)=>{const r=e[n];return t[n]=j(r)?Ft(r):r,t},{__proto__:null})}var _t=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});function kt(e,t,n){const r={__proto__:null};let o=null,i=!1;if(e)for(const n in e){if(!q(e,n))continue;const s=It(r,e[n],n,t);s&&((o??(o=f()))[n]=s,void 0!==s.key&&(i=!0))}return{buildKey:(e=r)=>qt(i?function(e,t){const n={__proto__:null};for(const r in t){if(!q(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}:zt(r),get:()=>zt(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];ce(r,e)||(t[o]=e,n(o,r,e))}))}return r?e=>{for(const t of r)t(e)}:d}(o,r,e)}}function It(e,t,n,r){return(o=t)&&"object"==typeof o&&wt in o?Ct(e,t.value,n,r,t.key):Ct(e,t,n,r);var o}function At(e,t){const n=[];let r,o;function i(e,t=l){return t(Tt(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}:_t}(i))),t(Tt(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,_t))},!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 Ct(e,t,n,r,o){if(function(e){return"function"==typeof e}(t)){const i=At(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 zt(e){const t={__proto__:null};for(const n in e)q(e,n)&&(t[n]=e[n]);return t}function Tt(e){return X(e)?e.getSnapshot():e.getState()}var Mt={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},Et=Object.freeze({force:!0}),Pt=Object.freeze({once:!0}),Kt=new Set,Dt=!1;function xt(e){Kt.add(e),Dt||(Dt=!0,queueMicrotask(()=>{Dt=!1,ae(Rt)}))}function Rt(){for(const e of Kt)Kt.delete(e),e()}function $t(e,t){return n=>{const r={...n},o={__proto__:null};for(const e in r)q(r,e)&&e in Mt&&(Mt[e]&&(o[e]=r[e]),delete r[e]);return{...t?t(r):Ke(r),...Lt(e,null,o)}}}function Lt(e,t,n){if(!n.queryCache)return n;const r=Date.now(),o=t??(e&&n.queryKey||null),i={__proto__:null};let s=!1;for(const e in n.queryCache){if(!q(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 Nt(){return Object.create(null)}function Vt(e,t,n){return new _(`[createQueryStore: ${e}]: ${t} failed`,n)}function Ht(e){return function(...t){return!0===t[1]?e().setState(t[0],!0):e().setState(t[0])}}function Wt(e,t){const n=Ye(e,t);return S(n,n.getState,n.getInitialState,Object.is)}function Jt(e,t=Object.is){const n=bt(e,t);return S(n,n.getSnapshot)}function Ut(e,t,n){const r=function(e,t,n){K();const r="function"==typeof t?t:Nt,o="object"==typeof t?t:n,i=function(e){return"string"==typeof e?.storageKey}(o)?o:void 0,s=x??(x=function(){const e={abortInterruptedFetches:!0,cacheTime:$.days(7),debugMode:!1,disableAutoRefetching:!1,keepPreviousData:!1,maxRetries:5,minStaleTime:!1,paramChangeThrottle:!1,retryDelay:L,staleTime:$.minutes(2),suppressStaleTimeWarning:!1},t=function(){if(A)return A}()?.queryStoreDefaults;return t?{...e,...t}:e}()),c=s.minStaleTime,{fetcher:l,onError:f,onFetched:d,setData:y,transform:p,abortInterruptedFetches:h=s.abortInterruptedFetches,cacheTime:g=s.cacheTime,debugMode:b=s.debugMode,disableAutoRefetching:m=s.disableAutoRefetching,disableCache:S=!1,enabled:v=!0,keepPreviousData:O=s.keepPreviousData,maxRetries:q=s.maxRetries,paramChangeThrottle:j=s.paramChangeThrottle,params:F,retryDelay:I=s.retryDelay,staleTime:C=s.staleTime,suppressStaleTimeWarning:z=s.suppressStaleTimeWarning}=e;let T="function"==typeof C?s.staleTime:C;a&&!1!==c&&!m&&!z&&T<c&&console.warn(`[createQueryStore${i?.storageKey?`: ${i.storageKey}`:""}] β Stale times under ${c/1e3} seconds are not recommended. Provided staleTime: ${T/1e3} seconds`);const M=new Error("[createQueryStore: AbortError] Fetch interrupted"),E="function"==typeof g,P=a&&b,D=e.params?Object.keys(e.params):[];let N,V=!1,H=[],W=null,J=null,B=null,Q=null,G=null,X=null,Y=null;const Z={enabled:"function"!=typeof v&&v,error:null,lastFetchedAt:null,queryCache:{},queryKey:"",status:R.Idle},ee=new vt(m);function te(){B&&(Q=null,B.abort(),B=null)}function ne(){G&&(clearTimeout(G),G=null)}function re(e,t,n){const o=n.setState;function s(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&&Y!==t&&(Y=t,t&&ee.hasSubscribers()?queueMicrotask(()=>a.fetch(void 0,void 0,!0)):(G||h)&&(h&&te(),ne()))}(r.enabled,i)),o});return n?.(),r}return o(e)}function c(e){if(m||T<=0||T===1/0)return;if(!ee.hasSubscribers())return;ne();const n=t();if(!n.enabled)return;const r=N.buildKey(e),o=(S?X===r&&n.lastFetchedAt:n.queryCache[r]?.lastFetchedAt)||null,i=o?T-(Date.now()-o):T;G=setTimeout(()=>{t().enabled&&a.fetch(e,Et,!0)},i)}n.setState=s,ee.init({onSubscribe:(n,r)=>{const o=t();if(o.enabled)if(n){const t=N.get(),n=N.buildKey(t);o.queryKey!==n&&e({queryKey:n}),o.isStale()?a.fetch(t,void 0,!0):c(t)}else m&&!r&&a.fetch(void 0,void 0,!0)},onLastUnsubscribe:e=>{ne(),h&&!e&&te()}});const a={...r(s,t,n),...Z,async fetch(n,r,o=!1){const u=!!r?.skipStoreUpdates,b=t();if(!u){if(!b.enabled&&!r?.force)return null;if(o&&!ee.hasSubscribers())return null}const m=b.error,v=b.queryKey,j=b.status===R.Loading,F=N.complete(n),A=N.buildKey(F);if(j&&Q?.promise&&Q.key===A)return P&&console.log("[π Using Active Fetch π] for params:",JSON.stringify(F)),Q.promise;const C=r?.staleTime??T,z="boolean"==typeof r?.updateQueryKey?r.updateQueryKey:!!o&&O,K=(o||v===A||z)&&!u,x=null!==Q;if(h&&K&&te(),!r?.force){const t=b.lastFetchedAt,n=b.queryCache[A],r=n?.lastFetchedAt,o=n?.errorInfo,i=o&&o.retryCount>=q,s=(S?X===A&&t:r)||null;if(s&&!(Date.now()-s>=C)&&(!o||i||u))return K&&!G&&0!==T&&T!==1/0&&c(F),z&&e(e=>e.queryKey!==A?{queryKey:A}:e),P&&console.log("[πΎ Returning Cached Data πΎ] for params:",JSON.stringify(F)),n?.data??null}const $=K?{key:A}:null,L=r?.cacheTime??(E?g(F):g);async function V(){const b=i?.storageKey||A;try{P&&(!o&&n&&D.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(F).filter(e=>!(e in n)).map(e=>[e,F[e]])))}`):console.log("[π Fetching π] for params:",JSON.stringify(F)));const t=await(h&&K?async function(e){const t=new AbortController;B=t;try{return await new Promise((n,r)=>{t.signal.addEventListener("abort",()=>r(M),Pt),Promise.resolve(l(e,t)).then(n,r)})}finally{B===t&&(B=null)}}(F):l(F,null)),i=Date.now();let f;P&&console.log("[β
Fetch Successful β
] for params:",JSON.stringify(F));try{f=function(e,t,n){return n?n(e,t):e}(t,F,p)}catch(e){throw Vt(b,"transform",e)}if(u)return P&&console.log("[π₯· Successful Parallel Fetch π₯·] for params:",JSON.stringify(F)),"withCache"===r.skipStoreUpdates&&e(e=>{if(!y)return S?e:{queryCache:{...e.queryCache,[A]:{cacheTime:L,data:f,errorInfo:null,lastFetchedAt:i}}};let t=e;const n=t.queryCache[A];try{y({data:f,params:F,queryKey:A,set:e=>{t="function"==typeof e?{...t,...e(t)}:{...t,...e}}})}catch(e){throw Vt(b,"setData",e)}return!S&&Object.is(n,t.queryCache[A])&&(t={...t,queryCache:{...t.queryCache,[A]:{cacheTime:L,data:null,errorInfo:null,lastFetchedAt:i}}}),t}),f;if((y?s:e)(e=>{let t={...e,error:null,lastFetchedAt:i,queryKey:z?A:e.queryKey,status:R.Success};if(y||S){if(y){P&&console.log("[πΎ Setting Data πΎ] for params:",JSON.stringify(F));const e=t.queryCache[A];try{y({data:f,params:F,queryKey:A,set:e=>{t="function"==typeof e?{...t,...e(t)}:{...t,...e}}})}catch(e){throw Vt(b,"setData",e)}!S&&Object.is(e,t.queryCache[A])&&(t.queryCache={...t.queryCache,[A]:{cacheTime:L,data:null,errorInfo:null,lastFetchedAt:i}})}}else P&&console.log("[πΎ Setting Cache πΎ] for params:",JSON.stringify(F),"| Has previous data?:",!!t.queryCache[A]?.data),t.queryCache={...t.queryCache,[A]:{cacheTime:L,data:f,errorInfo:null,lastFetchedAt:i}};return S||g===1/0?t:Lt(O,A,t)}),K&&(X=A,c(F)),d)try{d({data:f,fetch:a.fetch,params:F,set:s})}catch(e){w.error(Vt(b,"onFetched callback",e))}return f??null}catch(n){if(n===M)return P&&console.log("[β Fetch Aborted β] for params:",JSON.stringify(F)),null;const i=!o&&!0===r?.throwOnError,s=k(n);if(s instanceof _&&w.error(s),!K){if(i)throw s;return null}const c=S?void 0:t().queryCache[A],u=c?.errorInfo?.retryCount??0,l=u+1;try{f?.(s,u)}catch(e){w.error(Vt(b,"onError callback",e))}if(u<q){if(t().enabled&&ee.hasSubscribers()){const e="function"==typeof I?I(l,s):I;e!==1/0&&(ne(),G=setTimeout(()=>{t().enabled&&a.fetch(F,Et,!0)},e))}e(e=>({error:s,queryCache:{...e.queryCache,[A]:{cacheTime:c?.cacheTime??L,data:c?.data??null,lastFetchedAt:c?.lastFetchedAt??null,errorInfo:{error:s,lastFailedAt:Date.now(),retryCount:l}}},queryKey:z?A:e.queryKey,status:R.Error}))}else e(e=>({error:s,queryCache:{...e.queryCache,[A]:{cacheTime:c?.cacheTime??L,data:c?.data??null,lastFetchedAt:c?.lastFetchedAt??null,errorInfo:{error:s,lastFailedAt:Date.now(),retryCount:q}}},queryKey:z?A:e.queryKey,status:R.Error}));if(i)throw s;return null}finally{Q===$&&(Q=null)}}return $&&(ne(),z&&!x&&null===b.lastFetchedAt&&v!==A?e({error:null,queryKey:A,status:R.Loading}):!m&&j||e({error:null,status:R.Loading}),Q=$),$?($.promise=V(),$.promise):V()},getCacheEntry(e){if(S)return null;const n=t(),r=e?"string"==typeof e?e:N.buildKey(N.complete(e)):n.queryKey;return n.queryCache[r]??null},getData(e){if(S)return null;const n=t().getCacheEntry(e);return n&&null!==n.data?O?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===R.Idle;case"isLoading":return r===R.Loading;case"isError":case"isInitialLoad":case"isSuccess":case void 0:{const t=n.queryKey,o=n.queryCache[t],i=S?r===R.Error:"number"==typeof o?.errorInfo?.lastFailedAt;if("isError"===e)return i;const s=null!==((S?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===R.Idle,isLoading:r===R.Loading,isInitialLoad:c,isSuccess:a}}}},isDataExpired(e){const n=t(),r=n.queryCache[n.queryKey],o=n.queryKey,i=n.lastFetchedAt,s=(S?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=(S?X===r&&n.lastFetchedAt:n.queryCache[r]?.lastFetchedAt)||null;if(!o)return!0;const i=e??T;return Date.now()-o>=i},reset(t=!1){for(const e of H)e();H=[],N=kt(void 0,oe,D),W=null,J=null,te(),ne(),Q=null,X=null,t&&e(Z)}},u=n.subscribe;return n.subscribe=(...e)=>{const t=V?void 0:ee.subscribe(),n=1===e.length?u(e[0]):u(e[0],e[1],e[2]);return e=>{t?.(e),n()}},a}const oe=i?.storageKey?Ye(re,(ie=i,void 0===(se={partialize:$t(O,i.partialize)})?Object.assign({__proto__:null},ie):Object.assign({__proto__:null},ie,se))):o&&!("storageKey"in o)?Ye(re,o):Ye(re);var ie,se;const ce=oe.getState(),ae=ce.error,ue=ce.enabled,le=ce.queryKey,fe=ce.fetch;le&&!ae&&(X=le),V=!0,N=kt(F,oe,D),"function"==typeof v&&(W=At(v,oe)),"function"==typeof e.staleTime&&(J=At(e.staleTime,oe),T=J.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)},xt);function ye(){if(O)de(void 0);else{const e=N.get();oe.setState({queryKey:N.buildKey(e)}),de(e)}}const pe=u||!j?void 0:Me(ye,"number"==typeof j?j:j.delay,"number"==typeof j?{leading:!1,maxWait:j,trailing:!0}:j);if(H.push(N.subscribe((e,t,n)=>{P&&console.log("[π Param Change π] -",e,"- [Old]:",`${t?.toString()},`,"[New]:",n?.toString()),function(){if(ne(),pe){const e=oe.getState();return void(O&&Q?.key===e.queryKey&&null===e.lastFetchedAt?ye():pe())}ye()}()})),J){let e=J.initialValue;P&&console.log("[π StaleTime Subscription π] Initial value:",e),H.push(J.subscribe(t=>{t!==e&&(P&&console.log("[π StaleTime Change π] - [Old]:",`${e},`,"[New]:",t),e=t,T=t,ne(),fe(void 0,void 0,!0))}))}let he;if(W){let e=W.initialValue;ue!==e&&((he??(he={})).enabled=e),P&&console.log("[π Enabled Subscription π] Initial value:",e),H.push(W.subscribe(t=>{t!==e&&(P&&console.log("[π Enabled Change π] - [Old]:",`${e},`,"[New]:",t),e=t,oe.setState({enabled:t}))}))}else ue!==Z.enabled&&((he??(he={})).enabled=Z.enabled);const ge=N.buildKey();return ge!==le&&((he??(he={})).queryKey=ge),he&&oe.setState(he),V=!1,be=oe,me=U.QueryStore,Object.assign(be,{[me]:!0});var be,me}(e,t,n);return S(r,r.getState,r.getInitialState,Object.is)}function Bt(e,t,n){const r=function(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)&&Se()}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&&ve();for(const e of s)u(e,t,n,r)}(t,e),B(t)}const f=bt(e,{debugMode:i?.debugMode??!1,lockDependencies:i?.lockDependencies??!0});let y;function p(){return y??(y=f.subscribe(l)),f.getState()}const h=Object.assign({[U.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:Ht(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?(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?.(p));var g;return h}(e,t,n);return S(r,r.getState,r.getInitialState)}var Qt=Symbol(),Gt=Object.freeze({debugMode:!1,enabled:!0,equalityFn:Object.is,fireImmediately:!1});function Xt(n,r,o,i=Gt){const s=function(){const e=t(Qt);return e.current===Qt&&(e.current=function(e,t,n){return{selector:e,react:t,isActive:!1,options:en(n),resubscribe:d,unsubscribe:d}}(r,o,i)),e}(),c=function(e){return"function"==typeof e?Gt.enabled:e?.enabled??Gt.enabled}(i);return s.current.react=o,s.current.selector=r,function(e,t){"function"==typeof t?e.current.options.equalityFn=t:t&&(e.current.options=t??Gt)}(s,i),e(()=>{if(c)return Zt(n,s),()=>function(e){e.current.options.debugMode&&console.log("[ποΈ useListen ποΈ] Detaching listener"),e.current.resubscribe=d,e.current.unsubscribe(),e.current.unsubscribe=d,e.current.isActive=!1}(s)},[c,n]),s}var Yt=Object.freeze({fireImmediately:!1,forceResubscribe:!1});function Zt(e,t,n=Yt){if(t.current.isActive){if(!n?.forceResubscribe)return;t.current.unsubscribe()}t.current.options.debugMode&&console.log("[π‘ useListen π‘] Attaching listener"),t.current.isActive=!0,t.current.resubscribe=(n=Yt)=>Zt(e,t,n);const r=e.subscribe(e=>t.current.selector(e),(e,n)=>t.current.react(e,n,()=>{r(),t.current.isActive=!1}),n.fireImmediately?{...t.current.options,fireImmediately:!0}:t.current.options);t.current.unsubscribe=()=>{t.current.isActive&&(r(),t.current.isActive=!1)}}function en(e){return"function"==typeof e?{equalityFn:e}:e??Gt}var tn=Symbol();function nn(e){const n=t(tn);return n.current===tn&&(n.current=e()),n.current}export{R as QueryStatuses,_ as StoresError,V as applyStateUpdate,E as configureStores,Wt as createBaseStore,Jt as createDerivedStore,Ut as createQueryStore,ne as createStoreActions,Bt as createVirtualStore,ie as deepEqual,L as defaultRetryDelay,B as destroyStore,Q as destroyStores,qt as getQueryKey,G as getStoreName,X as hasGetSnapshot,l as identity,Z as isDerivedStore,ee as isPersistedStore,Y as isQueryStore,te as isVirtualStore,f as nullObject,jt as parseQueryKey,Ot as queryParam,W as replacer,J as reviver,se as shallowEqual,$ as time,Xt as useListen,nn as useStableValue};
|
|
1
|
+
import{createRequire as e}from"node:module";import{useDebugValue as t,useLayoutEffect as n,useRef as r,useSyncExternalStore as i}from"react";import{Platform as a,unstable_batchedUpdates as o}from"react-native";var s=e(import.meta.url);const c=a.OS===`ios`;a.OS;const l=process.env.NODE_ENV===`development`,u=process.env.NODE_ENV===`test`;Object.freeze(Object.create(null));function d(e){return e}function f(){return{__proto__:null}}function p(e,t){return t===void 0?Object.assign(f(),e):Object.assign(f(),e,t)}function m(){}function h(e,t,n){e(t,n)}const g=Symbol(`empty selection`),_=Object.is;function v(e,n,a,o,s=_){let c=r(null),l=e,u=n,d=a;if(o){let t=c.current;t===null&&(t=y(e,n,a,o,s),c.current=t),b(t,e,n,a,o,s),l=t.selectedSubscribe,u=t.getSelectedSnapshot,d=a===void 0?void 0:t.getSelectedServerSnapshot}let f=i(l,u,d);return t(f),f}function y(e,t,n,r,i){let a={committedEqualityFn:i,committedSelector:r,committedSource:e,committedValue:g,equalityFn:i,getSelectedServerSnapshot:()=>C(a),getSelectedSnapshot:()=>S(a),getServerStoreSnapshot:n,getStoreSnapshot:t,selector:r,selectedSource:e,selectedSubscribe:()=>m,source:e,value:g,valueEqualityFn:i,valueSelector:r,valueSnapshot:g};return a.selectedSubscribe=x(a,e),a}function b(e,t,n,r,i,a){e.source=t,e.getStoreSnapshot=n,e.getServerStoreSnapshot=r,e.selector=i,e.equalityFn=a,e.selectedSource!==t&&(e.selectedSource=t,e.selectedSubscribe=x(e,t))}function x(e,t){return n=>(E(e),t(r=>{let i=e.committedValue;if(i===g||e.committedSource!==t){n();return}let a=e.committedSelector,o=e.committedEqualityFn;if(e.selector===a&&e.equalityFn===o){let t=a(r);if(o===_?_(i,t):o(i,t))return;e.committedValue=t,e.value=t,e.valueEqualityFn=o,e.valueSelector=a,e.valueSnapshot=r,n();return}if(e.source!==t){n();return}let s=e.value;if(s===g)return;let c=e.selector(r),l=e.equalityFn(s,c);e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedValue=T(e,r,l?s:c),l||n()}))}function S(e){return w(e,e.getStoreSnapshot())}function C(e){return w(e,(e.getServerStoreSnapshot??e.getStoreSnapshot)())}function w(e,t){let n=e.value;if(n!==g&&_(e.valueSnapshot,t)&&e.valueSelector===e.selector&&e.valueEqualityFn===e.equalityFn)return n;let r=e.selector(t);if(n!==g&&(e.equalityFn===_?_(n,r):e.equalityFn(n,r)))return T(e,t,n);let i=e.committedValue;return i!==g&&i!==n&&e.committedSource===e.source&&(e.equalityFn===_?_(i,r):e.equalityFn(i,r))?T(e,t,i):T(e,t,r)}function T(e,t,n){return e.value=n,e.valueEqualityFn=e.equalityFn,e.valueSelector=e.selector,e.valueSnapshot=t,n}function E(e){e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedSource=e.source,e.committedValue=e.value===g?S(e):e.value}function D(e,t,n,r){let i=e.subscribe;function a(e,a){return v(i,t,n,e,a??r)}return Object.assign(a,e)}function O(e){let t;function n(){if(t)return t;try{let n=k(e),r;if(typeof n.delete==`function`?r=n.delete.bind(n):typeof n.remove==`function`&&(r=n.remove.bind(n)),typeof r!=`function`)throw Error(`[stores]: Storage instance does not conform to expected interface`);t={clearAll:n.clearAll.bind(n),contains:n.contains.bind(n),delete:r,get:n.getString.bind(n),getAllKeys:n.getAllKeys.bind(n),set:n.set.bind(n)}}catch(e){throw Error(`[stores] react-native-mmkv could not be loaded.
|
|
2
|
+
|
|
3
|
+
Persisted stores require a storage backend. Either:
|
|
4
|
+
- Install MMKV (the default): yarn add react-native-mmkv
|
|
5
|
+
- Or provide a custom adapter via configureStores()
|
|
6
|
+
`+(e instanceof Error?`\n${e.message}`:``))}return A(t),t}return{clearAll:()=>n().clearAll(),contains:e=>n().contains(e),delete:e=>n().delete(e),get:e=>n().get(e),getAllKeys:()=>n().getAllKeys(),set:(e,t)=>n().set(e,t)}}function k(e){let{createMMKV:t,MMKV:n}=s(`react-native-mmkv`);if(typeof t==`function`)return t({id:e});if(typeof n==`function`)return new n({id:e});throw Error(`[stores]: react-native-mmkv module does not export MMKV/createMMKV.`)}function A(e){if(!e||typeof e.get!=`function`||typeof e.set!=`function`||typeof e.delete!=`function`||typeof e.clearAll!=`function`)throw Error(`[stores]: Storage instance does not conform to expected interface`)}let j={debug:(e,t)=>{l&&console.debug(e,t)},error:(e,t)=>{l&&!u&&console.error(e,t)},info:(e,t)=>{l&&console.info(e,t)},warn:(e,t)=>{l&&console.warn(e,t)}};function ee(e){j=e}const M=Object.prototype.hasOwnProperty;function N(e,t){return M.call(e,t)}function P(e){let t=e.charCodeAt(0);if(t<48||t>57)return!1;let n=Number(e);return Number.isInteger(n)&&n<4294967295&&String(n)===e}function F(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function I(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var L=class extends Error{constructor(e,t){super(e),this.name=`StoresError`,t!==void 0&&Object.defineProperty(this,"cause",{configurable:!0,value:t,writable:!0})}};function te(e){return e instanceof Error?e:Error(String(e))}var R=class{destroy(){}publish(){}},z=class{constructor(){this.sessionId=`noop`}register(e){return new R}};let B;function V(){return B||(B=new z),B}let H,U,ne=!1;function re(e){l&&se(),e.logger&&ee(e.logger),H??(H=G(e)),U??(U=oe(e))}function W(){if(H)return H}function ie(){return U??(U=oe(void 0))}function ae(){ne=!0}function G(e){if(e?.queryStoreDefaults)return{queryStoreDefaults:e.queryStoreDefaults}}function oe(e){return{storage:e?.storage??O(e?.storageKeyPrefix??`stores:`),syncEngine:e?.syncEngine??V()}}function se(){if(ne)throw Error(`[stores]: configureStores() called after first store creation. Call it earlier before creating any stores.`)}const K={Error:`error`,Idle:`idle`,Loading:`loading`,Success:`success`},q={ms:e=>{"worklet";return e},seconds:e=>{"worklet";return e*1e3},minutes:e=>{"worklet";return e*6e4},hours:e=>{"worklet";return e*36e5},days:e=>{"worklet";return e*864e5},weeks:e=>{"worklet";return e*6048e5},infinity:1/0,zero:0};let ce;function le(){return ce??(ce=ue())}function ue(){let e=W()?.queryStoreDefaults;return{abortInterruptedFetches:e?.abortInterruptedFetches??!0,cacheTime:e?.cacheTime??q.days(7),debugMode:e?.debugMode??!1,disableAutoRefetching:e?.disableAutoRefetching??!1,keepPreviousData:e?.keepPreviousData??!1,minStaleTime:e?.minStaleTime??!1,onError:e?.onError,paramChangeThrottle:e?.paramChangeThrottle??!1,retry:e?.retry??5,retryDelay:e?.retryDelay,staleTime:e?.staleTime??q.minutes(2),suppressStaleTimeWarning:e?.suppressStaleTimeWarning??!1}}function de(e,t){let n=t?.baseDelay??q.seconds(5),r=t?.maxDelay??q.minutes(5);return Math.min(n*2**e,r)}function fe(e,t){return t[1]===!0?e(t[0],!0):e(t[0])}function pe(e,t,n){if(n===!0)return me(t)?t(e):t;let r=me(t)?t(e):t;return Object.is(r,e)?e:!I(e)||!I(r)?r:{...e,...r}}function me(e){return typeof e==`function`}function he(e){return typeof e==`object`&&!!e&&`__type`in e&&e.__type===`Map`}function ge(e){return typeof e==`object`&&!!e&&`__type`in e&&e.__type===`Set`}function _e(e,t){return t instanceof Map?{__type:`Map`,entries:Array.from(t.entries())}:t instanceof Set?{__type:`Set`,values:Array.from(t)}:t}function ve(e,t){return he(t)?new Map(t.entries):ge(t)?new Set(t.values):t}const ye=Object.freeze({QueryStore:Symbol(`queryStore`),VirtualStore:Symbol(`virtualStore`)});function be(e,t){return Object.assign(e,{[t]:!0})}function J(e,t){Ee(e)?e.getState().reset(t?.clearQueryCache):we(e)&&e.destroy()}function xe(e,t){for(let n of Array.isArray(e)?e:Object.values(e))!n||t?.skipDestroy?.(n)||J(n,t)}function Se(e){let t=Ce(e);return Oe(e)?e.persist.getOptions().name??t:t}function Ce(e){return typeof e==`function`?e.name:``}function we(e){return`destroy`in e}function Te(e){return`getSnapshot`in e}function Ee(e){return ye.QueryStore in e}function De(e){return`flushUpdates`in e}function Oe(e){return!(`persist`in e)||!e.persist?!1:typeof e.persist.getOptions().name==`string`}function ke(e){return ye.VirtualStore in e}function Ae(e,t){let n=je(e);return t?Object.assign(n,t):n}function je(e){let t=e.getState(),n=f(),r=n;if(l&&!(typeof t==`object`&&t))throw Error(`[createStoreActions]: State is not an object`);if(ke(e))for(let n in t)Ne(t,n)&&(r[n]=Me(e,n));else for(let e in t)Ne(t,e)&&(r[e]=t[e]);return n}function Me(e,t){return function(...n){let r=e.getState()[t];if(typeof r==`function`)return r(...n);throw Error(`[createVirtualStoreAction]: Method ${String(t)} is not a function`)}}function Ne(e,t){return typeof e[t]==`function`}function Pe(e,t){"worklet";if(typeof e!=`object`||!e||e===void 0||typeof t!=`object`||!t||t===void 0)return e===t;if(Object.is(e,t))return!0;let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let r of n)if(!(r in t)||!Pe(e[r],t[r]))return!1;return!0}function Fe(e,t){"worklet";if(typeof e!=`object`||!e||e===void 0||typeof t!=`object`||!t||t===void 0)return e===t;if(Object.is(e,t))return!0;let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let r of n)if(!Object.is(e[r],t[r]))return!1;return!0}function Ie(e,t){let n=Object.prototype.hasOwnProperty;function r(e,t){for(let n of e.keys())if(Ie(n,t))return n}let i,a,o;if(e===t)return!0;if(e&&t&&(i=e.constructor)===t.constructor){if(i===Date)return e.getTime()===t.getTime();if(i===RegExp)return e.toString()===t.toString();if(i===Array){if((a=e.length)===t.length)for(;a--&&Ie(e[a],t[a]););return a===-1}if(i===Set){if(e.size!==t.size)return!1;for(let n of e)if(o=n,o&&typeof o==`object`&&(o=r(t,o),!o)||!t.has(o))return!1;return!0}if(i===Map){if(e.size!==t.size)return!1;for(let n of e)if(o=n[0],o&&typeof o==`object`&&(o=r(t,o),!o)||!Ie(n[1],t.get(o)))return!1;return!0}if(i===ArrayBuffer)e=new Uint8Array(e),t=new Uint8Array(t);else if(i===DataView){if((a=e.byteLength)===t.byteLength)for(;a--&&e.getInt8(a)===t.getInt8(a););return a===-1}if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(t)){let n=e,r=t;if((a=n.byteLength)===r.byteLength)for(;a--&&n[a]===r[a];);return a===-1}if(!i||typeof e==`object`){a=0;for(let r in e)if(n.call(e,r)&&++a&&!n.call(t,r)||!(r in t)||!Ie(e[r],t[r]))return!1;return Object.keys(t).length===a}}return e!==e&&t!==t}function Le(e,t,n){if(t===0)return n;if(t===1){if(e===n)return null;let t=new Set;return t.add(e),t.add(n),t}return e.add(n),e.size===t?null:e}function Re(e,t,n){if(t===0)return null;if(t===1)return e===n?void 0:null;if(!e.delete(n))return null;if(t!==2)return e;for(let t of e)return t}function ze(e,t,n,r,i){if(t!==0){if(t===1){n(e,r,i);return}for(let t of e)n(t,r,i)}}function Be(e,t){t>1&&e.clear()}const Ve=o;let Y=!1,He=!1,Ue=!1,X,We,Ge=0;const Ke=new Map;let qe=0,Je=null,Z=1/0;function Ye(){return Y}function Xe(){return Je}function Ze(){Y||(Y=!0,!Ue&&(Ue=!0,queueMicrotask(()=>{Ue=!1,Qe()})))}function Qe(){if(Y){if(He){nt();return}He=!0;try{Ve(nt)}finally{ot()}}}function $e(){if(Y){if(He){Je===null&&rt();return}He=!0;try{rt()}catch(e){throw ot(),e}finally{He=!1,Je=null}}}function et(e){if(Y){if(We){We.push(e);return}if(!X){X=e;return}We=[X,e],X=void 0}}function tt(e,t){if(!Y)return;let n=t<0?0:t|0,r=Ke.get(n);r||(r=[],Ke.set(n,r)),r.push(e),qe+=1,n<Z&&(Z=n)}function nt(){for(;qe>0||st();)rt(),at()}function rt(){for(;qe>0;){let e=Z,t=Ke.get(e);if(!t){Z=1/0;for(let e of Ke.keys())e<Z&&(Z=e);continue}Ke.delete(e),qe-=t.length,it(),Je=e;for(let e=0;e<t.length;e++)t[e]();Je=null}}function it(){Z=1/0;for(let e of Ke.keys())e<Z&&(Z=e)}function at(){for(;;){let e=X;if(e){X=void 0,e();continue}let t=We;if(!t)return;for(;Ge<t.length;)t[Ge++]();We=void 0,Ge=0;return}}function ot(){Y=!1,He=!1,Je=null,X=void 0,We=void 0,Ge=0,Ke.clear(),qe=0,Z=1/0}function st(){return!!X||!!We}const Q=Symbol(`stores.subscribeCascadeState`);function ct(e){return Q in e}function lt(e,t){ct(e)&&(e[Q]=t(e[Q]))}const ut=Symbol(),dt=Symbol();function ft(e){let t,n,r,i=0;function a(e,a,o){let s=pe(t,e,a);if(Object.is(s,t))return o===ut?dt:void 0;let c=t;if(t=s,ze(r,i,h,t,c),n){Qe();for(let e of n)e(t,c)}}function o(){return t}function s(){return u}function c(e,t,n){return t?g(e,t,n):d(e)}let l={[Q]:p,getInitialState:s,getState:o,setState:a,subscribe:c},u=t=pt(e)?e(a,o,l):e;return l;function d(e){return(n??(n=new Set)).add(e),()=>{n?.delete(e),n?.size===0&&(n=void 0)}}function f(e){let t=Le(r,i,e);return t!==null&&(r=t,i+=1),()=>m(e)}function p(e){function t(t,n){Ze(),e(t,n)}return f(t)}function m(e){let t=Re(r,i,e);t!==null&&(r=t,--i)}function g(e,n,r){let i=r?.equalityFn??Object.is,a=r?.isCascadeParticipant??!1,o=e(t);function s(t){let r=e(t);if(i(o,r))return;let s=o;o=r,a&&Ze(),n(r,s)}return r?.fireImmediately&&n(o,o),a?f(s):d(s)}}function pt(e){return typeof e==`function`}function mt(e){return!!e&&typeof e==`object`&&`then`in e&&typeof e.then==`function`}const ht=Object.freeze({migrated:!1,state:void 0});function gt(e,t,n){return(r,i,a)=>{let o=vt(t),s,c=!1,l=0,u,d,f;function p(e){return o.storage.setItem(o.name,e,o.version)}function m(e,t){return(t===!0?r(e,t,ut):r(e,!1,ut))===dt?n?s??(s=Promise.resolve()):void 0:p(i())}a.setState=m;let h=e(m,i,a);a.getInitialState=()=>h;function g(){let e=x(),t=o.onRehydrateStorage?.(i()??h);try{let n=o.storage.getItem(o.name);return mt(n)?n.then(n=>_(e,n,t)).catch(n=>C(e,t,n)):_(e,n,t)}catch(n){C(e,t,n)}}return Object.assign(a,{persist:b()}),o.skipHydration||g(),u??h;function _(e,t,n){let r=_t(o,t);return mt(r)?r.then(t=>v(e,t,n)).catch(t=>C(e,n,t)):v(e,r,n)}function v(e,t,n){let r=y(e,t);if(mt(r))return r.then(()=>S(e,n));S(e,n)}function y(e,t){if(e!==l)return;let n=o.merge(t.state,i()??h);if(u=n,r(n,!0),t.migrated)return p(i())}function b(){return{clearStorage:()=>{o.storage.removeItem(o.name)},getOptions:()=>o,hasHydrated:()=>c,onFinishHydration:e=>(f??(f=new Set),f.add(e),()=>{f?.delete(e),f?.size===0&&(f=void 0)}),onHydrate:e=>(d??(d=new Set),d.add(e),()=>{d?.delete(e),d?.size===0&&(d=void 0)}),rehydrate:g,setOptions:e=>{o=vt({...o,...e,storage:e.storage??o.storage})}}}function x(){let e=++l;return c=!1,d?.forEach(e=>e(i()??h)),e}function S(e,t){if(e!==l)return;t?.(u,void 0);let n=i();u=n,c=!0,f?.forEach(e=>e(n))}function C(e,t,n){e===l&&t?.(void 0,n)}}}function _t(e,t){if(!t)return ht;if(typeof t.version!=`number`||t.version===e.version)return{migrated:!1,state:t.state};if(!e.migrate)return console.error(`State loaded from storage couldn't be migrated since no migrate function was provided`),ht;let n=e.migrate(t.state,t.version);return mt(n)?n.then(e=>({migrated:!0,state:e})):{migrated:!0,state:n}}function vt(e){return{...e,merge:e.merge??yt,skipHydration:e.skipHydration??!1}}function yt(e,t){return e===void 0?t:{...t,...e}}function bt(){let e=!1,t,n,r=new Promise((e,r)=>{t=e,n=r});function i(){e||!t||(e=!0,t(),t=void 0,n=void 0)}function a(r){e||!n||(e=!0,n(r),n=void 0,t=void 0)}function o(){return e}return{complete:i,isHydrated:o,fail:a,promise:r}}function xt(e){let t,n=!1,r,i;return{hydrationPromise:()=>n?t?.promise??r??(r=Promise.resolve()):(t||(t=bt()),t.promise),stateCreator:(r,a,o)=>{let s;function c(...e){return n?fe(r,e):(t||(t=bt()),s||(s=[]),s.push(e),t.promise)}return i=()=>{if(s?.length){for(let e of s)fe(o.setState,e);s=void 0}},e(c,a,o)},wrapOnRehydrateStorage:(e,r)=>a=>{let o=e?.(a);return(e,a)=>{n=!0,r?.onHydrationComplete?.(),i&&i(),r?.onHydrationFlushEnd?.(),a?t?.fail(te(a)):t?.complete(),o?.(e,a)}}}}function St(e){let t,n=null;function r(...r){return t=r,n||(n=new Promise(r=>{queueMicrotask(async()=>{try{await e(...t)}finally{n=null,r()}})})),n}return r}const Ct=Math.max,wt=Math.min;function Tt(e,t=0,n={}){let r,i,a,o,s,c,l=0,u=!1,d=!1,f=!0;if(typeof e!=`function`)throw TypeError(`Expected a function`);t=Dt(t)||0,Ot(n)&&(u=!!n.leading,d=`maxWait`in n,a=d?Ct(Dt(n.maxWait)||0,t):void 0,f=`trailing`in n?!!n.trailing:f);function p(t){let n=r,a=i;return r=i=void 0,l=t,o=n?e.apply(a,n):e.apply(a),o}function m(e){return l=e,s=setTimeout(_,t),u?p(e):o}function h(e){let n=e-(c??0),r=e-l,i=t-n;return d&&a!==void 0?wt(i,a-r):i}function g(e){let n=e-(c??0),r=e-l;return c===void 0||n>=t||n<0||d&&a!==void 0&&r>=a}function _(){let e=Et();if(g(e))return v(e);s=setTimeout(_,h(e))}function v(e){return s=void 0,f&&r?p(e):(r=i=void 0,o)}function y(){s!==void 0&&clearTimeout(s),l=0,r=c=i=s=void 0}function b(){return s===void 0?o:v(Et())}function x(...e){let n=Et(),a=g(n);if(r=e,i=this,c=n,a){if(s===void 0)return m(c);if(d)return clearTimeout(s),s=setTimeout(_,t),p(c)}return s===void 0&&(s=setTimeout(_,t)),o}return x.cancel=y,x.flush=b,x}function Et(){return typeof performance<`u`&&typeof performance.now==`function`?performance.now():Date.now()}function Dt(e){if(typeof e==`number`)return e;if(typeof e==`symbol`||e===void 0)return NaN;if(typeof e==`object`&&e){let t=typeof e.valueOf==`function`?e.valueOf():e;e=typeof t==`object`?t+``:t}return typeof e==`string`?(e=e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,``),/^0b[01]+$/i.test(e)?parseInt(e.slice(2),2):/^0o[0-7]+$/i.test(e)?parseInt(e.slice(2),8):/^[-+]0x[0-9a-f]+$/i.test(e)?NaN:+e):e===0?e:+e}function Ot(e){let t=typeof e;return e!==null&&(t===`object`||t===`function`)}function kt(e){if(!F(e))return e;let t=f(),n=Object.keys(e);for(let r=0;r<n.length;r++){let i=n[r],a=e[i];typeof a!=`function`&&(t[i]=a)}return t}function At(e,t){try{return JSON.stringify(e,t?_e:void 0)}catch(e){throw j.error(new L(`[createBaseStore]: Failed to serialize store data`,e)),e}}function jt(e,t){try{return JSON.parse(e,t?ve:void 0)}catch(e){throw j.error(new L(`[createBaseStore]: Failed to deserialize persisted store data`,e)),e}}const Mt=u?0:c?q.seconds(3):q.seconds(5);function Nt(e,t,n){let r=t??e.storage??ie().storage,i=(e.sync?void 0:e.persistThrottleMs??Mt)||void 0,a=e.version??0;return r.async?{async:!0,persistStorage:Ft(r,e,i,n),version:a}:{async:!1,persistStorage:Pt(r,e,i,n),version:a}}function Pt(e,t,n,r){let i=!t.deserializer&&!t.serializer&&!e.deserializer&&!e.serializer,a=typeof t.sync==`object`&&(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata)===!0,o=t.partialize??kt,s=t.deserializer??e.deserializer??It(i),c=t.serializer??e.serializer??Lt(i);function l(t,n,i){try{if(Ht(r))return;let s={state:o(n),version:i},l=zt(r,a,s),u=c(s);try{e.set(t,u),Bt(r,l)}catch(e){j.error(new L(`[createBaseStore]: Failed to persist store data`,e))}}catch(e){j.error(new L(`[createBaseStore]: Failed to persist store data`,e))}}let u=n===void 0?l:Tt(l,n,{leading:!1,maxWait:n,trailing:!0});return{getItem:t=>{let n=e.get(t);return n===void 0?null:s(n)},setItem:(e,t,n)=>{r?.getIsApplyingRemote()||u(e,t,n)},removeItem:t=>{try{e.delete(t)}catch(e){j.error(new L(`[createBaseStore]: Failed to delete persisted store data`,e))}}}}function Ft(e,t,n,r){let i=!t.deserializer&&!t.serializer&&!e.deserializer&&!e.serializer,a=typeof t.sync==`object`&&(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata)===!0,o=t.partialize??kt,s=t.deserializer??e.deserializer??It(i),c=t.serializer??e.serializer??Lt(i);async function l(t,n,i){try{if(Ht(r))return;let s={state:o(n),version:i},l=zt(r,a,s),u=c(s);try{await e.set(t,u),Bt(r,l)}catch(e){j.error(new L(`[createBaseStore]: Failed to persist store data`,e))}}catch(e){j.error(new L(`[createBaseStore]: Failed to serialize persisted store data`,e))}}let u=n===void 0?St(l):Tt(l,n,{leading:!1,maxWait:n,trailing:!0});return{getItem:async t=>{let n=await e.get(t);return n===void 0?null:s(n)},setItem:async(e,t,n)=>{if(!r?.getIsApplyingRemote())return await u(e,t,n)},removeItem:async t=>{try{await e.delete(t)}catch(e){j.error(new L(`[createBaseStore]: Failed to delete persisted store data`,e))}}}}function It(e){return t=>{if(typeof t!=`string`)throw new L(`[createBaseStore]: Received non-string serialized state without a custom deserializer. Provide a deserializer on the store or storage adapter.`);return jt(t,e)}}function Lt(e){return t=>At(t,e)}const Rt=Object.freeze({shouldClear:!1});function zt(e,t,n){if(!t||!e)return Rt;let r=e.getFieldTimestampSnapshot();return Vt(e,n),n.syncMetadata?r&&Object.keys(r).length>0?(n.syncMetadata.fields=r,{fieldSnapshot:r,shouldClear:!0}):(delete n.syncMetadata.fields,{fieldSnapshot:r,shouldClear:!1}):{fieldSnapshot:r,shouldClear:!1}}function Bt(e,t){!e||!t.shouldClear||!t.fieldSnapshot||!Object.keys(t.fieldSnapshot).length||e.clearFieldTimestamps(t.fieldSnapshot)}function Vt(e,t){let n=e.getSessionId(),r=e.getTimestamp();n!==void 0&&r!==void 0&&(t.syncMetadata={origin:n,timestamp:r})}function Ht(e){return e?!!e.getIsApplyingRemote():!1}function Ut(e,t,n){let r=t.engine??ie().syncEngine;return(i,a,o)=>{let s=new Map,c=[],l=[],u=null,d=!1,p=!1,m=0,h=null,g=[],_=Promise.resolve(),v=!n?.isAsync;function y(){let e=Date.now(),t=e>m?e:m+1;return m=t,t}function b(e,t){if(!(!n||!r.sessionId)&&(n.setSessionId(r.sessionId),n.setTimestamp(e),t.length>0)){let r=f();for(let n of t)r[String(n)]=e;n.mergeFieldTimestamps(r)}}function x(e,t,n,i=!1){let a=r.sessionId;for(let t of e)s.set(t,[n,a]);!u||!p?l.push({keys:e,replace:i,timestamp:n,values:t}):u.publish?.({replace:i,sessionId:a,timestamp:n,values:t})}function S(){if(!(!u||!l.length)){for(let e of l){let t=r.sessionId;for(let n of e.keys)s.set(n,[e.timestamp,t]);b(e.timestamp,e.keys),u.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values})}l.length=0}}function C(e,t){if(d||!h)return t?i(e,t):i(e);let n=y(),r,a,o=t?i(s,!0):i(s);if(!r||!a)return o;function s(i){let o=pe(i,e,t);for(let e of g)Object.is(o[e],i[e])||((r??(r=[])).push(e),(a??(a=f()))[e]=o[e]);return r&&b(n,r),o}return mt(o)?o.finally(x.bind(void 0,r,a,n,t)):(x(r,a,n,t),o)}let w=o.setState;o.setState=C;let T=e(C,a,o);if(g=t.fields??Kt(T),!g.length)return T;h=new Set(g);async function E(e){m=Math.max(m,e.timestamp);let r=f(),i=a(),o=e.timestamp,c;if(e.replace)for(let t of g)N(e.values,t)||Gt(s.get(t),o,e.sessionId)&&(c??(c=[])).push(t);for(let n of g){if(!Yt(e.values,n)||!h?.has(n)||!Gt(s.get(n),o,e.sessionId))continue;let a=t.merge?.[n];if(a){let t=e.values[n],c=i[n];if(t!==void 0){let l=a(t,c,i,e.values),u=c===void 0?t:c;if(!Jt(l,u)){j.error(new L(`[sync] Merge function for field "${String(n)}" returned ${qt(l)} but expected ${qt(u)}`));return}r[n]=l,s.set(n,[o,e.sessionId])}}else r[n]=e.values[n],s.set(n,[o,e.sessionId])}if(!(!(Object.keys(r).length>0)&&!c?.length)){d=!0,n?.setIsApplyingRemote(!0);try{if(e.replace){let e={...i},t=!1;if(c?.length){t=!0;for(let t of c)delete e[t],s.delete(t)}for(let n in r){if(!N(r,n))continue;let i=r[n];if(i===void 0)continue;Object.is(e[n],i)||(t=!0);let a=e;a[n]=i}if(!t)return;await(n?.setWithoutPersist??w)(e,!0)}else await(n?.setWithoutPersist??w)(r)}finally{d=!1,n?.setIsApplyingRemote(!1)}}}function D(e){n?.isAsync?_=_.then(()=>E(e)):E(e)}function O(){if(!c.length)return;let e=c.slice();c.length=0;for(let t of e)D(t)}if(u=r.register({apply:e=>{if(!v){c.push(e);return}D(e)},fields:g,getState:a,key:t.key}),u?.onFirstSubscribe||u?.onLastUnsubscribe){let e=u,t=0,n=o.subscribe;function r(n){return t++===0&&e.onFirstSubscribe?.(),r=>{n(r),--t,t||queueMicrotask(()=>{t||e.onLastUnsubscribe?.()})}}o.subscribe=(...e)=>r(e.length===1?n(e[0]):n(e[0],e[1],e[2])),lt(o,e=>t=>r(e(t)))}function k(){p=!0,S()}function A(){v=!0,O()}return n?.isAsync?(n.onHydrationComplete=k,n.onHydrationFlushEnd=A):u.onHydrated?(u.onHydrated(k),A()):(k(),A()),T}}function Wt(e){let t,n,r,i=!1;function a(e){if(!(!e||!r)){for(let t of Object.entries(e)){let e=t[0],n=t[1];r[e]===n&&delete r[e]}Object.keys(r).length||(r=void 0)}}function o(){if(r)return{...r}}function s(e){if(!r){r={...e};return}for(let t of Object.entries(e)){let e=t[0],n=t[1],i=r[e];(i===void 0||n>i)&&(r[e]=n)}}return{isAsync:e,clearFieldTimestamps:a,getFieldTimestampSnapshot:o,getIsApplyingRemote:()=>i,getSessionId:()=>t,getTimestamp:()=>n,mergeFieldTimestamps:s,onHydrationComplete:void 0,onHydrationFlushEnd:void 0,setIsApplyingRemote:e=>i=e,setSessionId:e=>t=e,setTimestamp:e=>n=e,setWithoutPersist:void 0}}function Gt(e,t,n){if(!e)return!0;let r=e[0],i=e[1];return t<r?!1:t>r?!0:n>i}function Kt(e){let t=[];for(let n of Object.keys(e))Xt(e,n)&&t.push(n);return t}function qt(e){if(e===null)return`null`;let t=typeof e;return t===`object`?Object.prototype.toString.call(e):t}function Jt(e,t){if(!l)return!0;if(e===null||t===null)return e===t;let n=typeof e;return n===typeof t?n===`object`?Object.prototype.toString.call(e)===Object.prototype.toString.call(t):!0:!1}function Yt(e,t){return N(e,t)}function Xt(e,t){return typeof e[t]!=`function`}function Zt(e,t){if(ae(),!t)return ft(e);let n=t.storageKey,r=typeof n==`string`,i=r?t.storage??ie().storage:void 0,a=Qt(t.sync,n),o=!i||!a?void 0:Wt(i.async??!1),s=a?Ut(e,a,o):e;if(!r)return ft(s);let c=Nt(t,i,o),l=c.async?xt(s):void 0,u=l?l.wrapOnRehydrateStorage(t.onRehydrateStorage,o):t.onRehydrateStorage,d=ft(gt(l?(e,t,n)=>(o&&(o.setWithoutPersist=n.setState),l.stateCreator(e,t,n)):s,{merge:t.merge,migrate:t.migrate,name:n,onRehydrateStorage:u,storage:c.persistStorage,version:c.version},c.async));return l?Object.assign(d,{persist:Object.assign(d.persist,{hydrationPromise:l.hydrationPromise})}):d}function Qt(e,t){if(!e)return null;let n=typeof e==`object`,r=n?e.key??t:e===!0?t:e;if(!r)throw new L(`[createBaseStore]: sync requires a key to be specified either directly or via storageKey`);return n?{...e,key:r}:{key:r}}function $t(e,t,n=`s`){return t===1?e:`${e}${n}`}const en=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});var tn=class{constructor(e){this.invalidate=e,this.stateDependencyRevisionStamp=0,this.stateDependencyRevision=0}beginRebuild(e){this.clearSelectors(e),this.stateDependencyRevision+=1}addSelector(e){let t=this.selectorUnsubscribes;if(!t){this.selectorUnsubscribes=e;return}if(typeof t==`function`){this.selectorUnsubscribes=[t,e];return}t.push(e)}retainState(e){let t=this.stateDependencies;if(t){let n=t.get(e);if(n){n.revision=this.stateDependencyRevision;return}t.set(e,this.createStateDependency(e));return}let n=this.stateDependencyStore;if(!n){this.stateDependencyStore=e,this.stateDependencyRevisionStamp=this.stateDependencyRevision,this.stateDependencyUnsubscribe=this.subscribeState(e);return}if(n===e){this.stateDependencyRevisionStamp=this.stateDependencyRevision;return}let r=this.stateDependencyUnsubscribe;this.stateDependencyStore=void 0,this.stateDependencyUnsubscribe=void 0,this.stateDependencies=new Map,r&&this.stateDependencies.set(n,{revision:this.stateDependencyRevisionStamp,unsubscribe:r}),this.stateDependencies.set(e,this.createStateDependency(e))}finishRebuild(e){this.stateDependencyStore&&this.stateDependencyRevisionStamp!==this.stateDependencyRevision&&(this.stateDependencyUnsubscribe?.(e),this.stateDependencyStore=void 0,this.stateDependencyUnsubscribe=void 0);let t=this.stateDependencies;if(t){for(let n of t){let r=n[1];r.revision!==this.stateDependencyRevision&&(r.unsubscribe(e),t.delete(n[0]))}if(!t.size){this.stateDependencies=void 0;return}if(t.size===1){for(let e of t){this.stateDependencyStore=e[0],this.stateDependencyRevisionStamp=e[1].revision,this.stateDependencyUnsubscribe=e[1].unsubscribe;break}this.stateDependencies=void 0}}}clear(e){this.clearSelectors(e),this.stateDependencyUnsubscribe?.(e),this.stateDependencyStore=void 0,this.stateDependencyUnsubscribe=void 0;let t=this.stateDependencies;if(t){for(let n of t)n[1].unsubscribe(e);this.stateDependencies=void 0}}get size(){let e=this.selectorUnsubscribes;return(typeof e==`function`?1:e?.length??0)+ +!!this.stateDependencyStore+(this.stateDependencies?.size??0)}clearSelectors(e){let t=this.selectorUnsubscribes;if(this.selectorUnsubscribes=void 0,t){if(typeof t==`function`){t(e);return}for(let n=0;n<t.length;n++)t[n](e)}}createStateDependency(e){return{revision:this.stateDependencyRevision,unsubscribe:this.subscribeState(e)}}subscribeState(e){return ct(e)?e[Q](this.invalidate):e.subscribe(d,this.invalidate,en)}},nn=class{constructor(){this.watcherCount=0,this.ordinaryWatcherCount=0,this.cascadeParticipantCount=0,this.cascadeStateListenerCount=0}addWatcher(e){let t=Le(this.watchers,this.watcherCount,e);return t===null?!1:(this.watchers=t,this.watcherCount+=1,sn(e)?this.cascadeParticipantCount+=1:this.ordinaryWatcherCount+=1,!0)}deleteWatcher(e){let t=Re(this.watchers,this.watcherCount,e);return t===null?!1:(this.watchers=t,--this.watcherCount,sn(e)?--this.cascadeParticipantCount:--this.ordinaryWatcherCount,!0)}addCascadeStateListener(e){let t=Le(this.cascadeStateListeners,this.cascadeStateListenerCount,e);return t===null?!1:(this.cascadeStateListeners=t,this.cascadeParticipantCount+=1,this.cascadeStateListenerCount+=1,!0)}deleteCascadeStateListener(e){let t=Re(this.cascadeStateListeners,this.cascadeStateListenerCount,e);return t===null?!1:(this.cascadeStateListeners=t,--this.cascadeParticipantCount,--this.cascadeStateListenerCount,!0)}notifyCascade(e,t){ze(this.cascadeStateListeners,this.cascadeStateListenerCount,h,e,t),this.cascadeParticipantCount!==this.cascadeStateListenerCount&&ze(this.watchers,this.watcherCount,rn,e,t)}notifyOrdinary(e,t){ze(this.watchers,this.watcherCount,an,e,t)}clear(){this.watchers=Be(this.watchers,this.watcherCount),this.cascadeStateListeners=Be(this.cascadeStateListeners,this.cascadeStateListenerCount),this.watcherCount=0,this.ordinaryWatcherCount=0,this.cascadeParticipantCount=0,this.cascadeStateListenerCount=0}};function rn(e,t,n){typeof e==`function`||!e.isCascadeParticipant||on(e,t)}function an(e,t,n){if(typeof e==`function`){e(t,n);return}e.isCascadeParticipant||on(e,t)}function on(e,t){let n=e.selector(t);if(e.equalityFn(e.currentSlice,n))return;let r=e.currentSlice;e.currentSlice=n,e.listener(n,r)}function sn(e){return typeof e!=`function`&&e.isCascadeParticipant}const cn=Symbol(`stores.deriveProxy.unwrap`);function ln(e,t,n,r){let i=n.get(e);if(vn(i))return i;let a=un(t,e,r);return n.set(e,a),a}function un(e,t,n,r=[]){return!e||typeof e!=`object`?(n(t,r,!0),e):dn(e,r,t,n,new WeakSet,new WeakMap)}function dn(e,t,n,r,i,a){let o=Array.isArray(e);return new Proxy(e,{get(s,c,l){if(c===cn)return r(n,t,!0),s;if(i.has(s))return Reflect.get(s,c,l);if(c===`__proto__`||typeof c==`symbol`)return c===Symbol.iterator&&(r(n,t,!0),i.add(s)),Reflect.get(s,c,l);if(o&&P(c))return r(n,t,!0),i.add(s),Reflect.get(s,c,l);let u=Reflect.get(s,c,s),d=String(c),f=t.concat(d);if(typeof u==`function`)return N(s,c)?function(...e){return r(n,f,!0,{args:e.length?e:void 0}),Reflect.apply(u,s,e)}:(r(n,t,!0),u.bind(e));let p=!!u&&typeof u==`object`;return r(n,f,!p),p?(a.has(u)||a.set(u,dn(u,f,n,r,i,a)),a.get(u)):u},getOwnPropertyDescriptor(e,a){return r(n,t,!0),i.add(e),Reflect.getOwnPropertyDescriptor(e,a)},has(e,i){return r(n,t,!0),Reflect.has(e,i)},ownKeys(e){return r(n,t,!0),i.add(e),Reflect.ownKeys(e)}})}function fn(e,t){return!e||typeof e!=`object`?e:gn(e)||(Array.isArray(e)?pn(e,t):F(e)&&mn(e,t),e)}function pn(e,t){let n=_n(e,t);if(n)for(let t=0;t<e.length;t++)hn(e,String(t),n)}function mn(e,t){let n=_n(e,t);if(n)for(let t of Reflect.ownKeys(e))hn(e,t,n)}function hn(e,t,n){let r=Reflect.getOwnPropertyDescriptor(e,t);if(!r||!(`value`in r))return;let i=fn(r.value,n);i!==r.value&&(r.value=i,Reflect.defineProperty(e,t,r))}function gn(e){let t=Reflect.get(e,cn);return t&&typeof t==`object`?t:void 0}function _n(e,t){let n=t??new WeakSet;return n.has(e)?null:(n.add(e),n)}function vn(e){return e!==void 0}const yn=Object.freeze([]);function bn(){let e,t,n;return{buildProxySubscriptions(r,i,a){let o=[],s=t,c=e;if(s&&c)Cn(s,c,[],0,o,a);else if(n)for(let e of n)Cn(e[1],e[0],[],0,o,a);Dn(o,r,i)},reset(){e=void 0,t=void 0,n=void 0},trackPath(r,i,a,o){let s=t;if(s){let i=e;if(i!==r)if(!i)e=r;else{let a=n??(n=new Map);a.set(i,s),s=xn(),a.set(r,s),e=void 0,t=void 0}}else{let i=n;i?(s=i.get(r),s||(s=xn(),i.set(r,s))):(s=xn(),e=r,t=s)}Sn(s,i,a,o)}}}function xn(){return f()}function Sn(e,t,n,r){let i=e;for(let e=0;e<t.length;e++){let n=t[e],r=i.children,a;if(r)a=r[n],a||(a=r[n]=xn());else if(a=i.child,!a)a=xn(),i.child=a,i.childKey=n;else if(i.childKey!==n){let e=i.childKey;if(e===void 0)i.childKey=n;else{let t=xn();t[e]=a,a=t[n]=xn(),i.child=void 0,i.childKey=void 0,i.children=t}}i=a}n&&(i.isLeaf=!0),r&&wn(i,r)}function Cn(e,t,n,r,i,a=2){let o=e.child;if(o){let s=e.childKey;if(e.isLeaf){if(En(e,t,n,i),!o.invocation||s===void 0)return}else if(s===void 0){En(e,t,n,i);return}n.push(s),Cn(o,t,n,r+1,i,a),n.pop();return}let s=e.children;if(!s){En(e,t,n,i);return}if(e.isLeaf||r>=a){En(e,t,n,i);for(let e in s){let o=s[e];o.invocation&&(n.push(e),Cn(o,t,n,r+1,i,a),n.pop())}return}for(let e in s)n.push(e),Cn(s[e],t,n,r+1,i,a),n.pop()}function wn(e,t){let n=e.invocation;if(!n){e.invocation=t;return}if(Tn(n,t))return;let r=e.extraInvocations;if(!r){e.extraInvocations=[t];return}for(let e=0;e<r.length;e++)if(Tn(r[e],t))return;r.push(t)}function Tn(e,t){let n=e.args,r=t.args,i=n?.length??0;if(i!==(r?.length??0))return!1;if(!n||!r)return!0;for(let e=0;e<i;e++)if(!Object.is(n[e],r[e]))return!1;return!0}function En(e,t,n,r){let i=n.slice(),a=e.invocation;if(!a){r.push({store:t,path:i});return}r.push({store:t,path:i,invocation:a});let o=e.extraInvocations;if(o)for(let e=0;e<o.length;e++)r.push({store:t,path:i,invocation:o[e]})}function Dn(e,t,n){for(let n of e){let e=n.invocation?kn(n.path,n.invocation):On(n.path);t(n.store,e,n.path)}n&&jn(e)}function On(e){return e.length?t=>An(t,e):d}function kn(e,t){let n=e.slice(0,-1),r=e[e.length-1];return e=>{let i=An(e,n),a=i&&typeof i==`object`?Reflect.get(i,r):void 0;return typeof a==`function`?Reflect.apply(a,i,t.args??yn):void 0}}function An(e,t){let n=e;for(let e=0;e<t.length;e++){if(!n||typeof n!=`object`)return n;n=Reflect.get(n,t[e])}return n}function jn(e){let t=e.length;console.log(`[π‘ ${t} ${$t(`Proxy Subscription`,t)} π‘]:`,JSON.stringify(e.map(e=>{let t=Mn(e.store),n=e.path.join(`.`);if(!e.invocation)return n?`$(${t}).${n}`:`$(${t})`;let r=e.invocation.args?.length??0;return`$(${t}).${n}${r?`(${r}_${$t(`arg`,r)})`:`()`}`}),null,2))}function Mn(e){return`name`in e&&typeof e.name==`string`?e.name:`store`}const Nn=Symbol(),Pn=Symbol(),Fn=Symbol(`stores.derivedStore.readDependencyState`);function In(e,t=Object.is){let n,r=!1,i,a=!1,o=!1;typeof t==`function`?i=t:(n=t.debounce,r=l?t.debugMode??!1:!1,i=t.equalityFn??Object.is,a=t.keepAlive??!1,o=t.lockDependencies??!1);let s=new nn,c=new tn(A),u=+!!a,f,p,m=Nn,h=!1,g=!1,_=!0,v=!0,y=null,b=Pn;function x(e,t,n){if(!v)return(t??d)(zn(e));if(!u)return(t??d)(e.getState());if(!t){let t=zn(e);return!t||typeof t!=`object`?(c.retainState(e),t):(f||(f=new WeakMap),p||(p=bn()),ln(e,t,f,p.trackPath))}let r=n?{equalityFn:n,isCascadeParticipant:!0}:en;return c.addSelector(e.subscribe(t,A,r)),t(zn(e))}function S(){if(!_&&$(m))return m;_=!1,v&&c.beginRebuild(!0);let t=!0,n=m,a=$(n);g=!0;try{let o=e(x),s=p?fn(o):o;a&&i(n,s)?(r&&console.log(`[π₯· Derive Complete π₯·]: No change detected`),t=!1,m=n):m=s}finally{g=!1,v&&c.finishRebuild(!0)}let s=r&&(!a||r===`verbose`&&v);if(s){a?r===`verbose`&&console.log(`[π Rebuilding Subscriptions π]: Createdβ¦`):console.log(`[π Initial Derive Complete π]: Createdβ¦`);let e=c.size;console.log(`[π― ${e} ${$t(`Selector Subscription`,e)} π―]`)}return p&&v&&(p.buildProxySubscriptions((e,t)=>{c.addSelector(e.subscribe(t,A,en))},s),f=void 0,o?p=void 0:p.reset()),t&&a&&C(m,n),o&&(v=!1),m}function C(e,t){let n=s.cascadeParticipantCount,i=n>0&&s.ordinaryWatcherCount>0,a=s.ordinaryWatcherCount>0&&(i||Xe()!==null||Ye());if(i&&Ze(),r){let e=s.ordinaryWatcherCount+n;console.log(`[π» Derive Complete π»]: Notifying ${e} ${$t(`watcher`,e)}`)}if(n&&s.notifyCascade(e,t),s.ordinaryWatcherCount){if(a){b===Pn?(b=t,et(w)):$(b)||(b=t);return}s.notifyOrdinary(e,t)}}function w(){u&&_&&!s.cascadeParticipantCount&&S();let e=b;b=Pn,s.ordinaryWatcherCount&&$(m)&&e!==Pn&&$(e)&&s.notifyOrdinary(m,e)}let T=n?Tt(D,typeof n==`number`?n:n.delay,typeof n==`number`?{leading:!1,maxWait:n,trailing:!0}:n):void 0,E=T??(()=>{h||(h=!0,queueMicrotask(D))});function D(){if(h=!1,!u){a||I();return}_&&S()}function O(e){if(e!==void 0&&(e||T&&_)){queueMicrotask(O);return}!u&&!a&&I()}function k(){let e=y;e===Xe()&&(D(),y===e&&(y=null))}function A(){if(!g){if(!T){if(s.cascadeParticipantCount){_=!0,Ze();let e=Xe(),t=e===null?0:e+1;if(y!==null&&t<=y)return;y=t,tt(k,t);return}if(_)return;if(_=!0,Ye()){b===Pn&&(b=Nn,et(w));return}}_||(_=!0,y=null,E())}}function j(e){u+=1;try{return e()}finally{--u}}function ee(){return _||!$(m)?u?S():j(S):(h&&u&&D(),m)}function M(){return Ye()&&Xe()===null&&$e(),_||!$(m)?u?S():e(x):m}function N(...e){if(e.length===1){let t=e[0];return s.addWatcher(t)&&(u+=1),$(m)||M(),()=>{s.deleteWatcher(t)&&(--u,u||O(!1))}}let[t,n,r]=e,i=r?.equalityFn??Object.is,a=r?.isCascadeParticipant??!1,o=t(u?M():j(M)),c={currentSlice:o,equalityFn:i,isCascadeParticipant:a,listener:n,selector:t};return s.addWatcher(c),u+=1,r?.fireImmediately&&n(o,o),()=>{s.deleteWatcher(c)&&(--u,u||O(a))}}function P(e){return u?M():j(M),s.addCascadeStateListener(e)&&(u+=1),()=>{s.deleteCascadeStateListener(e)&&(--u,u||O(!0))}}function F(){u&&(T?T.flush():_&&S())}function I(){T?.cancel(),c.clear(),s.clear(),u=0,p=void 0,f=void 0,v=!0,h=!1,g=!1,_=!0,m=Nn,b=Pn,y=null}function L(){return _||h||!$(m)?u?S():j(S):m}return{[Fn]:L,[Q]:P,destroy:I,flushUpdates:F,getSnapshot:ee,getState:M,subscribe:N,getInitialState:Ln,setState:Rn}}function Ln(){throw Error(`[createDerivedStore]: getInitialState() is not available on derived stores.`)}function Rn(){throw Error(`[createDerivedStore]: setState() is not available on derived stores.`)}function zn(e){let t=e[Fn];return t?t():e.getState()}function $(e){return e!==Nn}var Bn=class{constructor(e){this.count=0,this.lastSubscriptionTime=null,this.fetchThrottleMs=null,this.onSubscribe=null,this.onLastUnsubscribe=null,e&&(this.fetchThrottleMs=q.seconds(5))}init({onSubscribe:e,onLastUnsubscribe:t}){this.onSubscribe=e,this.onLastUnsubscribe=t}hasSubscribers(){return this.count>0}subscribe(){let e=this.count===0,t=this.fetchThrottleMs!==null,n=t&&this.lastSubscriptionTime!==null&&!e&&Date.now()-this.lastSubscriptionTime<=this.fetchThrottleMs;return this.count+=1,this.onSubscribe?.(e,n),t&&(this.lastSubscriptionTime=Date.now()),e=>{let t=this.count===1;this.count=Math.max(this.count-1,0),t&&(this.onLastUnsubscribe?.(e),this.lastSubscriptionTime=null)}}};function Vn(e,t=queueMicrotask){let n=!1,r;function i(){n=!1,e(...r)}function a(...e){r=e,!n&&(n=!0,t(i))}return a}const Hn=Symbol(`stores.queryParamConfig`);function Un(e,t){return{[Hn]:!0,key:t.key,value:e}}function Wn(e){return!!e&&typeof e==`object`&&Hn in e}function Gn(e){return JSON.stringify(qn(e))}function Kn(e){return JSON.parse(e)}function qn(e){return typeof e!=`object`||!e?e:Object.keys(e).sort().reduce((t,n)=>{let r=e[n];return t[n]=F(r)?qn(r):r,t},f())}const Jn=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});function Yn(e,t,n){let r=f(),i=null,a=!1;if(e)for(let n in e){if(!N(e,n))continue;let o=Xn(r,e[n],n,t);o&&((i??(i=f()))[n]=o,o.key!==void 0&&(a=!0))}return{buildKey(e=r){return Gn(a?tr(i,e):e)},complete(e){return e?ir(e,n)?e:{...r,...e}:$n(r)},get(){return $n(r)},subscribe(e){return er(i,r,e)}}}function Xn(e,t,n,r){return Wn(t)?Qn(e,t.value,n,r,t.key):Qn(e,t,n,r)}function Zn(e,t){let n=[],r,i;function a(e,t,a){return t?(n.push(n=>e.subscribe(t,n,nr(a))),t(rr(e))):(r??(r=bn()),i??(i=new WeakMap),ln(e,rr(e),i,r.trackPath))}function o(e,t=d){return t(rr(e))}let s=e(a,t),c=r?fn(s):s;return r&&(r.buildProxySubscriptions((e,t)=>{n.push(n=>e.subscribe(t,n,Jn))},!1),r=void 0),i=void 0,{initialValue:c,subscribe(r){let i=()=>r(e(o,t)),a=n.map(e=>e(i));return e=>{for(let t of a)t(e)}}}}function Qn(e,t,n,r,i){if(ar(t)){let a=Zn(t,r);return e[n]=a.initialValue,i===void 0?{tracked:a}:{key:i,tracked:a}}return e[n]=t,i===void 0?null:{key:i}}function $n(e){let t=f();for(let n in e)N(e,n)&&(t[n]=e[n]);return t}function er(e,t,n){if(!e)return m;let r;for(let i in e){let a=e[i]?.tracked;a&&(r??(r=[])).push(a.subscribe(e=>{let r=t[i];Ie(r,e)||(t[i]=e,n(i,r,e))}))}return r?e=>{for(let t of r)t(e)}:m}function tr(e,t){let n=f();for(let r in t){if(!N(t,r))continue;let i=e?.[r];if(i?.key===!1)continue;let a=t[r];n[r]=i?.key?i.key(a):a}return n}function nr(e){return e?{equalityFn:e,isCascadeParticipant:!0}:Jn}function rr(e){return Te(e)?e.getSnapshot():e.getState()}function ir(e,t){for(let n of t)if(!(n in e))return!1;return!0}function ar(e){return typeof e==`function`}const or={error:!0,lastFetchedAt:!0,queryCache:!0,queryKey:!0,status:!0,enabled:!1,fetch:!1,getCacheEntry:!1,getData:!1,getStatus:!1,isDataExpired:!1,isStale:!1,reset:!1},sr=Object.freeze({force:!0}),cr=Object.freeze({once:!0}),lr=new Set;let ur=!1;function dr(e){lr.add(e),!ur&&(ur=!0,queueMicrotask(()=>{ur=!1,Ve(fr)}))}function fr(){for(let e of lr)lr.delete(e),e()}function pr(e,t,n){ae();let r=typeof t==`function`?t:_r,i=typeof t==`object`?t:n,a=mr(i)?i:void 0,o=le(),s=o.minStaleTime,{fetcher:c,onError:d=o.onError,onFetched:f,setData:m,transform:h,abortInterruptedFetches:g=o.abortInterruptedFetches,cacheTime:_=o.cacheTime,debugMode:v=o.debugMode,disableAutoRefetching:y=o.disableAutoRefetching,disableCache:b=!1,enabled:x=!0,keepPreviousData:S=o.keepPreviousData,paramChangeThrottle:C=o.paramChangeThrottle,params:w,retry:T=o.retry,retryDelay:E=o.retryDelay,staleTime:D=o.staleTime,suppressStaleTimeWarning:O=o.suppressStaleTimeWarning}=e,k=typeof D==`function`?o.staleTime:D;l&&s!==!1&&!y&&!O&&k<s&&console.warn(`[createQueryStore${a?.storageKey?`: ${a.storageKey}`:``}] β Stale times under ${s/1e3} seconds are not recommended. Provided staleTime: ${k/1e3} seconds`);let A=Error(`[createQueryStore: AbortError] Fetch interrupted`),ee=typeof _==`function`,M=l&&v,N=e.params?Object.keys(e.params):[],P=!1,F,I=[],R=null,z=null,B=null,V=null,H=null,U=null,ne=null,re={enabled:typeof x==`function`?!1:x,error:null,lastFetchedAt:null,queryCache:{},queryKey:``,status:K.Idle},W=new Bn(y);function ie(){B&&(V=null,B.abort(),B=null)}function G(){H&&(clearTimeout(H),H=null)}async function oe(e){let t=new AbortController;B=t;try{return await new Promise((n,r)=>{t.signal.addEventListener(`abort`,()=>r(A),cr),Promise.resolve(c(e,t)).then(n,r)})}finally{B===t&&(B=null)}}function se(e,t,n){let i=n.setState;function o(e,t){e!==t&&ne!==t&&(ne=t,t&&W.hasSubscribers()?queueMicrotask(()=>p.fetch(void 0,void 0,!0)):(H||g)&&(g&&ie(),G()))}function s(e){let t=typeof e==`function`;if(t||e.enabled!==void 0){let n,r=i(r=>{let i=t?e(r):e,a=i.enabled===void 0?r.enabled:i.enabled;return a!==r.enabled&&(n=()=>o(r.enabled,a)),i});return n?.(),r}else return i(e)}n.setState=s,W.init({onSubscribe:(n,r)=>{let i=t();if(i.enabled)if(n){let t=F.get(),n=F.buildKey(t);i.queryKey!==n&&e({queryKey:n}),i.isStale()?p.fetch(t,void 0,!0):l(t)}else y&&!r&&p.fetch(void 0,void 0,!0)},onLastUnsubscribe:e=>{G(),g&&!e&&ie()}});function l(e){if(y||k<=0||k===1/0||!W.hasSubscribers())return;G();let n=t();if(!n.enabled)return;let r=F.buildKey(e),i=(b?U===r&&n.lastFetchedAt:n.queryCache[r]?.lastFetchedAt)||null,a=i?k-(Date.now()-i):k;H=setTimeout(()=>{t().enabled&&p.fetch(e,sr,!0)},a)}function u(e){let n=t(),r=n.status;switch(e){case`isIdle`:return r===K.Idle;case`isLoading`:return r===K.Loading;case`isError`:case`isInitialLoad`:case`isSuccess`:case void 0:{let t=n.queryKey,i=b?void 0:n.queryCache[t],a=b?r===K.Error:typeof i?.errorInfo?.lastFailedAt==`number`;if(e===`isError`)return a;let o=((b?U===t&&n.lastFetchedAt:i?.lastFetchedAt)||null)!==null,s=!o&&!a&&n.enabled;if(e===`isInitialLoad`)return s;let c=o&&!a;return e===`isSuccess`?c:{isError:a,isIdle:r===K.Idle,isLoading:r===K.Loading,isInitialLoad:s,isSuccess:c}}}}let p={...r(s,t,n),...re,async fetch(n,r,i=!1,o=0){let u=!!r?.skipStoreUpdates,v=t();if(!u&&(!v.enabled&&!r?.force||i&&!W.hasSubscribers()))return null;let y=v.error,x=v.queryKey,C=v.status===K.Loading,w=F.complete(n),D=F.buildKey(w);if(C&&V?.promise&&V.key===D)return M&&console.log(`[π Using Active Fetch π] for params:`,JSON.stringify(w)),V.promise;let O=r?.staleTime??k,P=typeof r?.updateQueryKey==`boolean`?r.updateQueryKey:i?S:!1,I=(i||x===D||P)&&!u,R=V!==null;if(g&&I&&ie(),!r?.force){let t=v.lastFetchedAt,n=b?void 0:v.queryCache[D],r=n?.lastFetchedAt,i=n?.errorInfo,a=(b?U===D&&t:r)||null;if(!(!a||Date.now()-a>=O)&&(!i||!i.retryAllowed||u))return I&&!H&&k!==0&&k!==1/0&&l(w),P&&e(e=>e.queryKey===D?e:{queryKey:D}),M&&console.log(`[πΎ Returning Cached Data πΎ] for params:`,JSON.stringify(w)),n?.data??null}let z=I?{key:D}:null,B=r?.cacheTime??(ee?_(w):_);z&&(G(),P&&!R&&v.lastFetchedAt===null&&x!==D?e({error:null,queryKey:D,status:K.Loading}):(y||!C)&&e({error:null,status:K.Loading}),V=z);async function ne(){let v=a?.storageKey||D;try{M&&(!i&&n&&N.some(e=>!(e in n))?console.log(`[π Fetching with Partial Params π]
|
|
7
|
+
`,`- Provided params:`,`${JSON.stringify(n)}\n`,`- Filled in params:`,`${JSON.stringify(Object.fromEntries(Object.keys(w).filter(e=>!(e in n)).map(e=>[e,w[e]])))}`):console.log(`[π Fetching π] for params:`,JSON.stringify(w)));let t=await(g&&I?oe(w):c(w,null)),a=Date.now();M&&console.log(`[β
Fetch Successful β
] for params:`,JSON.stringify(w));let o;try{o=yr(t,w,h)}catch(e){throw vr(v,`transform`,e)}if(u)return M&&console.log(`[π₯· Successful Parallel Fetch π₯·] for params:`,JSON.stringify(w)),r.skipStoreUpdates===`withCache`&&e(e=>{if(!m)return b?e:{queryCache:{...e.queryCache,[D]:{cacheTime:B,data:o,errorInfo:null,lastFetchedAt:a}}};let t=e,n=b?void 0:t.queryCache[D];try{m({data:o,params:w,queryKey:D,set:e=>{t=typeof e==`function`?{...t,...e(t)}:{...t,...e}}})}catch(e){throw vr(v,`setData`,e)}return!b&&Object.is(n,t.queryCache[D])&&(t={...t,queryCache:{...t.queryCache,[D]:{cacheTime:B,data:null,errorInfo:null,lastFetchedAt:a}}}),t}),o;if((m?s:e)(e=>{let t={...e,error:null,lastFetchedAt:a,queryKey:P?D:e.queryKey,status:K.Success};if(!m&&!b)M&&console.log(`[πΎ Setting Cache πΎ] for params:`,JSON.stringify(w),`| Has previous data?:`,!!t.queryCache[D]?.data),t.queryCache={...t.queryCache,[D]:{cacheTime:B,data:o,errorInfo:null,lastFetchedAt:a}};else if(m){M&&console.log(`[πΎ Setting Data πΎ] for params:`,JSON.stringify(w));let e=b?void 0:t.queryCache[D];try{m({data:o,params:w,queryKey:D,set:e=>{t=typeof e==`function`?{...t,...e(t)}:{...t,...e}}})}catch(e){throw vr(v,`setData`,e)}!b&&Object.is(e,t.queryCache[D])&&(t.queryCache={...t.queryCache,[D]:{cacheTime:B,data:null,errorInfo:null,lastFetchedAt:a}})}return b||_===1/0?t:gr(S,D,t)}),I&&(U=D,l(w)),f)try{f({data:o,fetch:p.fetch,params:w,set:s})}catch(e){j.error(vr(v,`onFetched callback`,e))}return o??null}catch(n){if(n===A)return M&&console.log(`[β Fetch Aborted β] for params:`,JSON.stringify(w)),null;let a=!i&&r?.throwOnError===!0,s=te(n);if(s instanceof L&&j.error(s),!I){if(a)throw s;return null}let c=b?void 0:t().queryCache[D],l,u;if(typeof T==`function`){l={error:s,params:w,queryKey:D,retryCount:o};try{u=T(l)}catch(e){j.error(vr(v,`retry callback`,e)),u=!1}}else u=T!==!1&&o<T;let f;if(u&&t().enabled&&W.hasSubscribers())if(E===void 0)f=de(o);else if(typeof E==`number`)f=E;else{l??(l={error:s,params:w,queryKey:D,retryCount:o});try{f=E(l)}catch(e){j.error(vr(v,`retryDelay callback`,e)),u=!1}}let m=f!==void 0;if(f!==void 0&&(G(),H=setTimeout(()=>{t().enabled&&p.fetch(w,sr,!0,o+1)},f)),e(b?e=>({error:s,queryKey:P?D:e.queryKey,status:K.Error}):e=>({error:s,queryCache:{...e.queryCache,[D]:{cacheTime:c?.cacheTime??B,data:c?.data??null,lastFetchedAt:c?.lastFetchedAt??null,errorInfo:{error:s,lastFailedAt:Date.now(),retryAllowed:u,retryCount:o}}},queryKey:P?D:e.queryKey,status:K.Error})),d)try{d({error:s,params:w,queryKey:D,retryCount:o,willRetry:m})}catch(e){j.error(vr(v,`onError callback`,e))}if(a)throw s;return null}finally{V===z&&(V=null)}}return z?(z.promise=ne(),z.promise):ne()},getCacheEntry(e){if(b)return null;let n=t(),r=e?typeof e==`string`?e:F.buildKey(F.complete(e)):n.queryKey;return n.queryCache[r]??null},getData(e){if(b)return null;let n=t().getCacheEntry(e);return!n||n.data===null?null:S?n.data:n.lastFetchedAt&&Date.now()-n.lastFetchedAt>=n.cacheTime?null:n.data},getStatus:u,isDataExpired(e){let n=t(),r=n.queryKey,i=b?void 0:n.queryCache[r],a=n.lastFetchedAt,o=(b?U===r&&a:i?.lastFetchedAt)||null;if(!o)return!0;let s=e??i?.cacheTime;return s===void 0||Date.now()-o>=s},isStale(e){let n=t(),r=n.queryKey,i=(b?U===r&&n.lastFetchedAt:n.queryCache[r]?.lastFetchedAt)||null;if(!i)return!0;let a=e??k;return Date.now()-i>=a},reset(t=!1){for(let e of I)e();I=[],F=Yn(void 0,q,N),R=null,z=null,ie(),G(),_e?.cancel(),V=null,U=null,t&&e(re)}},v=n.subscribe;return n.subscribe=(...e)=>{let t=P?void 0:W.subscribe(),n=e.length===1?v(e[0]):v(e[0],e[1],e[2]);return e=>{t?.(e),n(e)}},lt(n,e=>t=>{let n=P?void 0:W.subscribe(),r=e(t);return e=>{n?.(e),r(e)}}),p}let q=a?.storageKey?Zt(se,p(a,{partialize:hr(S,a.partialize)})):i&&!(`storageKey`in i)?Zt(se,i):Zt(se),ce=q.getState(),ue=ce.error,fe=ce.enabled,pe=ce.queryKey,me=ce.fetch;pe&&!ue&&(U=pe),P=!0,F=Yn(w,q,N),typeof x==`function`&&(R=Zn(x,q)),typeof e.staleTime==`function`&&(z=Zn(e.staleTime,q),k=z.initialValue);let he=Vn(e=>{me(e,void 0,!0)},dr);function ge(){if(S)he(void 0);else{let e=F.get();q.setState({queryKey:F.buildKey(e)}),he(e)}}let _e=u||!C?void 0:Tt(ge,typeof C==`number`?C:C.delay,typeof C==`number`?{leading:!1,maxWait:C,trailing:!0}:C);function ve(){if(G(),_e){let e=q.getState();S&&V?.key===e.queryKey&&e.lastFetchedAt===null?ge():_e();return}ge()}if(I.push(F.subscribe((e,t,n)=>{M&&console.log(`[π Param Change π] -`,e,`- [Old]:`,`${t?.toString()},`,`[New]:`,n?.toString()),ve()})),z){let e=z.initialValue;M&&console.log(`[π StaleTime Subscription π] Initial value:`,e),I.push(z.subscribe(t=>{t!==e&&(M&&console.log(`[π StaleTime Change π] - [Old]:`,`${e},`,`[New]:`,t),e=t,k=t,G(),me(void 0,void 0,!0))}))}let J;if(R){let e=R.initialValue;fe!==e&&((J??(J={})).enabled=e),M&&console.log(`[π Enabled Subscription π] Initial value:`,e),I.push(R.subscribe(t=>{t!==e&&(M&&console.log(`[π Enabled Change π] - [Old]:`,`${e},`,`[New]:`,t),e=t,q.setState({enabled:t}))}))}else fe!==re.enabled&&((J??(J={})).enabled=re.enabled);let xe=F.buildKey();return xe!==pe&&((J??(J={})).queryKey=xe),J&&q.setState(J),P=!1,be(q,ye.QueryStore)}function mr(e){return typeof e?.storageKey==`string`}function hr(e,t){return n=>{let r={...n},i=f();for(let e in r)N(r,e)&&e in or&&(or[e]&&(i[e]=r[e]),delete r[e]);return{...t?t(r):kt(r),...gr(e,null,i)}}}function gr(e,t,n){if(!n.queryCache)return n;let r=Date.now(),i=t??(e&&n.queryKey||null),a=f(),o=!1;for(let e in n.queryCache){if(!N(n.queryCache,e))continue;let t=n.queryCache[e];t&&(r-(t.lastFetchedAt??t.errorInfo.lastFailedAt)<t.cacheTime||e===i)?a[e]=t:o=!0}return o?{...n,queryCache:a}:n}function _r(){return Object.create(null)}function vr(e,t,n){return new L(`[createQueryStore: ${e}]: ${t} failed`,n)}function yr(e,t,n){return n?n(e,t):e}const br=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});function xr(e,t,n){let r=typeof t==`function`,i=r?t:void 0,a=r?n:t,o=new Set,s,c;function l(e,t){let n=e.getState(),r=t.getState();if(c)for(let e of c)u(e,t,n,r);if(s)for(let e of s)d(e,t,n,r);o.size&&Qe();for(let e of o)f(e,t,n,r)}function u(e,t,n,r){e.unsubscribe(),e.unsubscribe=Sr(t,e.listener),!Object.is(r,n)&&(Ze(),e.listener(r,n))}function d(e,t,n,r){f(e,t,n,r)&&Ze()}function f(e,t,n,r){e.unsubscribe();let i=e.args;if(i.length===1){let a=i[0];e.unsubscribe=t.subscribe(a);let o=!Object.is(r,n);return o&&a(r,n),o}let a=i[0],o=i[1],s=i[2];s?.fireImmediately&&(s={...s,fireImmediately:!1});let c=a(n),l=a(r);return e.unsubscribe=t.subscribe(a,o,s),(s?.equalityFn??Object.is)(c,l)?!1:(o(l,c),!0)}function p(e,t){l(t,e),J(t)}let m=In(e,{debugMode:a?.debugMode??!1,lockDependencies:a?.lockDependencies??!0}),h;function g(){return h??(h=m.subscribe(p)),m.getState()}function _(...e){let t=g(),n={args:e,unsubscribe:e.length===1?t.subscribe(e[0]):t.subscribe(e[0],e[1],e[2])},r=e[2]?.isCascadeParticipant??!1;return r?(s??(s=new Set)).add(n):o.add(n),()=>{n.unsubscribe(),r?s?.delete(n)&&s.size===0&&(s=void 0):o.delete(n)}}function v(e){let t={listener:e,unsubscribe:Sr(g(),e)};return(c??(c=new Set)).add(t),e=>{t.unsubscribe(e),c?.delete(t)&&c.size===0&&(c=void 0)}}return Object.assign({[Q]:v,[ye.VirtualStore]:!0,destroy:()=>{h?.(),h=void 0,m.destroy()},getInitialState:()=>g().getInitialState(),getState:()=>g().getState(),persist:Cr(g),setState:wr(g),subscribe:_},i?.(g))}function Sr(e,t){return ct(e)?e[Q](t):e.subscribe(d,t,br)}function Cr(e){return{clearStorage:()=>e().persist?.clearStorage(),getOptions:()=>e().persist?.getOptions()??{},hasHydrated:()=>e().persist?.hasHydrated()??!0,hydrationPromise:()=>e().persist?.hydrationPromise?.()??Promise.resolve(),onFinishHydration:t=>e().persist?.onFinishHydration(t)??m,onHydrate:t=>e().persist?.onHydrate(t)??m,rehydrate:()=>e().persist?.rehydrate(),setOptions:t=>e().persist?.setOptions(t)}}function wr(e){return function(...t){return t[1]===!0?e().setState(t[0],!0):e().setState(t[0])}}function Tr(e,t){let n=Zt(e,t);return D(n,n.getState,n.getInitialState)}function Er(e,t=Object.is){let n=In(e,t);return D(n,n.getSnapshot,void 0)}function Dr(e,t,n){let r=pr(e,t,n);return D(r,r.getState,r.getInitialState)}function Or(e,t,n){let r=xr(e,t,n);return D(r,r.getState,r.getInitialState)}const kr=Symbol();function Ar(e){let t=r(kr);return t.current===kr&&(t.current=e()),t}const jr=Object.freeze({debugMode:!1,enabled:!0,equalityFn:Object.is,fireImmediately:!1});function Mr(e,t,r,i=jr){let a=Ar(()=>Ir(t,r,i)),o=Rr(i);return zr(a,t,r,i),n(()=>{if(o)return Pr(e,a),()=>Fr(a)},[o,e]),a}const Nr=Object.freeze({fireImmediately:!1,forceResubscribe:!1});function Pr(e,t,n=Nr){if(t.current.isActive){if(!n?.forceResubscribe)return;t.current.unsubscribe()}t.current.options.debugMode&&console.log(`[π‘ useListen π‘] Attaching listener`),t.current.isActive=!0,t.current.resubscribe=(n=Nr)=>Pr(e,t,n);let r=e.subscribe(e=>t.current.selector(e),(n,i)=>t.current.react(n,i,e.getState,()=>{r(),t.current.isActive=!1}),n.fireImmediately?{...t.current.options,fireImmediately:!0}:t.current.options);t.current.unsubscribe=()=>{t.current.isActive&&(r(),t.current.isActive=!1)}}function Fr(e){e.current.options.debugMode&&console.log(`[ποΈ useListen ποΈ] Detaching listener`),e.current.resubscribe=m,e.current.unsubscribe(),e.current.unsubscribe=m,e.current.isActive=!1}function Ir(e,t,n){return{selector:e,react:t,isActive:!1,options:Lr(n),resubscribe:m,unsubscribe:m}}function Lr(e){return typeof e==`function`?{equalityFn:e}:e??jr}function Rr(e){return typeof e==`function`?jr.enabled:e?.enabled??jr.enabled}function zr(e,t,n,r){e.current.selector=t,e.current.react=n,typeof r==`function`?e.current.options.equalityFn=r:r&&(e.current.options=r??jr)}const Br=Symbol();function Vr(e){let t=r(Br);return t.current===Br&&(t.current=e()),t.current}export{K as QueryStatuses,L as StoresError,pe as applyStateUpdate,re as configureStores,Tr as createBaseStore,Er as createDerivedStore,Dr as createQueryStore,Ae as createStoreActions,Or as createVirtualStore,Pe as deepEqual,de as defaultRetryDelay,J as destroyStore,xe as destroyStores,Gn as getQueryKey,Se as getStoreName,Te as hasGetSnapshot,d as identity,De as isDerivedStore,Oe as isPersistedStore,Ee as isQueryStore,ke as isVirtualStore,f as nullObject,Kn as parseQueryKey,Un as queryParam,_e as replacer,ve as reviver,Fe as shallowEqual,q as time,Mr as useListen,Vr as useStableValue};
|