{"version":3,"file":"storeMethods-DYgUGHSk.cjs","names":["deepEqual","isPlainObject","deepEqual","isAnyPath","makeSelector","deepEqual","strictEqual","createStore","makeSelector","isAnyPath","createStore"],"sources":["../src/lib/trackingProxy.ts","../src/react/lib/useMemoEquals.ts","../src/react/useStore.ts","../src/react/loadingBoundary.tsx","../src/react/useCache.ts","../src/react/cacheMethods.ts","../src/react/lib/useLatestRef.ts","../src/react/lib/useLatestFunction.ts","../src/react/useProp.ts","../src/react/scope.tsx","../src/react/scopeMethods.ts","../src/react/storeMethods.ts"],"sourcesContent":["import { deepEqual } from './equals';\nimport { isPlainObject } from '@lib/helpers';\n\nconst unwrapProxySymbol = /* @__PURE__ */ Symbol('unwrapProxy');\n\nexport type TrackingProxy<T> = [value: T, equals: (newValue: T) => boolean, revoke?: () => void];\ntype Object_ = Record<string | symbol, unknown>;\n\nexport function trackingProxy<T>(\n  value: T,\n  equals: (a: any, b: any) => boolean = deepEqual,\n): TrackingProxy<T> {\n  if (!isPlainObject(value) && !Array.isArray(value)) {\n    return [value, (other) => equals(value, other)];\n  }\n\n  // Unpack proxies, we don't want to nest them\n  value = (value as any)[unwrapProxySymbol] ?? value;\n\n  const deps = new Array<TrackingProxy<any>[1]>();\n  const revokations = new Array<() => void>();\n  let revoked = false;\n\n  function trackComplexProp(function_: any, ...args: any[]) {\n    const [proxiedValue, equals, revoke] = trackingProxy(function_(value, ...args));\n\n    deps.push((otherValue) => {\n      if (!isPlainObject(otherValue) && !Array.isArray(otherValue)) {\n        return false;\n      }\n\n      return equals(function_(otherValue, ...args));\n    });\n\n    if (revoke) {\n      revokations.push(revoke);\n    }\n\n    return proxiedValue;\n  }\n\n  function trackSimpleProp(function_: any, ...args: any[]) {\n    const calculatedValue = function_(value, ...args);\n\n    deps.push((otherValue) => {\n      return function_(otherValue, ...args) === calculatedValue;\n    });\n\n    return calculatedValue;\n  }\n\n  const proxy = new Proxy(value as T & Object_, {\n    get(target, p, receiver) {\n      if (p === unwrapProxySymbol) {\n        return value;\n      }\n\n      if (revoked) {\n        return target[p];\n      }\n\n      const { writable, configurable } = Object.getOwnPropertyDescriptor(target, p) ?? {};\n      if (writable === false && configurable === false) {\n        return target[p];\n      }\n\n      return trackComplexProp(Reflect.get, p, receiver);\n    },\n\n    getOwnPropertyDescriptor(target, p) {\n      const { writable, configurable } = Object.getOwnPropertyDescriptor(target, p) ?? {};\n      if (writable === false && configurable === false) {\n        return Reflect.getOwnPropertyDescriptor(target, p);\n      }\n\n      return trackComplexProp(Reflect.getOwnPropertyDescriptor, p);\n    },\n\n    ownKeys() {\n      return trackComplexProp(Reflect.ownKeys);\n    },\n\n    getPrototypeOf() {\n      return trackSimpleProp(Reflect.getPrototypeOf);\n    },\n\n    has(_target, p) {\n      return trackSimpleProp(Reflect.has, p);\n    },\n\n    isExtensible() {\n      return trackSimpleProp(Reflect.isExtensible);\n    },\n  });\n\n  return [\n    proxy,\n    (other) => !!other && deps.every((equals) => equals(other)),\n    () => {\n      revoked = true;\n      revokations.forEach((revoke) => revoke());\n    },\n  ];\n}\n","import { deepEqual } from '@lib/equals';\nimport { useEffect, useRef } from 'react';\n\nexport default function useMemoEquals<T>(value: T, equals: (a: T, b: T) => boolean = deepEqual): T {\n  const ref = useRef<{ value: T }>(undefined);\n  const hasChanged = !ref.current || !equals(ref.current.value, value);\n\n  useEffect(() => {\n    if (hasChanged) {\n      ref.current = { value };\n    }\n  });\n\n  return hasChanged ? value : ref.current!.value;\n}\n","import type { Selector, SubscribeOptions } from '@core/commonTypes';\nimport type { Store } from '@core/store';\nimport type { Constrain } from '@lib/constrain';\nimport { deepEqual, strictEqual } from '@lib/equals';\nimport { makeSelector } from '@lib/makeSelector';\nimport { isAnyPath, type AnyPath, type Path, type Value } from '@lib/path';\nimport { trackingProxy } from '@lib/trackingProxy';\nimport useMemoEquals from '@react/lib/useMemoEquals';\nimport {\n  useCallback,\n  useDebugValue,\n  useLayoutEffect,\n  useMemo,\n  useRef,\n  useSyncExternalStore,\n} from 'react';\n\nexport interface UseStoreOptions<T> extends Omit<SubscribeOptions, 'runNow' | 'passive'> {\n  /**\n   * If true, the cache content can be consumed but no fetch will be triggered.\n   * @default false\n   */\n\n  passive?: boolean;\n\n  /**\n   * (experimental) If true, the a rerender will only be triggered when a property of the returned value changes that was\n   * actually accessed during the last render.\n   * @default false\n   */\n  enableTrackingProxy?: boolean;\n\n  /**\n   * (experimental) If provided, a rerender will be wrapped in a browser view transition.\n   */\n  withViewTransition?: boolean | ((value: T) => unknown);\n}\n\nexport interface UseStoreOptionsWithSelector<T, S> extends UseStoreOptions<S> {\n  /**\n   * Equality function to compare the raw store values before reevaluating the selector.\n   * Can be used to avoid unnecessary selector evaluations.\n   * @default strictEqual\n   */\n  storeValueEquals?: (newValue: T, oldValue: T) => boolean;\n}\n\nexport function useStore<T, S>(\n  store: Store<T>,\n  selector: Selector<T, S>,\n  option?: UseStoreOptionsWithSelector<T, S>,\n): S;\n\nexport function useStore<T, const P>(\n  store: Store<T>,\n  selector: Constrain<P, Path<T>>,\n  option?: UseStoreOptionsWithSelector<T, Value<T, P>>,\n): Value<T, P>;\n\nexport function useStore<T>(store: Store<T>, option?: UseStoreOptions<T>): T;\n\nexport function useStore<T, S>(\n  store: Store<T>,\n  ...args:\n    | [Selector<T, S> | AnyPath, UseStoreOptionsWithSelector<T, S>?]\n    | [UseStoreOptionsWithSelector<T, S>?]\n): S {\n  let selectorRaw: Selector<T, S> | AnyPath | undefined;\n  let allOptions: UseStoreOptionsWithSelector<T, S>;\n\n  if (typeof args[0] === 'function' || isAnyPath(args[0])) {\n    selectorRaw = args[0];\n    allOptions = args[1] ?? {};\n  } else {\n    allOptions = args[0] ?? {};\n  }\n\n  const selectorMemoized = useMemoEquals(selectorRaw);\n  const selector = useMemo(() => makeSelector<T, S>(selectorMemoized), [selectorMemoized]);\n  const lastEqualsRef = useRef<(newValue: S) => boolean | undefined>(undefined);\n\n  const {\n    enableTrackingProxy,\n    equals = store.options.equals ?? deepEqual,\n    withViewTransition,\n    storeValueEquals = strictEqual,\n    ...options\n  } = allOptions;\n\n  const snapshot = useRef<{ storeValue: T; selector: (value: T) => S; selectedValue: S }>(\n    undefined,\n  );\n\n  const get = useCallback(() => {\n    const storeValue = store.get();\n\n    if (\n      snapshot.current &&\n      storeValueEquals(storeValue, snapshot.current.storeValue) &&\n      selector === snapshot.current.selector\n    ) {\n      return snapshot.current.selectedValue;\n    }\n\n    const selectedValue = selector(storeValue);\n    if (!(lastEqualsRef.current?.(selectedValue) ?? false)) {\n      snapshot.current = { storeValue, selector, selectedValue };\n    }\n\n    return snapshot.current!.selectedValue;\n  }, [store, storeValueEquals, selector]);\n\n  const rootStore = store.derivedFrom?.store ?? store;\n  const subOptions = useMemoEquals({ ...options, runNow: false });\n\n  const subscribe = useCallback(\n    (listener: () => void) => {\n      let _listener: (value: any) => void = listener;\n      let stopped = false;\n\n      if (withViewTransition && (document as any).startViewTransition) {\n        let lastObservedValue: any;\n\n        _listener = (value: any) => {\n          const observedValue =\n            withViewTransition instanceof Function ? withViewTransition(value) : value;\n\n          if (equals(lastObservedValue, observedValue)) {\n            listener();\n            return;\n          }\n\n          lastObservedValue = observedValue;\n\n          let hasChanges = false;\n          const mutationObserver = new MutationObserver(() => {\n            hasChanges = true;\n            mutationObserver.disconnect();\n          });\n          mutationObserver.observe(document.body, { childList: true, subtree: true });\n\n          (document as any).startViewTransition(() => {\n            mutationObserver.disconnect();\n\n            if (!stopped) {\n              listener();\n            }\n\n            if (!hasChanges) {\n              throw new Error('no change');\n            }\n          });\n        };\n      }\n\n      const cancel = rootStore.subscribe(_listener, subOptions);\n      return () => {\n        stopped = true;\n        cancel();\n      };\n    },\n    [rootStore, withViewTransition, equals, subOptions],\n  );\n\n  let value = useSyncExternalStore<S>(subscribe, get, get);\n  let lastEquals = (newValue: S) => equals(newValue, value);\n  let revoke: (() => void) | undefined;\n\n  if (enableTrackingProxy) {\n    [value, lastEquals, revoke] = trackingProxy(value, equals);\n  }\n\n  useLayoutEffect(() => {\n    lastEqualsRef.current = lastEquals;\n    revoke?.();\n  });\n\n  useDebugValue(value);\n  return value;\n}\n","import { createStore } from '@core';\nimport { useStore } from '@react/useStore';\nimport { createContext, useContext, useLayoutEffect, useMemo, type ReactNode } from 'react';\n\nexport interface LoadingBoundaryEntry {\n  label?: ReactNode;\n}\n\nexport interface LoadingBoundaryProps {\n  /**\n   * Fallback node to render when there are loading components within the boundary.\n   */\n  fallback?: ReactNode | ((entries: LoadingBoundaryEntry[]) => ReactNode);\n\n  /**\n   * Child node to render when there are no loading components within the boundary.\n   */\n  children?: ReactNode;\n\n  /**\n   * Add a loading state from outside the boundary. Useful for when you want to\n   * show a loading state for a component that is not a child of the boundary.\n   */\n  isLoading?: boolean;\n}\n\nconst LoadingBoundaryContext = createContext(createStore(new Set<LoadingBoundaryEntry>()));\n\nexport function LoadingBoundary({\n  fallback,\n  children,\n  isLoading: isLoadingExternal,\n}: LoadingBoundaryProps): React.JSX.Element {\n  const store = useMemo(() => createStore(new Set<LoadingBoundaryEntry>()), []);\n  const entries = useStore(store);\n  const isLoading = entries.size > 0 || isLoadingExternal;\n\n  const fallbackNode = isLoading\n    ? typeof fallback === 'function'\n      ? fallback([...entries])\n      : fallback\n    : undefined;\n\n  return (\n    <LoadingBoundaryContext.Provider value={store}>\n      {fallbackNode !== undefined ? (\n        <>\n          {fallbackNode}\n          <div style={{ display: 'none' }}>{children}</div>\n        </>\n      ) : (\n        children\n      )}\n    </LoadingBoundaryContext.Provider>\n  );\n}\n\nexport function useLoadingBoundary(isLoading: boolean | undefined, label?: ReactNode): void {\n  const store = useContext(LoadingBoundaryContext);\n\n  useLayoutEffect(() => {\n    if (!isLoading) {\n      return;\n    }\n\n    const entry = { label };\n    store.set((entries) => new Set(entries).add(entry));\n\n    return () => {\n      store.set((entries) => {\n        const newEntries = new Set(entries);\n        newEntries.delete(entry);\n        return newEntries;\n      });\n    };\n    // oxlint-disable-next-line exhaustive-deps\n  }, [store, isLoading]);\n}\n","import { useStore, type UseStoreOptions } from './useStore';\nimport type { Cache } from '@core';\nimport type { CacheState } from '@lib/cacheState';\nimport { makeSelector } from '@lib/makeSelector';\nimport { useLoadingBoundary } from '@react/loadingBoundary';\nimport { useEffect, useMemo, useRef } from 'react';\n\nexport type UseCacheArray<T> = [\n  value: T | undefined,\n  error: unknown | undefined,\n  isUpdating: boolean,\n  isStale: boolean,\n];\n\nexport type UseCacheValue<T> = UseCacheArray<T> & CacheState<T>;\n\nexport interface UseCacheOptions<T> extends UseStoreOptions<UseCacheArray<T> & CacheState<T>> {\n  /**\n   * If true, will always return undefined as value and no fetch will be triggered.\n   * @default false\n   */\n  disabled?: boolean;\n\n  /**\n   * If true, the cache will be invalidated when the component mounts.\n   * @default false\n   */\n  updateOnMount?: boolean;\n\n  /**\n   * If true, `useCache` will throw a promise when the cache is pending. This can be used with React Suspense.\n   * @see https://react.dev/reference/react/Suspense\n   * @default false\n   */\n  suspense?: boolean;\n\n  /**\n   * If true, `useCache` will register its loading state with the nearest `LoadingBoundary`.\n   * @default false\n   */\n  loadingBoundary?: boolean;\n}\n\nexport function useCache<T>(\n  cache: Cache<T, any>,\n  {\n    passive,\n    disabled,\n    updateOnMount,\n    withViewTransition,\n    suspense,\n    loadingBoundary,\n    ...options\n  }: UseCacheOptions<T> = {},\n): UseCacheValue<T> {\n  if (withViewTransition === true) {\n    withViewTransition = (state) => state.value;\n  }\n\n  const { rootCache, selector } = useMemo(() => {\n    const rootCache: Cache<any, any> = cache.derivedFromCache?.cache ?? cache;\n    let selector = (x: any) => x;\n\n    if (cache.derivedFromCache) {\n      selector = (value: any) => {\n        for (const s of cache.derivedFromCache!.selectors) {\n          value = makeSelector(s)(value);\n        }\n        return value;\n      };\n    }\n\n    return { rootCache, selector };\n  }, [cache]);\n\n  const hasMounted = useRef(false);\n\n  useEffect(() => {\n    hasMounted.current = true;\n\n    if (updateOnMount) {\n      rootCache.invalidate();\n    }\n    // oxlint-disable-next-line exhaustive-deps\n  }, []);\n\n  const result = useStore(\n    rootCache.state,\n    (state) => {\n      if (disabled) {\n        return Object.assign<UseCacheArray<T>, CacheState<T>>(\n          [undefined, undefined, false, false],\n          { status: 'pending', isUpdating: false, isStale: false, isConnected: false },\n        );\n      }\n\n      const isStale = updateOnMount && !hasMounted.current ? true : state.isStale;\n      try {\n        const value = state.status === 'value' ? selector(state.value) : undefined;\n\n        return Object.assign<UseCacheArray<T>, CacheState<T>>(\n          [value, state.error, state.isUpdating, isStale],\n          { ...state, value, isStale },\n        );\n      } catch (error) {\n        return Object.assign<UseCacheArray<T>, CacheState<T>>(\n          [undefined, error, state.isUpdating, isStale],\n          {\n            status: 'error',\n            error,\n            isUpdating: state.isUpdating,\n            isStale: isStale,\n            isConnected: state.isConnected,\n          },\n        );\n      }\n    },\n    { ...options, withViewTransition, passive: passive || disabled },\n  );\n\n  useEffect(\n    () => rootCache.subscribe(() => undefined, { passive: passive || disabled }),\n    [rootCache, passive, disabled],\n  );\n\n  useLoadingBoundary(loadingBoundary && !disabled && result.status === 'pending');\n\n  if (suspense && result.status === 'pending') {\n    throw rootCache.get();\n  }\n\n  return result;\n}\n","import type { Cache } from '@core';\nimport { type UseCacheOptions, type UseCacheValue, useCache } from '@react/useCache';\n\nexport const cacheMethods = {\n  useCache<T>(this: Cache<T, any>, options?: UseCacheOptions<T>): UseCacheValue<T> {\n    return useCache(this, options);\n  },\n};\n","import { useRef } from 'react';\n\nexport default function useLatestRef<T>(value: T): { current: T } {\n  const ref = useRef(value);\n  ref.current = value;\n  return ref;\n}\n","import useLatestRef from '@react/lib/useLatestRef';\nimport { useCallback } from 'react';\n\nexport default function useLatestFunction<Args extends any[], R>(\n  fn: (...args: Args) => R,\n): (...args: Args) => R {\n  const ref = useLatestRef(fn);\n\n  return useCallback(\n    (...args: Args) => {\n      return ref.current(...args);\n    },\n    [ref],\n  );\n}\n","import { useStore, type UseStoreOptions } from './useStore';\nimport { type Selector, type Update } from '@core/commonTypes';\nimport type { Store } from '@core/store';\nimport type { Constrain } from '@lib/constrain';\nimport { isAnyPath, type AnyPath, type SettablePath, type Value } from '@lib/path';\nimport useLatestFunction from '@react/lib/useLatestFunction';\n\nexport function useProp<T, S>(\n  store: Store<T>,\n  selector: Selector<T, S>,\n  updater: (value: S) => Update<T>,\n  options?: UseStoreOptions<S>,\n): [value: S, setValue: Store<S>['set']];\n\nexport function useProp<T, const P>(\n  store: Store<T>,\n  selector: Constrain<P, SettablePath<T>>,\n  options?: UseStoreOptions<Value<T, P>>,\n): [value: Value<T, P>, setValue: Store<Value<T, P>>['set']];\n\nexport function useProp<T>(\n  store: Store<T>,\n  options?: UseStoreOptions<T>,\n): [value: T, setValue: Store<T>['set']];\n\nexport function useProp<T, S>(\n  store: Store<T>,\n  ...args:\n    | [Selector<T, S>, (value: S) => Update<T>, UseStoreOptions<S>?]\n    | [AnyPath, UseStoreOptions<Value<T, any>>?]\n    | [UseStoreOptions<S>?]\n): [value: S, setValue: Store<S>['set']] {\n  let selector: Selector<T, S> | AnyPath | undefined;\n  let updater: ((value: S) => Update<T>) | undefined;\n  let options: UseStoreOptions<S> | undefined;\n\n  if (typeof args[0] === 'function' || isAnyPath(args[0])) {\n    selector = args[0];\n    if (typeof args[1] === 'function') {\n      updater = args[1];\n      options = args[2];\n    } else {\n      options = args[1];\n    }\n  } else {\n    options = args[0];\n  }\n\n  const value = useStore(store, (selector ?? ((x) => x)) as Selector<T, S>, options);\n\n  const update = useLatestFunction((update) => {\n    let _store: Store<any> = store;\n    if (selector) {\n      _store = _store.map(selector as Selector<any, any>, updater);\n    }\n\n    _store.set(update);\n  });\n\n  return [value, update];\n}\n","import { useProp } from './useProp';\nimport { useStore, type UseStoreOptions } from './useStore';\nimport type { Scope, Selector, Update } from '@core';\nimport { createStore, type Store } from '@core/store';\nimport type { Constrain } from '@lib/constrain';\nimport type { Path, Value } from '@lib/path';\nimport { createContext, useContext, useMemo, type Context, type ReactNode } from 'react';\n\nexport type ScopeProps<T> = { scope: Scope<T>; store?: Store<T>; children?: ReactNode };\n\ndeclare module '..' {\n  interface Scope<T> {\n    context?: Context<Store<T>>;\n  }\n}\n\nfunction getScopeContext<T>(scope: Scope<T>): Context<Store<T>> {\n  scope.context ??= createContext<Store<T>>(createStore(scope.defaultValue));\n  return scope.context;\n}\n\nexport function ScopeProvider<T>({\n  scope,\n  store: inputStore,\n  children,\n}: ScopeProps<T>): React.JSX.Element {\n  const context = getScopeContext(scope);\n  const currentStore = useMemo(\n    () => inputStore ?? createStore(scope.defaultValue),\n    [scope, inputStore],\n  );\n\n  return <context.Provider value={currentStore}>{children}</context.Provider>;\n}\n\nexport function useScope<T>(scope: Scope<T>): Store<T> {\n  const context = getScopeContext(scope);\n  return useContext(context);\n}\n\nexport function useScopeStore<T, S>(\n  scope: Scope<T>,\n  selector: Selector<T, S>,\n  option?: UseStoreOptions<S>,\n): S;\n\nexport function useScopeStore<T, const P>(\n  scope: Scope<T>,\n  selector: Constrain<P, Path<T>>,\n  option?: UseStoreOptions<Value<T, P>>,\n): Value<T, P>;\n\nexport function useScopeStore<T>(scope: Scope<T>, option?: UseStoreOptions<T>): T;\n\nexport function useScopeStore<T>(scope: Scope<T>, ...args: any[]): T {\n  const store = useScope(scope);\n  return useStore(store, ...args);\n}\n\nexport function useScopeProp<T, S>(\n  scope: Scope<T>,\n  selector: Selector<T, S>,\n  updater: (value: S) => Update<T>,\n  options?: UseStoreOptions<S>,\n): [value: S, setValue: Store<S>['set']];\n\nexport function useScopeProp<T, const P>(\n  scope: Scope<T>,\n  selector: Constrain<P, Path<T>>,\n  options?: UseStoreOptions<Value<T, P>>,\n): [value: Value<T, P>, setValue: Store<Value<T, P>>['set']];\n\nexport function useScopeProp<T>(\n  scope: Scope<T>,\n  options?: UseStoreOptions<T>,\n): [value: T, setValue: Store<T>['set']];\n\nexport function useScopeProp<T>(\n  scope: Scope<T>,\n  ...args: any[]\n): [value: T, setValue: Store<T>['set']] {\n  const store = useScope(scope);\n  return useProp(store, ...args);\n}\n","import type { Scope, Selector, Store, Update } from '@core';\nimport type { Constrain } from '@lib/constrain';\nimport type { Path, Value } from '@lib/path';\nimport {\n  ScopeProvider,\n  useScope,\n  useScopeProp,\n  useScopeStore,\n  type ScopeProps,\n} from '@react/scope';\nimport type { UseStoreOptions } from '@react/useStore';\n\nfunction boundUseScope<T>(this: Scope<T>): Store<T> {\n  return useScope(this);\n}\n\nfunction boundUseScopeStore<T, S>(\n  this: Scope<T>,\n  selector: Selector<T, S>,\n  option?: UseStoreOptions<S>,\n): S;\n\nfunction boundUseScopeStore<T, const P>(\n  this: Scope<T>,\n  selector: Constrain<P, Path<T>>,\n  option?: UseStoreOptions<Value<T, P>>,\n): Value<T, P>;\n\nfunction boundUseScopeStore<T>(this: Scope<T>, option?: UseStoreOptions<T>): T;\n\nfunction boundUseScopeStore(this: Scope<any>, ...args: any[]) {\n  return useScopeStore(this, ...args);\n}\n\nfunction boundUseScopeProp<T, S>(\n  this: Scope<T>,\n  selector: Selector<T, S>,\n  updater: (value: S) => Update<T>,\n  options?: UseStoreOptions<S>,\n): [value: S, setValue: Store<S>['set']];\n\nfunction boundUseScopeProp<T, const P>(\n  this: Scope<T>,\n  selector: Constrain<P, Path<T>>,\n  options?: UseStoreOptions<Value<T, P>>,\n): [value: Value<T, P>, setValue: Store<Value<T, P>>['set']];\n\nfunction boundUseScopeProp<T>(\n  this: Scope<T>,\n  options?: UseStoreOptions<T>,\n): [value: T, setValue: Store<T>['set']];\n\nfunction boundUseScopeProp(this: Scope<any>, ...args: any[]) {\n  return useScopeProp(this, ...args);\n}\n\nfunction Provider<T>(this: Scope<T>, props: Omit<ScopeProps<T>, 'scope'>): React.JSX.Element {\n  return ScopeProvider({ ...props, scope: this });\n}\n\nexport const scopeMethods: {\n  useScope: typeof boundUseScope;\n  useStore: typeof boundUseScopeStore;\n  useProp: typeof boundUseScopeProp;\n  Provider: typeof Provider;\n} = {\n  useScope: boundUseScope,\n  useStore: boundUseScopeStore,\n  useProp: boundUseScopeProp,\n  Provider,\n};\n","import type { Selector, Store, Update } from '@core';\nimport type { Constrain } from '@lib/constrain';\nimport type { Path, Value } from '@lib/path';\nimport { useProp } from '@react/useProp';\nimport { type UseStoreOptions, useStore } from '@react/useStore';\n\nfunction boundUseStore<T, S>(\n  this: Store<T>,\n  selector: Selector<T, S>,\n  option?: UseStoreOptions<S>,\n): S;\nfunction boundUseStore<T, const P>(\n  this: Store<T>,\n  selector: Constrain<P, Path<T>>,\n  option?: UseStoreOptions<Value<T, P>>,\n): Value<T, P>;\nfunction boundUseStore<T>(this: Store<T>, option?: UseStoreOptions<T>): T;\nfunction boundUseStore(this: Store<any>, ...args: any[]) {\n  return useStore(this, ...args);\n}\n\nfunction boundUseProp<T, S>(\n  this: Store<T>,\n  selector: Selector<T, S>,\n  updater: (value: S) => Update<T>,\n  options?: UseStoreOptions<S>,\n): [value: S, setValue: Store<S>['set']];\nfunction boundUseProp<T, const P>(\n  this: Store<T>,\n  selector: Constrain<P, Path<T>>,\n  options?: UseStoreOptions<Value<T, P>>,\n): [value: Value<T, P>, setValue: Store<Value<T, P>>['set']];\nfunction boundUseProp<T>(\n  this: Store<T>,\n  options?: UseStoreOptions<T>,\n): [value: T, setValue: Store<T>['set']];\nfunction boundUseProp(this: Store<any>, ...args: any[]) {\n  return useProp(this, ...args);\n}\n\nexport const storeMethods: {\n  useStore: typeof boundUseStore;\n  useProp: typeof boundUseProp;\n} = {\n  useStore: boundUseStore,\n  useProp: boundUseProp,\n};\n"],"mappings":";;;;;;;AAGA,MAAM,oBAAoC,uBAAO,aAAa;AAK9D,SAAgB,cACd,OACA,SAAsCA,8BACpB;CAClB,IAAI,CAACC,iCAAc,KAAK,KAAK,CAAC,MAAM,QAAQ,KAAK,GAC/C,OAAO,CAAC,QAAQ,UAAU,OAAO,OAAO,KAAK,CAAC;CAIhD,QAAS,MAAc,sBAAsB;CAE7C,MAAM,OAAO,IAAI,MAA6B;CAC9C,MAAM,cAAc,IAAI,MAAkB;CAC1C,IAAI,UAAU;CAEd,SAAS,iBAAiB,WAA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