{"version":3,"sources":["../../src/createStateScope/index.ts"],"names":["handleState_default","_value","_root","get","_callbacks","set","_onValueChange","createSubscribe_default","_children","_valueToggler","createScope_default"],"mappings":";;;;;;;AAyBA,IAAM,gBAMF,GAAA,CACF,KACA,EAAA,gBAAA,EACA,IACG,KAAA;AACH,EAAM,MAAA,SAAA,uBAAsC,GAAI,EAAA;AAEhD,EAAA,MAAM,KAAQ,GAAAA,qCAAA;AAAA,IACZ;AAAA,MACEC,CAAQ,EAAA,KAAA,CAAA;AAAA,MACRC,CAAO,EAAA,KAAA,CAAA;AAAA,WACPC,qBAAA;AAAA,MACAC,CAAY,EAAA,SAAA;AAAA,WACZC,qBAAA;AAAA,MACAC,CAAAA,EAAgBC,0CAAgB,SAAS,CAAA;AAAA,MACzCC,CAAW,EAAA,KAAA,CAAA;AAAA,MACXC,CAAe,EAAA;AAAA,KACjB;AAAA,IACA,KAAA;AAAA,IACA,gBAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAC,MAAgCP,CAAQ,GAAA,KAAA;AAEzC,EAAA,OAAOQ,sCAAY,KAAK,CAAA;AAC1B,CAAA;AAIA,IAAO,wBAAQ,GAAA","file":"chunk-YBWV7VPO.cjs","sourcesContent":["import type {\n  StateInitializer,\n  StateScope,\n  State,\n  Mutable,\n  ValueChangeCallbacks,\n} from '../types';\nimport handleState from '../utils/handleState';\nimport createScope from '../utils/createScope';\nimport { set } from '../utils/state/scope';\nimport { get } from '../utils/state/common';\nimport createSubscribe from '../utils/createSubscribe';\n\n/**\n * Creates a {@link StateScope state scope} for managing complex state structures.\n *\n * @example\n * ```js\n * const state1Scope = createStateScope();\n *\n * const state2Scope = createStateScope({ name: 'John' });\n *\n * const state3Scope = createStateScope(() => ({ name: 'John' }));\n * ```\n */\nconst createStateScope: {\n  <T>(): StateScope<T | undefined>;\n  <T>(\n    value: T | (() => T),\n    stateInitializer?: StateInitializer<T | undefined>\n  ): StateScope<T>;\n} = (\n  value?: unknown | (() => unknown),\n  stateInitializer?: StateInitializer,\n  keys?: any[]\n) => {\n  const callbacks: ValueChangeCallbacks = new Set();\n\n  const state = handleState<State>(\n    {\n      _value: undefined,\n      _root: undefined!,\n      get,\n      _callbacks: callbacks,\n      set,\n      _onValueChange: createSubscribe(callbacks),\n      _children: undefined,\n      _valueToggler: 0,\n    },\n    value,\n    stateInitializer,\n    keys\n  );\n\n  (state as Mutable<typeof state>)._root = state;\n\n  return createScope(state);\n};\n\nexport type { StateScope };\n\nexport default createStateScope;\n"]}