import "./chunk-4CSS7JW7.js"; import "./chunk-VAL2CHZC.js"; import { readonly, ref, toRaw, watch } from "./chunk-AAHVYXXY.js"; import "./chunk-OWZYVOTZ.js"; import "./chunk-V4OQ3NZ2.js"; // ../node_modules/.pnpm/@tanstack+store@0.7.7/node_modules/@tanstack/store/dist/esm/scheduler.js var __storeToDerived = /* @__PURE__ */ new WeakMap(); var __derivedToStore = /* @__PURE__ */ new WeakMap(); var __depsThatHaveWrittenThisTick = { current: [] }; var __isFlushing = false; var __batchDepth = 0; var __pendingUpdates = /* @__PURE__ */ new Set(); var __initialBatchValues = /* @__PURE__ */ new Map(); function __flush_internals(relatedVals) { const sorted = Array.from(relatedVals).sort((a, b) => { if (a instanceof Derived && a.options.deps.includes(b)) return 1; if (b instanceof Derived && b.options.deps.includes(a)) return -1; return 0; }); for (const derived of sorted) { if (__depsThatHaveWrittenThisTick.current.includes(derived)) { continue; } __depsThatHaveWrittenThisTick.current.push(derived); derived.recompute(); const stores = __derivedToStore.get(derived); if (stores) { for (const store of stores) { const relatedLinkedDerivedVals = __storeToDerived.get(store); if (!relatedLinkedDerivedVals) continue; __flush_internals(relatedLinkedDerivedVals); } } } } function __notifyListeners(store) { const value = { prevVal: store.prevState, currentVal: store.state }; for (const listener of store.listeners) { listener(value); } } function __notifyDerivedListeners(derived) { const value = { prevVal: derived.prevState, currentVal: derived.state }; for (const listener of derived.listeners) { listener(value); } } function __flush(store) { if (__batchDepth > 0 && !__initialBatchValues.has(store)) { __initialBatchValues.set(store, store.prevState); } __pendingUpdates.add(store); if (__batchDepth > 0) return; if (__isFlushing) return; try { __isFlushing = true; while (__pendingUpdates.size > 0) { const stores = Array.from(__pendingUpdates); __pendingUpdates.clear(); for (const store2 of stores) { const prevState = __initialBatchValues.get(store2) ?? store2.prevState; store2.prevState = prevState; __notifyListeners(store2); } for (const store2 of stores) { const derivedVals = __storeToDerived.get(store2); if (!derivedVals) continue; __depsThatHaveWrittenThisTick.current.push(store2); __flush_internals(derivedVals); } for (const store2 of stores) { const derivedVals = __storeToDerived.get(store2); if (!derivedVals) continue; for (const derived of derivedVals) { __notifyDerivedListeners(derived); } } } } finally { __isFlushing = false; __depsThatHaveWrittenThisTick.current = []; __initialBatchValues.clear(); } } function batch(fn) { __batchDepth++; try { fn(); } finally { __batchDepth--; if (__batchDepth === 0) { const pendingUpdateToFlush = __pendingUpdates.values().next().value; if (pendingUpdateToFlush) { __flush(pendingUpdateToFlush); } } } } // ../node_modules/.pnpm/@tanstack+store@0.7.7/node_modules/@tanstack/store/dist/esm/types.js function isUpdaterFunction(updater) { return typeof updater === "function"; } // ../node_modules/.pnpm/@tanstack+store@0.7.7/node_modules/@tanstack/store/dist/esm/store.js var Store = class { constructor(initialState, options) { this.listeners = /* @__PURE__ */ new Set(); this.subscribe = (listener) => { var _a, _b; this.listeners.add(listener); const unsub = (_b = (_a = this.options) == null ? void 0 : _a.onSubscribe) == null ? void 0 : _b.call(_a, listener, this); return () => { this.listeners.delete(listener); unsub == null ? void 0 : unsub(); }; }; this.prevState = initialState; this.state = initialState; this.options = options; } setState(updater) { var _a, _b, _c; this.prevState = this.state; if ((_a = this.options) == null ? void 0 : _a.updateFn) { this.state = this.options.updateFn(this.prevState)(updater); } else { if (isUpdaterFunction(updater)) { this.state = updater(this.prevState); } else { this.state = updater; } } (_c = (_b = this.options) == null ? void 0 : _b.onUpdate) == null ? void 0 : _c.call(_b); __flush(this); } }; // ../node_modules/.pnpm/@tanstack+store@0.7.7/node_modules/@tanstack/store/dist/esm/derived.js var Derived = class _Derived { constructor(options) { this.listeners = /* @__PURE__ */ new Set(); this._subscriptions = []; this.lastSeenDepValues = []; this.getDepVals = () => { const l = this.options.deps.length; const prevDepVals = new Array(l); const currDepVals = new Array(l); for (let i = 0; i < l; i++) { const dep = this.options.deps[i]; prevDepVals[i] = dep.prevState; currDepVals[i] = dep.state; } this.lastSeenDepValues = currDepVals; return { prevDepVals, currDepVals, prevVal: this.prevState ?? void 0 }; }; this.recompute = () => { var _a, _b; this.prevState = this.state; const depVals = this.getDepVals(); this.state = this.options.fn(depVals); (_b = (_a = this.options).onUpdate) == null ? void 0 : _b.call(_a); }; this.checkIfRecalculationNeededDeeply = () => { for (const dep of this.options.deps) { if (dep instanceof _Derived) { dep.checkIfRecalculationNeededDeeply(); } } let shouldRecompute = false; const lastSeenDepValues = this.lastSeenDepValues; const { currDepVals } = this.getDepVals(); for (let i = 0; i < currDepVals.length; i++) { if (currDepVals[i] !== lastSeenDepValues[i]) { shouldRecompute = true; break; } } if (shouldRecompute) { this.recompute(); } }; this.mount = () => { this.registerOnGraph(); this.checkIfRecalculationNeededDeeply(); return () => { this.unregisterFromGraph(); for (const cleanup of this._subscriptions) { cleanup(); } }; }; this.subscribe = (listener) => { var _a, _b; this.listeners.add(listener); const unsub = (_b = (_a = this.options).onSubscribe) == null ? void 0 : _b.call(_a, listener, this); return () => { this.listeners.delete(listener); unsub == null ? void 0 : unsub(); }; }; this.options = options; this.state = options.fn({ prevDepVals: void 0, prevVal: void 0, currDepVals: this.getDepVals().currDepVals }); } registerOnGraph(deps = this.options.deps) { for (const dep of deps) { if (dep instanceof _Derived) { dep.registerOnGraph(); this.registerOnGraph(dep.options.deps); } else if (dep instanceof Store) { let relatedLinkedDerivedVals = __storeToDerived.get(dep); if (!relatedLinkedDerivedVals) { relatedLinkedDerivedVals = /* @__PURE__ */ new Set(); __storeToDerived.set(dep, relatedLinkedDerivedVals); } relatedLinkedDerivedVals.add(this); let relatedStores = __derivedToStore.get(this); if (!relatedStores) { relatedStores = /* @__PURE__ */ new Set(); __derivedToStore.set(this, relatedStores); } relatedStores.add(dep); } } } unregisterFromGraph(deps = this.options.deps) { for (const dep of deps) { if (dep instanceof _Derived) { this.unregisterFromGraph(dep.options.deps); } else if (dep instanceof Store) { const relatedLinkedDerivedVals = __storeToDerived.get(dep); if (relatedLinkedDerivedVals) { relatedLinkedDerivedVals.delete(this); } const relatedStores = __derivedToStore.get(this); if (relatedStores) { relatedStores.delete(dep); } } } } }; // ../node_modules/.pnpm/@tanstack+store@0.7.7/node_modules/@tanstack/store/dist/esm/effect.js var Effect = class { constructor(opts) { const { eager, fn, ...derivedProps } = opts; this._derived = new Derived({ ...derivedProps, fn: () => { }, onUpdate() { fn(); } }); if (eager) { fn(); } } mount() { return this._derived.mount(); } }; // ../node_modules/.pnpm/@tanstack+vue-store@0.7.7_vue@3.5.24_typescript@5.9.3_/node_modules/@tanstack/vue-store/dist/esm/index.js function useStore(store, selector = (d) => d) { const slice = ref(selector(store.state)); watch( () => store, (value, _oldValue, onCleanup) => { const unsub = value.subscribe(() => { const data = selector(value.state); if (shallow(toRaw(slice.value), data)) { return; } slice.value = data; }); onCleanup(() => { unsub(); }); }, { immediate: true } ); return readonly(slice); } function shallow(objA, objB) { if (Object.is(objA, objB)) { return true; } if (typeof objA !== "object" || objA === null || typeof objB !== "object" || objB === null) { return false; } if (objA instanceof Map && objB instanceof Map) { if (objA.size !== objB.size) return false; for (const [k, v] of objA) { if (!objB.has(k) || !Object.is(v, objB.get(k))) return false; } return true; } if (objA instanceof Set && objB instanceof Set) { if (objA.size !== objB.size) return false; for (const v of objA) { if (!objB.has(v)) return false; } return true; } if (objA instanceof Date && objB instanceof Date) { if (objA.getTime() !== objB.getTime()) return false; return true; } const keysA = Object.keys(objA); if (keysA.length !== Object.keys(objB).length) { return false; } for (let i = 0; i < keysA.length; i++) { if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) { return false; } } return true; } export { Derived, Effect, Store, __depsThatHaveWrittenThisTick, __derivedToStore, __flush, __storeToDerived, batch, isUpdaterFunction, shallow, useStore }; //# sourceMappingURL=@tanstack_vue-store.js.map