{"version":3,"sources":["jsdelivr-header.js","/home/runner/work/reactive/reactive/packages/reactive/dist/index.js","/npm/@shined/reactive@0.3.5/src/enhancers/react/with-use-derived.ts","/npm/@shined/reactive@0.3.5/src/react/use-reactive.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,49BCLE,gBACA,YACA,aACA,gBACA,qBACK,6BAEL,cACA,UACA,SACA,YACA,QACA,WACA,IACA,sBACA,SACA,UACA,YACA,aACA,kBACK,sBC0BA,SAAS,eACd,G,IACA,yDAA6C,SAAC,G,OAAM,C,EAIpD,OAAO,qBAAA,eAAA,GAFkB,YAA4B,EAAO,IAGvD,CACH,WAAY,W,IAAC,yDAAoC,CAAC,EAChD,OAAO,YAAsC,EAAM,OAAQ,EAAO,EACpE,GAEJ,QC3DS,WAAc,QAchB,SAAS,YACd,G,IACA,yDAAqC,CAAC,EAEhC,EAAQ,aAAY,W,OAAM,gBAAgB,E,GAAe,CAAC,IAChE,MAAO,CAAC,EAAM,YAAY,eAAA,GAAK,IAAY,EAAM,OACnD,CAQA,SAAS,YAAe,EAAiB,GACvC,IAAQ,EAAsB,OAA4B,CAAC,GAAnD,QAQR,OANK,EAAS,SAAY,UAAU,EAAS,QAAS,KACpD,EAAS,MAAQ,IACjB,EAAS,SAAU,EACnB,EAAS,QAAU,GAGd,EAAS,KAClB,QFYE,0BACA,cACA,SACA,YACA,QACA,WACA,IACA,sBACA,SACA,UACA,YACA,YACA,aACA,YACA,aACA,cACA,eACA,gBACA","file":"/npm/@shined/reactive@0.3.5/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@shined/reactive@0.3.5/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import {\n  createWithHooks,\n  useSnapshot,\n  useSubscribe,\n  withUseSnapshot,\n  withUseSubscribe\n} from \"./chunk-XDJMLCSF.js\";\nimport {\n  createVanilla,\n  deepEqual,\n  devtools,\n  getSnapshot,\n  produce,\n  proxyCount,\n  ref,\n  setGlobalNotifyInSync,\n  snapshot,\n  subscribe,\n  withDerived,\n  withSnapshot,\n  withSubscribe\n} from \"./chunk-22VVHX5B.js\";\n\n// src/enhancers/react/with-use-derived.ts\nfunction withUseDerived(store, mapFn = (s) => s) {\n  const storeWithDerived = withDerived(store, mapFn);\n  return {\n    ...storeWithDerived,\n    useDerived: (options = {}) => {\n      return useSnapshot(store.mutate, mapFn, options);\n    }\n  };\n}\n\n// src/react/use-reactive.ts\nimport { useRef } from \"react\";\nfunction useReactive(initialState, options = {}) {\n  const store = useCreation(() => createWithHooks(initialState), [initialState]);\n  return [store.useSnapshot({ ...options }), store.mutate];\n}\nfunction useCreation(create, currDeps) {\n  const { current: creation } = useRef({});\n  if (!creation.created || !deepEqual(creation.preDeps, currDeps)) {\n    creation.value = create();\n    creation.created = true;\n    creation.preDeps = currDeps;\n  }\n  return creation.value;\n}\nexport {\n  createWithHooks as create,\n  createVanilla,\n  devtools,\n  getSnapshot,\n  produce,\n  proxyCount,\n  ref,\n  setGlobalNotifyInSync,\n  snapshot,\n  subscribe,\n  useReactive,\n  useSnapshot,\n  useSubscribe,\n  withDerived,\n  withSnapshot,\n  withSubscribe,\n  withUseDerived,\n  withUseSnapshot,\n  withUseSubscribe\n};\n","import { useSnapshot } from '../../react/use-snapshot.js'\nimport { withDerived } from '../vanilla/with-derived.js'\n\nimport type { SnapshotOptions } from '../../react/use-snapshot.js'\nimport type { VanillaStore } from '../../vanilla/index.js'\nimport type { WithDerivedContributes } from '../vanilla/with-derived.js'\n\nexport interface WithUseDerivedContributes<State extends object, Derived extends object = State>\n  extends WithDerivedContributes<State, Derived> {\n  /**\n   * Get the derived state.\n   */\n  useDerived: (options?: SnapshotOptions<Derived>) => Derived\n}\n\n/**\n * Enhances a store with `useDerived` & `derived` method that returns the derived state.\n * \n * @param store - The store to enhance.\n * @param mapFn - The function to map the state to the derived state.\n * @returns The enhanced store.\n * \n * @since 0.2.0\n * \n * @example\n * \n * ```tsx\n * const store = withDerived(\n *  create({\n *    count: 123,\n *    info: { name: 'Viki' },\n *  }),\n *  (s) => ({\n *    isViki: s.info.name === 'Viki',\n *    isNegative: s.count < 0,\n *  }),\n * )\n\n * // in normal JS/TS\n * console.log(store.derived().isViki)\n\n * // in React component\n * export function App() {\n *  const { isNegative } = store.useDerived()\n * }\n * ```\n */\nexport function withUseDerived<Store extends VanillaStore<object>, Derived extends object = Store['mutate']>(\n  store: Store,\n  mapFn: (state: Store['mutate']) => Derived = (s) => s as unknown as Derived,\n): Store & WithUseDerivedContributes<Store['mutate'], Derived> {\n  const storeWithDerived = withDerived<Store, Derived>(store, mapFn)\n\n  return {\n    ...storeWithDerived,\n    useDerived: (options: SnapshotOptions<Derived> = {}) => {\n      return useSnapshot<Store['mutate'], Derived>(store.mutate, mapFn, options)\n    },\n  }\n}\n","import { useRef } from 'react'\nimport { deepEqual } from '../utils/index.js'\nimport { createWithHooks } from './create-with-hooks.js'\n\nimport type { DependencyList } from 'react'\nimport type { SnapshotOptions } from './use-snapshot.js'\n\nexport interface UseReactiveOptions<State> extends SnapshotOptions<State> {}\n\n/**\n * A React Hook that helps to use [Reactive](https://sheinsight.github.io/reactive) in React with ease.\n *\n * @since 0.2.0\n */\nexport function useReactive<State extends object>(\n  initialState: State,\n  options: UseReactiveOptions<State> = {},\n): readonly [State, State] {\n  const store = useCreation(() => createWithHooks(initialState), [initialState])\n  return [store.useSnapshot({ ...options }), store.mutate] as const\n}\n\ninterface CreationRefState<T> {\n  value?: T\n  created?: boolean\n  preDeps?: DependencyList\n}\n\nfunction useCreation<T>(create: () => T, currDeps?: DependencyList): T {\n  const { current: creation } = useRef<CreationRefState<T>>({})\n\n  if (!creation.created || !deepEqual(creation.preDeps, currDeps)) {\n    creation.value = create()\n    creation.created = true\n    creation.preDeps = currDeps\n  }\n\n  return creation.value as T\n}\n"]}