{"version":3,"sources":["../src/core/ref.ts","../src/core/computed-v2.ts","../src/core/reactive-public.ts"],"names":["useRef","initialValue","hook","createComputedV2","fn","scheduleEffect","UNINITIALIZED","cachedValue","container","makeSignalContainer","effect","makeEffectRecord","newValue","triggerV2","setDirty","get","runEffectV2","trackV2","stopEffectV2","createSignal","sc","createSignalV2","createEffect","runner","createEffectV2","createComputed","c"],"mappings":"0GA2BO,SAASA,EAAUC,GAAAA,CAA4C,CACpE,OAAOC,CAAAA,CAAK,KAAO,CACjB,OAAA,CAASD,GACX,CAAA,CAAE,CACJ,CCGO,SAASE,EACZC,CAAAA,CACAC,CAAAA,CACiB,CAEjB,IAAMC,GAAAA,CAAgB,MAAA,CAAO,QAAQ,EACjCC,CAAAA,CAAwCD,GAAAA,CAGtCE,CAAAA,CAAYC,GAAAA,CAAuB,MAAyB,CAAA,CAE5DC,CAAAA,CAASC,CAAAA,CAAiB,IAAM,CAClC,IAAMC,CAAAA,CAAWR,GAAG,CACf,MAAA,CAAO,GAAGQ,CAAAA,CAAUL,CAAW,CAAA,GAChCA,CAAAA,CAAcK,EACdJ,CAAAA,CAAU,KAAA,CAAQI,CAAAA,CAElBC,GAAAA,CAAUL,EAAWH,CAAc,CAAA,EAE3C,CAAC,CAAA,CAGDK,EAAO,KAAA,CAAQI,CAAAA,CAASJ,EAAO,KAAK,CAAA,CAEpC,SAASK,CAAAA,EAAS,CAEd,OAAA,CAAA,CAAKL,CAAAA,CAAO,MAAQ,CAAA,IAAkB,CAAA,EAAKH,IAAgBD,GAAAA,GACvDU,CAAAA,CAAYN,CAAM,CAAA,CAGtBO,CAAAA,CAAQT,CAAS,CAAA,CACVA,EAAU,KACrB,CAEA,OAAO,CACH,IAAI,IAAK,CAAE,OAAOA,CAAAA,CAAU,EAAG,EAC/B,GAAA,CAAAO,CAAAA,CACA,IAAA,EAAO,CAAEG,EAAaR,CAAM,EAAE,CAAA,CAC9B,IAAI,YAAa,CAAE,OAAOF,CAAU,CAAA,CACpC,IAAI,SAAU,CAAE,OAAOE,CAAO,CAClC,CACJ,CCxCO,SAASS,EAAgBlB,CAAAA,CAA4B,CACxD,IAAMmB,CAAAA,CAAKC,CAAAA,CAAepB,CAAAA,CAAcI,CAAc,EACtD,OAAO,CAACe,EAAG,OAAA,CAASA,CAAAA,CAAG,OAAoB,CAC/C,CAUO,SAASE,CAAAA,CAAalB,EAAsC,CAC/D,IAAMmB,CAAAA,CAASC,CAAAA,CAAepB,EAAI,CAAE,iBAAA,CAAmB,KAAM,CAAC,EAC9D,OAAO,CAAE,KAAM,IAAMmB,CAAAA,CAAO,OAAO,IAAA,EAAO,CAC9C,CAQO,SAASE,CAAAA,CAAkBrB,CAAAA,CAAiD,CAC/E,IAAMsB,CAAAA,CAAIvB,EAAiBC,CAAAA,CAAIC,CAAc,CAAA,CAC7C,OAAO,CAAE,GAAA,CAAKqB,CAAAA,CAAE,IAAK,IAAA,CAAMA,CAAAA,CAAE,IAAK,CACtC","file":"chunk-ZWDMOORC.mjs","sourcesContent":["import { hook } from './hook'\nimport type { RefObject } from './types'\n\n/**\n * Creates a mutable ref object that persists across renders\n *\n * @example\n * ```tsx\n * function InputWithFocus() {\n *   const inputRef = useRef<HTMLInputElement>()\n *\n *   const focusInput = () => {\n *     inputRef.current?.focus()\n *   }\n *\n *   return (\n *     <div>\n *       <input ref={inputRef} type=\"text\" />\n *       <button onClick={focusInput}>Focus Input</button>\n *     </div>\n *   )\n * }\n * ```\n */\nexport function useRef<T>(initialValue: T): RefObject<T>\nexport function useRef<T>(initialValue: T | null): RefObject<T | null>\nexport function useRef<T = undefined>(): RefObject<T | undefined>\nexport function useRef<T>(initialValue?: T): RefObject<T | undefined> {\n  return hook(() => ({\n    current: initialValue\n  }))\n}\n","import {\n    makeSignalContainer,\n    makeEffectRecord,\n    runEffectV2,\n    stopEffectV2,\n    trackV2,\n    triggerV2,\n    type SignalContainer,\n    type EffectRecord,\n} from './reactive-v2'\nimport {\n    EFFECT_DIRTY,\n    setDirty,\n} from './effect-flags'\nimport type { ScheduleEffectFn } from './scheduler'\n\nexport interface ComputedSignal<T> {\n    readonly id: number\n    /** Read the computed value. Lazily re-computes if dirty. */\n    readonly get: () => T\n    /** Force stop the computed (unsubscribes from all deps). */\n    stop: () => void\n    /** @internal — the underlying signal container for triggerV2 */\n    readonly _container: SignalContainer<T>\n    /** @internal — the underlying effect record */\n    readonly _effect: EffectRecord\n}\n\n/**\n * Create a lazy computed signal.\n *\n * The computed re-evaluates `fn` only when one of its tracked deps changes AND\n * the value is actually read (lazy / pull-based).\n */\nexport function createComputedV2<T>(\n    fn: () => T,\n    scheduleEffect: ScheduleEffectFn\n): ComputedSignal<T> {\n    // Use a sentinel to detect first run\n    const UNINITIALIZED = Symbol('uninit')\n    let cachedValue: T | typeof UNINITIALIZED = UNINITIALIZED\n\n    // The container exposes the computed value as a signal so downstream effects can track it\n    const container = makeSignalContainer<T>(undefined as unknown as T)\n\n    const effect = makeEffectRecord(() => {\n        const newValue = fn()\n        if (!Object.is(newValue, cachedValue)) {\n            cachedValue = newValue\n            container.value = newValue\n            // Notify downstream effects that read this computed\n            triggerV2(container, scheduleEffect)\n        }\n    })\n\n    // Mark dirty so first read triggers computation\n    effect.flags = setDirty(effect.flags)\n\n    function get(): T {\n        // If dirty, re-compute before returning\n        if ((effect.flags & EFFECT_DIRTY) !== 0 || cachedValue === UNINITIALIZED) {\n            runEffectV2(effect)\n        }\n        // Track this computed as a dependency of any outer effect\n        trackV2(container)\n        return container.value\n    }\n\n    return {\n        get id() { return container.id },\n        get,\n        stop() { stopEffectV2(effect) },\n        get _container() { return container },\n        get _effect() { return effect },\n    }\n}\n","/**\n * Low-level reactivity primitives — additive escape hatch alongside `use()`.\n *\n * These bypass the hook system and the component-mount overhead (~14 μs per\n * `use(0)` call in Phase 0 measurements). Use them for framework-level state,\n * detached effects, or hot loops that mount/teardown signals at high frequency.\n *\n * Component-scoped state should still use `use()` — it integrates with hooks,\n * the global registry, devtools, and component-lifecycle cleanup.\n *\n * @example\n * import { createSignal, createEffect } from 'flexium/core'\n *\n * const [count, setCount] = createSignal(0)\n * createEffect(() => console.log('count is', count()))\n * setCount(c => c + 1)   // → logs \"count is 1\" on next microtask\n */\n\nimport {\n    createSignalV2,\n    createEffectV2,\n} from './reactive-v2'\nimport { createComputedV2 } from './computed-v2'\nimport { scheduleEffect } from './scheduler'\nimport type { Setter } from './use'\n\nexport type Signal<T> = readonly [() => T, Setter<T>]\n\n/**\n * Create a reactive signal with a stable [getter, setter] tuple.\n *\n * Unlike `use(value)`, this is NOT tied to a component — it can be created at\n * module scope or inside arbitrary functions. The signal lives until all of\n * its subscribers are stopped and the tuple is garbage-collected.\n */\nexport function createSignal<T>(initialValue: T): Signal<T> {\n    const sc = createSignalV2(initialValue, scheduleEffect)\n    return [sc._getter, sc._setter as Setter<T>] as const\n}\n\n/**\n * Create an effect that runs immediately and re-runs when any signal it reads\n * changes. Unlike `unsafeEffect()`, this is not auto-registered with a\n * component instance — it lives until `.stop()` is called on the returned\n * handle.\n *\n * @returns a handle with `.stop()` to permanently dispose the effect\n */\nexport function createEffect(fn: () => void): { stop: () => void } {\n    const runner = createEffectV2(fn, { attachToComponent: false })\n    return { stop: () => runner.effect.stop() }\n}\n\n/**\n * Create a lazy computed signal — a derived getter that re-evaluates only\n * when one of its deps changes AND the value is actually read.\n *\n * @returns a `() => T` getter; call `.stop` on the returned handle to dispose\n */\nexport function createComputed<T>(fn: () => T): { get: () => T; stop: () => void } {\n    const c = createComputedV2(fn, scheduleEffect)\n    return { get: c.get, stop: c.stop }\n}\n"]}