{"version":3,"file":"index.cjs","names":["events"],"sources":["../../../../@mongez/atom/src/persist.ts","../../../../@mongez/atom/src/atom.ts","../../../../@mongez/atom/src/atom-store.ts","../../../../@mongez/atom/src/derive.ts","../../../../@mongez/atom/src/devtools.ts","../../../../@mongez/atom/src/atom-collection.ts"],"sourcesContent":["/**\n * @fileoverview Persistence adapters for atoms.\n *\n * Plug in any store-shaped object (cache, localStorage wrapper, cookie\n * helper, IndexedDB layer) and atoms will:\n *\n *   1. Load their initial value from the adapter at creation (sync or async).\n *   2. Write every subsequent update through to the adapter.\n *   3. Remove the entry on `reset()`.\n *\n * The default adapter is a thin localStorage wrapper for the client; it\n * silently no-ops on the server (no `window`). For SSR-safe per-request\n * persistence, supply your own cookie-aware adapter.\n */\nimport type { Atom, AtomOptions } from \"./types\";\n\n/**\n * Shape of an external store. Methods may be sync or async; the\n * persistence layer handles both transparently.\n */\nexport type PersistAdapter<V = unknown> = {\n  /** Read the persisted value for `key`. `undefined` means \"not present\". */\n  get(key: string): V | undefined | Promise<V | undefined>;\n  /** Write `value` to the store under `key`. */\n  set(key: string, value: V): void | Promise<void>;\n  /** Drop the entry for `key`. Called on `reset()`. */\n  remove(key: string): void | Promise<void>;\n};\n\n/**\n * The shape that goes on `AtomOptions.persist`.\n *\n *   - `true` → use the built-in localStorage adapter (client-only).\n *   - `false` / omitted → no persistence.\n *   - Any object matching `PersistAdapter` → use that adapter.\n */\nexport type PersistOption<V = unknown> =\n  | boolean\n  | PersistAdapter<V>;\n\n/**\n * Built-in adapter backed by `window.localStorage`. JSON-encodes the\n * value on write, decodes on read. No-ops on the server.\n */\nexport const localStorageAdapter: PersistAdapter = {\n  get(key) {\n    if (typeof window === \"undefined\" || !window.localStorage) return undefined;\n    const raw = window.localStorage.getItem(key);\n    if (raw === null) return undefined;\n    try {\n      return JSON.parse(raw);\n    } catch {\n      // Corrupt entry — pretend it doesn't exist.\n      return undefined;\n    }\n  },\n  set(key, value) {\n    if (typeof window === \"undefined\" || !window.localStorage) return;\n    try {\n      window.localStorage.setItem(key, JSON.stringify(value));\n    } catch {\n      // QuotaExceededError or private-mode storage block — silently drop.\n    }\n  },\n  remove(key) {\n    if (typeof window === \"undefined\" || !window.localStorage) return;\n    window.localStorage.removeItem(key);\n  },\n};\n\n/**\n * Resolve a `PersistOption` to an actual adapter, or `undefined` if\n * persistence is disabled.\n */\nexport function resolvePersistAdapter<V>(\n  option: PersistOption<V> | undefined,\n): PersistAdapter<V> | undefined {\n  if (!option) return undefined;\n  if (option === true) return localStorageAdapter as PersistAdapter<V>;\n  return option;\n}\n\n/**\n * Wire an atom up to a persistence adapter.\n *\n * On creation, asynchronously reads the stored value and applies it via\n * `silentUpdate` (so subscribers see it on next render but no `update`\n * event fires). On every update afterwards, writes through to the\n * adapter. On `reset`, removes the entry.\n *\n * This is internal — `createAtom` calls it when `options.persist` is\n * truthy. Consumers don't call it directly.\n */\nexport function attachPersist<V, A extends Record<string, any>>(\n  atom: Atom<V, A>,\n  adapter: PersistAdapter<V>,\n  options: AtomOptions<V, any>,\n): void {\n  // Bootstrap: read the stored value. We don't block the constructor on\n  // an async adapter — the consumer sees the default until the read\n  // resolves, then a silentUpdate flips the value in place.\n  // Both sync throws and async rejections are caught so a broken\n  // adapter never crashes atom creation.\n  try {\n    const stored = adapter.get(atom.key);\n    if (stored instanceof Promise) {\n      stored\n        .then(value => {\n          if (value !== undefined) atom.silentUpdate(value);\n        })\n        .catch(() => {\n          /* keep default */\n        });\n    } else if (stored !== undefined) {\n      atom.silentUpdate(stored);\n    }\n  } catch {\n    /* sync throw on read — keep default */\n  }\n\n  // Write-through on every update. Using onChange instead of replacing\n  // beforeUpdate so we don't fight the user's own beforeUpdate hook.\n  // Sync throws are swallowed so a transient storage error (quota,\n  // private-mode block, etc.) doesn't break the consumer's update flow;\n  // async rejections are caught the same way.\n  const updateSub = atom.onChange(newValue => {\n    try {\n      const result = adapter.set(atom.key, newValue);\n      if (result instanceof Promise) result.catch(() => {});\n    } catch {\n      /* adapter blew up — keep going */\n    }\n  });\n\n  // Drop the entry on reset so the next session starts fresh.\n  const resetSub = atom.onReset(() => {\n    try {\n      const result = adapter.remove(atom.key);\n      if (result instanceof Promise) result.catch(() => {});\n    } catch {\n      /* same — non-fatal */\n    }\n  });\n\n  // Clean up subscriptions when the atom dies.\n  atom.onDestroy(() => {\n    updateSub.unsubscribe();\n    resetSub.unsubscribe();\n  });\n\n  // Suppress unused-options lint when not consumed by future logic.\n  void options;\n}\n","/* eslint-disable no-multi-assign */\n/* eslint-disable guard-for-in */\n/* eslint-disable @typescript-eslint/no-shadow */\n/* eslint-disable prefer-template */\nimport events, { EventSubscription } from \"@mongez/events\";\nimport { clone, get } from \"@mongez/reinforcements\";\nimport { attachPersist, resolvePersistAdapter } from \"./persist\";\nimport {\n  Atom,\n  AtomActions,\n  AtomOptions,\n  AtomPartialChangeCallback,\n  AtomValue,\n} from \"./types\";\n\nexport const atoms: Record<string, Atom<any>> = {};\n\nlet cloneCounter = 0;\n\n/**\n * Get atom by name\n */\nexport function getAtom<T>(name: string): Atom<T> | undefined {\n  return atoms[name];\n}\n\n/**\n * Options that control how an atom is constructed.\n * Internal-only; used by store-scoped clones to opt out of the global registry.\n */\nexport type CreateAtomOptions = {\n  /**\n   * When false, the new atom will NOT be inserted into the module-level\n   * `atoms` registry. Used by `AtomStore` to create per-store clones that\n   * stay isolated from the global lookup table.\n   *\n   * Defaults to true.\n   */\n  register?: boolean;\n};\n\n/**\n * Create a new atom\n */\nexport function createAtom<\n  Value = any,\n  Actions extends AtomActions<Value> = AtomActions<Value>\n>(\n  data: AtomOptions<AtomValue<Value>, Actions>,\n  options: CreateAtomOptions = {}\n): Atom<Value, Actions> {\n  let defaultValue = data.default;\n  let atomValue = data.default;\n\n  let atomValueIsObject = false;\n\n  if (defaultValue && typeof defaultValue === \"object\") {\n    atomValue = defaultValue = clone(defaultValue);\n    atomValueIsObject = true;\n  }\n\n  const atomType = Array.isArray(defaultValue) ? \"array\" : typeof defaultValue;\n\n  const atomEvent = `atoms.${data.key}`;\n\n  const event = (type: string): string => `${atomEvent}.${type}`;\n\n  const watchers: any = {};\n\n  const atomKey = data.key;\n\n  const atom: Atom<Value, Actions> = {\n    default: defaultValue,\n    currentValue: atomValue,\n    key: atomKey,\n    get type() {\n      return atomType;\n    },\n    watch<T extends keyof Value>(\n      key: T,\n      callback: AtomPartialChangeCallback\n    ): EventSubscription {\n      if (!watchers[key]) {\n        watchers[key] = [];\n      }\n\n      watchers[key].push(callback);\n\n      return {\n        unsubscribe: () => {\n          watchers[key] = watchers[key].filter(\n            (cb: AtomPartialChangeCallback) => cb !== callback\n          );\n        },\n      } as EventSubscription;\n    },\n    get defaultValue(): Value {\n      return this.default;\n    },\n    get value(): Value {\n      return this.currentValue;\n    },\n    change<T extends keyof Value>(key: T, newValue: any) {\n      this.update({\n        ...this.currentValue,\n        [key]: newValue,\n      });\n    },\n    silentChange<T extends keyof Value>(key: T, newValue: any) {\n      this.silentUpdate({\n        ...this.currentValue,\n        [key]: newValue,\n      });\n    },\n    merge(newValue: Partial<Value>) {\n      this.update({\n        ...this.currentValue,\n        ...newValue,\n      });\n    },\n    update(newValue: (oldValue: Value, atom: Atom<Value, Actions>) => Value) {\n      if (newValue === this.currentValue) return;\n\n      const oldValue = this.currentValue;\n      let updatedValue: Value;\n\n      if (typeof newValue === \"function\") {\n        updatedValue = newValue(oldValue, this);\n      } else {\n        updatedValue = newValue;\n      }\n\n      if (data.beforeUpdate) {\n        const beforeUpdateOutput = data.beforeUpdate(\n          updatedValue,\n          oldValue,\n          this\n        );\n\n        if (beforeUpdateOutput !== undefined) {\n          updatedValue = beforeUpdateOutput;\n        }\n      }\n\n      this.currentValue = updatedValue;\n      events.trigger(event(\"update\"), this.currentValue, oldValue, this);\n      if (atomValueIsObject) {\n        for (const key in watchers) {\n          const keyOldValue = get(oldValue, key);\n          const keyNewValue = get(updatedValue, key);\n\n          if (keyOldValue !== keyNewValue) {\n            watchers[key].forEach(\n              (callback: AtomPartialChangeCallback) =>\n                callback(keyNewValue, keyOldValue, this)\n            );\n          }\n        }\n      }\n    },\n    silentUpdate(\n      newValue: ((oldValue: Value, atom: Atom<Value>) => Value) | Value\n    ) {\n      if (newValue === this.currentValue) return;\n\n      const oldValue = this.currentValue;\n      let updatedValue: Value;\n\n      if (typeof newValue === \"function\") {\n        updatedValue = (newValue as any)(oldValue, this);\n      } else {\n        updatedValue = newValue;\n      }\n\n      if (data.beforeUpdate) {\n        const beforeUpdateOutput = data.beforeUpdate(\n          updatedValue,\n          oldValue,\n          this\n        );\n\n        if (beforeUpdateOutput !== undefined) {\n          updatedValue = beforeUpdateOutput;\n        }\n      }\n\n      this.currentValue = updatedValue;\n    },\n    onChange(\n      callback: (newValue: Value, oldValue: Value, atom: Atom<Value>) => void\n    ): EventSubscription {\n      return events.subscribe(event(\"update\"), callback);\n    },\n    onReset(callback: (atom: Atom<Value>) => void): EventSubscription {\n      return events.subscribe(event(\"reset\"), callback);\n    },\n    get<T extends keyof Value>(key: T, defaultValue?: any): Value[T] {\n      if (data.get) {\n        return data.get(\n          key as string,\n          defaultValue,\n          this.currentValue\n        ) as Value[T];\n      }\n\n      return get(this.currentValue, key as string, defaultValue);\n    },\n    destroy() {\n      events.trigger(event(\"delete\"), this);\n\n      events.unsubscribeNamespace(atomEvent);\n      delete atoms[this.key];\n    },\n    onDestroy(callback: (atom: Atom<Value>) => void): EventSubscription {\n      return events.subscribe(`atoms.${this.key}.delete`, callback);\n    },\n    reset() {\n      this.update(clone(this.defaultValue));\n      events.trigger(event(\"reset\"), this);\n    },\n    /**\n     * Reset the value without triggering the update event\n     * But this will trigger the reset event\n     */\n    silentReset() {\n      this.currentValue = clone(this.defaultValue);\n      events.trigger(event(\"reset\"), this);\n    },\n    clone(cloneOptions?: CreateAtomOptions) {\n      return createAtom(\n        {\n          key: this.key + \".clone.\" + (++cloneCounter),\n          default: clone(this.currentValue),\n          beforeUpdate: data.beforeUpdate,\n          get: data.get,\n          onUpdate: data.onUpdate,\n          actions: data.actions,\n        },\n        { register: cloneOptions?.register ?? true }\n      );\n    },\n  } as any;\n\n  // Install actions on the atom instance.\n  //\n  // Three kinds of entries can appear in `actions`:\n  //   1. Plain functions — bound to the atom so `this` refers to it.\n  //   2. Property getters (e.g. `atomCollection`'s `length`) — forwarded\n  //      as getters bound to the atom; calling `.bind(...)` on them would\n  //      blow up because the getter is invoked the moment we touch it.\n  //   3. Anything else — assigned by value as a fallback.\n  if (data.actions) {\n    const actions = data.actions as Record<string, unknown>;\n    for (const actionKey of Object.keys(actions)) {\n      const descriptor = Object.getOwnPropertyDescriptor(actions, actionKey);\n      if (descriptor?.get) {\n        Object.defineProperty(atom, actionKey, {\n          get: descriptor.get.bind(atom),\n          set: descriptor.set ? descriptor.set.bind(atom) : undefined,\n          enumerable: true,\n          configurable: true,\n        });\n        continue;\n      }\n      const value = actions[actionKey];\n      if (typeof value === \"function\") {\n        (atom as any)[actionKey] = (value as Function).bind(atom);\n      } else {\n        (atom as any)[actionKey] = value;\n      }\n    }\n  }\n\n  if (data.onUpdate) {\n    events.subscribe(event(\"update\"), data.onUpdate.bind(atom));\n  }\n\n  if (options.register !== false) {\n    atoms[atomKey] = atom;\n  }\n\n  // Persistence wiring. Resolve the adapter (boolean → built-in\n  // localStorage, object → as-is, falsy → skip). The adapter handles\n  // the initial read and the write-through; we just hand it the atom.\n  const adapter = resolvePersistAdapter(data.persist);\n  if (adapter) {\n    attachPersist(atom, adapter, data);\n  }\n\n  return atom;\n}\n\n/**\n * Get all atoms list\n */\nexport function atomsList(): Atom<any>[] {\n  return Object.values(atoms);\n}\n\n/**\n * Return atoms in object format\n */\nexport function atomsObject(): Record<string, Atom<any>> {\n  return atoms;\n}\n","import type { Atom } from \"./types\";\n\n/**\n * A store is an isolated registry of atom instances.\n *\n * Each store creates and holds its own clones of atom templates so that\n * concurrent consumers (e.g. server-rendered requests) do not share state.\n *\n * Stores are looked up via React context by `<AtomStoreProvider>` in\n * `@mongez/react-atom`, but the class itself is framework-agnostic and can\n * be used directly outside React.\n */\nexport class AtomStore {\n  /**\n   * Scoped atom clones, keyed by the ORIGINAL atom's key (not the clone key).\n   */\n  private store = new Map<string, Atom<any>>();\n\n  /**\n   * Values applied to atoms the moment they enter the store. Useful for\n   * SSR hydration when atoms register lazily.\n   */\n  private pendingValues = new Map<string, unknown>();\n\n  /**\n   * Get or lazily create a store-scoped clone of the given atom template.\n   * The clone shares the template's options (actions, beforeUpdate, get,\n   * onUpdate) but owns its own state and event topic.\n   */\n  use<V, A extends Record<string, any> = {}>(template: Atom<V, A>): Atom<V, A> {\n    const existing = this.store.get(template.key);\n    if (existing) return existing as Atom<V, A>;\n\n    const scoped = template.clone({ register: false }) as Atom<V, A>;\n\n    if (this.pendingValues.has(template.key)) {\n      scoped.silentUpdate(this.pendingValues.get(template.key) as V);\n      this.pendingValues.delete(template.key);\n    }\n\n    this.store.set(template.key, scoped);\n    return scoped;\n  }\n\n  /**\n   * Look up a scoped atom by its original key. Returns undefined when the\n   * atom has not been used in this store yet.\n   */\n  get<V = any>(key: string): Atom<V> | undefined {\n    return this.store.get(key) as Atom<V> | undefined;\n  }\n\n  /**\n   * True when the given key has a scoped atom in this store.\n   */\n  has(key: string): boolean {\n    return this.store.has(key);\n  }\n\n  /**\n   * All scoped atoms currently in this store.\n   */\n  list(): Atom<any>[] {\n    return Array.from(this.store.values());\n  }\n\n  /**\n   * Apply initial values to atoms in the store. Atoms not yet registered\n   * have their values queued until first `use(template)` call.\n   */\n  hydrate(snapshot: Record<string, unknown>): void {\n    for (const key in snapshot) {\n      const value = snapshot[key];\n      const atom = this.store.get(key);\n      if (atom) {\n        atom.silentUpdate(value);\n      } else {\n        this.pendingValues.set(key, value);\n      }\n    }\n  }\n\n  /**\n   * Serialize the current values of every scoped atom as a plain object.\n   * Intended for SSR payloads that the client will pass back via\n   * `<AtomStoreProvider initialValues={...}>`.\n   */\n  snapshot(): Record<string, unknown> {\n    const result: Record<string, unknown> = {};\n    for (const [key, atom] of this.store.entries()) {\n      result[key] = atom.value;\n    }\n    return result;\n  }\n\n  /**\n   * Destroy every scoped atom and clear the store. Call this at the end of\n   * a request lifecycle to release event-bus subscriptions and let the\n   * scoped atoms be garbage collected.\n   */\n  destroy(): void {\n    for (const atom of this.store.values()) {\n      atom.destroy();\n    }\n    this.store.clear();\n    this.pendingValues.clear();\n  }\n}\n\n/**\n * Convenience factory; equivalent to `new AtomStore()`.\n */\nexport function createAtomStore(): AtomStore {\n  return new AtomStore();\n}\n","/**\n * @fileoverview Derived atoms.\n *\n * A derived atom holds a value computed from one or more other atoms.\n * Dependencies are auto-tracked: whichever atoms the compute function\n * reads via the `get` argument become dependencies. When any of those\n * change, the derived value recomputes and notifies its subscribers.\n *\n * Conceptually similar to Jotai's `atom(get => ...)` and MobX's\n * `computed`. Returns a normal `Atom<T>`, so every consumer pattern in\n * `@mongez/react-atom` (useValue, useState, watch, onChange, …) works.\n *\n * @example\n * ```ts\n * const first = createAtom({ key: \"first\", default: \"Ada\" });\n * const last  = createAtom({ key: \"last\",  default: \"Lovelace\" });\n *\n * const fullName = derive(\"fullName\", get => `${get(first)} ${get(last)}`);\n *\n * fullName.value;                 // \"Ada Lovelace\"\n * first.update(\"Grace\");\n * fullName.value;                 // \"Grace Lovelace\"\n * ```\n */\nimport { type EventSubscription } from \"@mongez/events\";\nimport { createAtom } from \"./atom\";\nimport type { Atom } from \"./types\";\n\n/**\n * The reader passed to a derive compute function. Calling `get(atom)`\n * registers that atom as a dependency and returns its current value.\n */\nexport type DeriveGetter = <V>(atom: Atom<V, any>) => V;\n\nexport type DeriveOptions = {\n  /**\n   * Skip the global `atoms` registry. Used by `AtomStore` clones — most\n   * consumers should leave this alone.\n   * @default true\n   */\n  register?: boolean;\n};\n\n/**\n * Create a derived atom.\n *\n * The compute function runs once eagerly on creation to seed the initial\n * value and to discover dependencies. After that, it re-runs every time\n * any tracked dependency changes.\n *\n * Conditional reads work: an `if` branch inside the compute function\n * that reads a different atom on a later run picks up the new dep and\n * drops the old one. This handles the \"dynamic dependency graph\" case\n * (e.g. `if (get(currentRoute) === \"users\") return get(usersAtom)`).\n *\n * Calling `update`, `silentUpdate`, `change`, `merge` directly on the\n * returned atom works but is discouraged — the next dependency change\n * will overwrite anything you wrote. Use a regular atom if you need\n * writable state.\n */\nexport function derive<T>(\n  key: string,\n  compute: (get: DeriveGetter) => T,\n  options: DeriveOptions = {},\n): Atom<T> {\n  /**\n   * Active subscriptions to dependencies, keyed by the source atom.\n   * Replaced wholesale on each recompute so dynamic dependency graphs\n   * don't accumulate stale subscriptions.\n   */\n  let depSubs = new Map<Atom<any>, EventSubscription>();\n\n  /**\n   * A scratch set used during a recompute to mark which atoms were\n   * touched on this run. After compute finishes we diff against\n   * `depSubs`, drop stale ones, and add new ones.\n   */\n  let trackedThisRun: Set<Atom<any>> | undefined;\n\n  const trackingGet: DeriveGetter = atom => {\n    if (trackedThisRun) trackedThisRun.add(atom);\n    return atom.value;\n  };\n\n  /**\n   * Recompute the derived value and reconcile the dependency set.\n   * Updates the derived atom via the normal `update` flow so all\n   * downstream subscribers see the change.\n   *\n   * Errors thrown inside `compute` are caught and re-thrown\n   * asynchronously: we don't want a single broken derivation to take\n   * down the atom-bus subscriber. The atom's previous value is kept.\n   */\n  const recompute = () => {\n    trackedThisRun = new Set();\n    let next: T;\n    try {\n      next = compute(trackingGet);\n    } catch (err) {\n      trackedThisRun = undefined;\n      // Surface the error without breaking the source-atom's update cycle.\n      queueMicrotask(() => {\n        throw err;\n      });\n      return;\n    }\n\n    // Reconcile: subscribe to newly-seen deps, drop deps no longer read.\n    const seen = trackedThisRun;\n    trackedThisRun = undefined;\n\n    for (const dep of seen) {\n      if (!depSubs.has(dep)) {\n        depSubs.set(dep, dep.onChange(recompute));\n      }\n    }\n    for (const [dep, sub] of depSubs) {\n      if (!seen.has(dep)) {\n        sub.unsubscribe();\n        depSubs.delete(dep);\n      }\n    }\n\n    // Push the new value through the standard update path. If the value\n    // is structurally unchanged the atom's update() will short-circuit\n    // for primitives; for objects we always send a new reference\n    // because `compute` builds one each call.\n    derivedAtom.update(next);\n  };\n\n  // Bootstrap: compute the initial value and the initial dep set.\n  trackedThisRun = new Set();\n  const initialValue = compute(trackingGet);\n  const seen = trackedThisRun;\n  trackedThisRun = undefined;\n\n  const derivedAtom = createAtom<T>(\n    {\n      key,\n      default: initialValue,\n    },\n    { register: options.register !== false },\n  );\n\n  // Wire up dependency subscriptions now that the derived atom exists.\n  for (const dep of seen) {\n    depSubs.set(dep, dep.onChange(recompute));\n  }\n\n  // Tear down dependency subs when the atom is destroyed so they don't\n  // outlive the consumer and leak memory.\n  derivedAtom.onDestroy(() => {\n    for (const sub of depSubs.values()) sub.unsubscribe();\n    depSubs.clear();\n  });\n\n  return derivedAtom;\n}\n","/**\n * @fileoverview Redux DevTools bridge for `@mongez/atom`.\n *\n * Opt-in, browser-only, zero-cost when not enabled (tree-shaken if you\n * never import `enableAtomDevtools`).\n *\n * Pipes every atom update into the Redux DevTools extension so you get:\n *\n *   - A live list of every registered atom and its current value.\n *   - A timeline of updates with diffs.\n *   - Time-travel: jumping back in the timeline restores the matching\n *     state via `silentUpdate` on every atom.\n *\n * @example\n * ```ts\n * // app entry, dev only\n * if (process.env.NODE_ENV !== \"production\") {\n *   enableAtomDevtools({ name: \"MyApp\" });\n * }\n * ```\n */\nimport events from \"@mongez/events\";\nimport { atoms } from \"./atom\";\nimport type { Atom } from \"./types\";\n\n/**\n * Subset of the Redux DevTools instance API we use. Typed locally so we\n * don't need to take a dep on `@redux-devtools/extension`.\n */\ntype DevtoolsInstance = {\n  init(state: unknown): void;\n  send(action: { type: string; payload?: unknown }, state: unknown): void;\n  subscribe(\n    listener: (message: {\n      type: string;\n      payload?: { type?: string };\n      state?: string;\n    }) => void,\n  ): () => void;\n  disconnect?(): void;\n};\n\ntype DevtoolsExtension = {\n  connect(options?: {\n    name?: string;\n    features?: Record<string, unknown>;\n  }): DevtoolsInstance;\n};\n\nexport type EnableDevtoolsOptions = {\n  /** Label shown in the extension UI. */\n  name?: string;\n  /**\n   * Skip atoms whose key matches any of these patterns. Useful for\n   * silencing high-frequency atoms (mouse position, scroll, etc.) that\n   * would otherwise spam the timeline.\n   */\n  ignore?: Array<RegExp | string>;\n  /**\n   * How often (ms) to look for newly-registered atoms. Apps that\n   * register every atom at startup never need this; the default of\n   * 1000ms is fine for hot-reload and code-splitting cases.\n   * @default 1000\n   */\n  scanInterval?: number;\n};\n\n/**\n * Connect every registered atom to the Redux DevTools extension.\n *\n * Returns a teardown function that disconnects and stops the registry\n * scan. Safe to call when the extension isn't installed — it returns\n * a no-op teardown without doing any work.\n */\nexport function enableAtomDevtools(\n  options: EnableDevtoolsOptions = {},\n): () => void {\n  const win =\n    typeof window !== \"undefined\" ? (window as unknown as Window & {\n      __REDUX_DEVTOOLS_EXTENSION__?: DevtoolsExtension;\n    }) : undefined;\n\n  const ext = win?.__REDUX_DEVTOOLS_EXTENSION__;\n  if (!ext) return () => {};\n\n  const devtools = ext.connect({\n    name: options.name ?? \"@mongez/atom\",\n  });\n\n  const ignored = (key: string): boolean =>\n    !!options.ignore?.some(pat =>\n      typeof pat === \"string\" ? pat === key : pat.test(key),\n    );\n\n  const snapshot = (): Record<string, unknown> => {\n    const out: Record<string, unknown> = {};\n    for (const [k, a] of Object.entries(atoms)) {\n      if (!ignored(k)) out[k] = a.value;\n    }\n    return out;\n  };\n\n  devtools.init(snapshot());\n\n  // Per-atom subscriptions we own (so we can tear them down).\n  const subscribed = new Map<string, () => void>();\n\n  const subscribeAtom = (atom: Atom<any>) => {\n    if (ignored(atom.key)) return;\n    if (subscribed.has(atom.key)) return;\n    const sub = atom.onChange(newValue => {\n      devtools.send(\n        { type: `${atom.key}/update`, payload: newValue },\n        snapshot(),\n      );\n    });\n    const onResetSub = atom.onReset(() => {\n      devtools.send({ type: `${atom.key}/reset` }, snapshot());\n    });\n    const onDestroySub = atom.onDestroy(() => {\n      devtools.send({ type: `${atom.key}/destroy` }, snapshot());\n      // Drop our own subscription bookkeeping.\n      subscribed.delete(atom.key);\n    });\n    subscribed.set(atom.key, () => {\n      sub.unsubscribe();\n      onResetSub.unsubscribe();\n      onDestroySub.unsubscribe();\n    });\n  };\n\n  for (const atom of Object.values(atoms)) subscribeAtom(atom);\n\n  // Pick up atoms registered AFTER enableAtomDevtools fires. Apps that\n  // import all their atoms at boot will never trigger this; lazy-loaded\n  // routes that register atoms on demand will. Poll-based for simplicity.\n  const interval = options.scanInterval ?? 1000;\n  const scanTimer: ReturnType<typeof setInterval> = setInterval(() => {\n    for (const atom of Object.values(atoms)) subscribeAtom(atom);\n  }, interval);\n\n  // Time-travel: when the user jumps to a snapshot in the extension,\n  // restore every atom's value via silentUpdate so consumers see the\n  // restored state on the next read.\n  const unsubDevtools = devtools.subscribe(message => {\n    if (message.type !== \"DISPATCH\") return;\n    const payloadType = message.payload?.type;\n    if (\n      payloadType !== \"JUMP_TO_STATE\" &&\n      payloadType !== \"JUMP_TO_ACTION\"\n    ) {\n      return;\n    }\n    if (!message.state) return;\n    let restored: Record<string, unknown>;\n    try {\n      restored = JSON.parse(message.state);\n    } catch {\n      return;\n    }\n    for (const [key, value] of Object.entries(restored)) {\n      const atom = atoms[key];\n      if (!atom) continue;\n      atom.silentUpdate(value);\n      // Synthesise an update event so React subscribers re-render.\n      events.trigger(`atoms.${key}.update`, value, atom.currentValue, atom);\n    }\n  });\n\n  return () => {\n    clearInterval(scanTimer);\n    for (const unsub of subscribed.values()) unsub();\n    subscribed.clear();\n    unsubDevtools();\n    devtools.disconnect?.();\n  };\n}\n","import { createAtom } from './atom';\nimport type { Atom, AtomActions, AtomOptions } from './types';\n\nexport type IndexOrCallback<Value> =\n  | number\n  | ((value: Value, index: number, list: Value[]) => boolean);\n\nexport interface AtomCollectionActions<Value> extends AtomActions<Value[]> {\n  /**\n   * Add items to the end of the array\n   */\n  push(this: Atom<Value[]>, ...items: Value[]): void;\n  /**\n   * Add items to the beginning of the array\n   */\n  unshift(this: Atom<Value[]>, ...items: Value[]): void;\n  /**\n   * Remove the last item from the array\n   */\n  pop(this: Atom<Value[]>): void;\n  /**\n   * Remove the first item from the array\n   */\n  shift(this: Atom<Value[]>): void;\n  /**\n   * Remove item from array either by index or callback\n   */\n  remove(this: Atom<Value[]>, indexOrCallback: IndexOrCallback<Value>): void;\n  /**\n   * Remove item from array by value\n   */\n  removeItem(this: Atom<Value[]>, item: Value): void;\n  /**\n   * Remove all occurrences of an item from the array\n   */\n  removeAll(this: Atom<Value[]>, item: Value): void;\n  /**\n   * Get item from array either by index or callback\n   */\n  get(this: Atom<Value[]>, indexOrCallback: IndexOrCallback<Value>): Value | undefined;\n  /**\n   * Find index of item in array by callback\n   */\n  index(\n    this: Atom<Value[]>,\n    callback: (item: Value, index: number, array: Value[]) => boolean,\n  ): number;\n  /**\n   * Map array items\n   * This will update the array with the new mapped array and trigger update\n   */\n  map(\n    this: Atom<Value[]>,\n    callback: (item: Value, index: number, array: Value[]) => Value,\n  ): Value[];\n  /**\n   * Loop through array items\n   */\n  forEach(\n    this: Atom<Value[]>,\n    callback: (item: Value, index: number, array: Value[]) => void,\n  ): void;\n  /**\n   * Replace item in array by index\n   */\n  replace(this: Atom<Value[]>, index: number, item: Value): void;\n  /**\n   * Get array length\n   */\n  length: number; // As a property\n}\n\nexport type CollectionOptions<Value> = Omit<\n  AtomOptions<Value[], AtomCollectionActions<Value>>,\n  'default'\n> & {\n  default?: Value[];\n};\n\n/**\n * Create an atom collection\n */\nexport function atomCollection<Value = any>(\n  options: CollectionOptions<Value>,\n): Atom<Value[], AtomCollectionActions<Value>> {\n  return createAtom<Value[], AtomCollectionActions<Value>>({\n    key: options.key,\n    default: options.default ?? [],\n    actions: {\n      ...options.actions,\n      push(...items: Value[]) {\n        this.update([...this.currentValue, ...items]);\n      },\n      pop() {\n        this.update(this.currentValue.slice(0, -1));\n      },\n      shift() {\n        this.update(this.currentValue.slice(1));\n      },\n      unshift(...items: Value[]) {\n        this.update([...items, ...this.currentValue]);\n      },\n      remove(indexOrCallback: IndexOrCallback<Value>) {\n        const index =\n          typeof indexOrCallback === 'function'\n            ? this.value.findIndex(indexOrCallback)\n            : indexOrCallback;\n\n        if (index === -1) return;\n\n        this.update(this.value.filter((_, i) => i !== index));\n      },\n      removeItem(item: Value) {\n        const index = this.value.indexOf(item);\n\n        if (index === -1) return;\n\n        // using splice\n        this.value.splice(index, 1);\n\n        this.update([...this.value]);\n      },\n      removeAll(item: Value) {\n        this.update(this.value.filter((value) => value !== item));\n      },\n      get(indexOrCallback: IndexOrCallback<Value>) {\n        const index: number =\n          typeof indexOrCallback === 'function'\n            ? this.value.findIndex(indexOrCallback)\n            : indexOrCallback;\n\n        return this.value[index];\n      },\n      index(callback: (item: Value, index: number, array: Value[]) => boolean) {\n        return this.value.findIndex(callback);\n      },\n      map(callback: (item: Value, index: number, array: Value[]) => Value) {\n        const value = this.value.map(callback);\n\n        this.update(value);\n\n        return value;\n      },\n      forEach(callback: (item: Value, index: number, array: Value[]) => void) {\n        this.value.forEach(callback);\n      },\n      get length() {\n        return this.value?.length;\n      },\n      replace(index: number, item: Value) {\n        this.update(\n          this.value.map((value, i) => {\n            if (i === index) {\n              return item;\n            }\n\n            return value;\n          }),\n        );\n      },\n    },\n  });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,MAAa,sBAAsC;CACjD,IAAI,KAAK;EACP,IAAI,OAAO,WAAW,eAAe,CAAC,OAAO,cAAc,OAAO;EAClE,MAAM,MAAM,OAAO,aAAa,QAAQ,GAAG;EAC3C,IAAI,QAAQ,MAAM,OAAO;EACzB,IAAI;GACF,OAAO,KAAK,MAAM,GAAG;EACvB,QAAQ;GAEN;EACF;CACF;CACA,IAAI,KAAK,OAAO;EACd,IAAI,OAAO,WAAW,eAAe,CAAC,OAAO,cAAc;EAC3D,IAAI;GACF,OAAO,aAAa,QAAQ,KAAK,KAAK,UAAU,KAAK,CAAC;EACxD,QAAQ,CAER;CACF;CACA,OAAO,KAAK;EACV,IAAI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