{"version":3,"file":"create-selectors.cjs","names":[],"sources":["../../src/store/create-selectors.ts"],"sourcesContent":["import type { StoreApi, UseBoundStore } from \"zustand\";\n\n/**\n * A bound Zustand hook augmented with auto-generated per-field selector hooks\n * under `.use`. Reading a single field via `store.use.field()` subscribes the\n * component only to that field, avoiding re-renders when unrelated slices change.\n */\nexport type WithSelectors<S> = S extends { getState: () => infer T }\n    ? S & { use: { [K in keyof T]: () => T[K] } }\n    : never;\n\n/**\n * Attach auto-generated selector hooks to a Zustand store. Instead of writing\n * `useStore((s) => s.user)` at every call site, you get `useStore.use.user()`\n * — one memoized selector per top-level state key.\n *\n * @typeParam S - The bound store hook type returned by `create`/{@link createStore}.\n * @param store - The bound Zustand hook.\n * @returns The same hook with a `.use` namespace of field selectors.\n *\n * @example\n * const useCart = createSelectors(\n *     createStore<CartState>((set) => ({ items: [], add: (id) => ... })),\n * );\n * const items = useCart.use.items(); // subscribes only to `items`\n */\nexport function createSelectors<S extends UseBoundStore<StoreApi<object>>>(\n    store: S,\n): WithSelectors<S> {\n    const bound = store as WithSelectors<S>;\n    bound.use = {} as WithSelectors<S>[\"use\"];\n    for (const key of Object.keys(store.getState())) {\n        (bound.use as Record<string, () => unknown>)[key] = () =>\n            store((state) => (state as Record<string, unknown>)[key]);\n    }\n    return bound;\n}\n"],"mappings":"AA0BA,SAAgB,EACZ,EACgB,CAChB,IAAM,EAAQ,EACd,EAAM,IAAM,CAAC,EACb,IAAK,IAAM,KAAO,OAAO,KAAK,EAAM,SAAS,CAAC,EAC1C,EAAO,IAAsC,OACzC,EAAO,GAAW,EAAkC,EAAI,EAEhE,OAAO,CACX"}