{"version":3,"file":"use-audio-bus.cjs","names":[],"sources":["../../src/audio/use-audio-bus.ts"],"sourcesContent":["import { useEffect, useState } from \"react\";\nimport { createAudioBus, type AudioBus, type AudioBusOptions } from \"./audio-bus\";\n\n/**\n * Keep one {@link AudioBus} alive for as long as the component is mounted.\n *\n * The bus is built on the first render and closed on unmount, which matters more\n * than it looks: browsers cap the number of live `AudioContext`s (Chrome allows\n * around six), so a bus leaked on unmount eventually breaks every later one on\n * the page.\n *\n * Options are read once. A bus is a device route and a mixing graph, not a\n * render output — rebuilding it because a prop changed would drop every attached\n * source mid-sentence. Change gain and output through the bus itself.\n *\n * @param options - See {@link AudioBusOptions}. Read on the first render only.\n * @returns The bus, stable for the component's lifetime.\n *\n * @example\n * const bus = useAudioBus({ maxGain: 3 });\n *\n * useEffect(() => {\n *   const handle = bus.attach(stream, { gain: 1 });\n *   return () => handle.stop();\n * }, [bus, stream]);\n */\nexport function useAudioBus(options: AudioBusOptions = {}): AudioBus {\n    const [bus] = useState<AudioBus>(() => createAudioBus(options));\n\n    useEffect(() => {\n        return () => bus.close();\n    }, [bus]);\n\n    return bus;\n}\n"],"mappings":"0DA0BA,SAAgB,EAAY,EAA2B,CAAC,EAAa,CACjE,GAAM,CAAC,IAAA,EAAO,EAAA,SAAA,KAAyB,EAAA,eAAe,CAAO,CAAC,EAM9D,OAJA,EAAA,EAAA,UAAA,SACiB,EAAI,MAAM,EACxB,CAAC,CAAG,CAAC,EAED,CACX"}