@flare-engine/audio 0.4.6 → 0.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,4 +1,3 @@
1
- //#region src/audio-manager.d.ts
2
1
  /**
3
2
  * Minimal interfaces for the Web Audio API subset we use.
4
3
  * At runtime these are provided by react-native-audio-api.
@@ -54,7 +53,7 @@ type AudioState = 'uninitialized' | 'running' | 'suspended' | 'closed';
54
53
  * AudioManager — manages the AudioContext lifecycle.
55
54
  * Wraps react-native-audio-api's AudioContext.
56
55
  */
57
- declare class AudioManager {
56
+ export declare class AudioManager {
58
57
  private ctx;
59
58
  /** Current audio state. */
60
59
  get state(): AudioState;
@@ -71,8 +70,6 @@ declare class AudioManager {
71
70
  /** Close and dispose the AudioContext. */
72
71
  close(): Promise<void>;
73
72
  }
74
- //#endregion
75
- //#region src/channels.d.ts
76
73
  /** A volume channel that wraps a GainNode. */
77
74
  interface Channel {
78
75
  readonly name: string;
@@ -87,14 +84,12 @@ type ChannelName = 'master' | 'sfx' | 'music';
87
84
  * Creates volume channels connected: sfx → master, music → master, master → destination.
88
85
  * Returns a map of channels by name.
89
86
  */
90
- declare function createChannels(ctx: AudioContextLike): Map<ChannelName, Channel>;
91
- //#endregion
92
- //#region src/music.d.ts
87
+ export declare function createChannels(ctx: AudioContextLike): Map<ChannelName, Channel>;
93
88
  /**
94
89
  * Music player — one track at a time, with crossfade support.
95
90
  * Loops by default.
96
91
  */
97
- declare class Music {
92
+ export declare class Music {
98
93
  private ctx;
99
94
  private output;
100
95
  private buffers;
@@ -118,8 +113,6 @@ declare class Music {
118
113
  crossfadeTo(name: string, duration: number, loop?: boolean): void;
119
114
  private stopInternal;
120
115
  }
121
- //#endregion
122
- //#region src/sfx-pool.d.ts
123
116
  /** Options for playing a sound effect. */
124
117
  interface PlaySFXOptions {
125
118
  /** Playback volume (0-1). Default: 1. */
@@ -138,7 +131,7 @@ interface SFXHandle {
138
131
  * SFX pool — pre-decoded audio buffers with polyphony management.
139
132
  * When max polyphony is reached, the oldest sound is killed.
140
133
  */
141
- declare class SFXPool {
134
+ export declare class SFXPool {
142
135
  private buffers;
143
136
  private active;
144
137
  private ctx;
@@ -162,6 +155,5 @@ declare class SFXPool {
162
155
  /** Stop all active sounds. */
163
156
  stopAll(): void;
164
157
  }
165
- //#endregion
166
- export { type AudioBufferLike, type AudioBufferSourceNodeLike, type AudioContextLike, type AudioDestinationNodeLike, AudioManager, type AudioParamLike, type AudioState, type Channel, type ChannelName, type GainNodeLike, Music, type PlaySFXOptions, type SFXHandle, SFXPool, createChannels };
158
+ export type { AudioBufferLike, AudioBufferSourceNodeLike, AudioContextLike, AudioDestinationNodeLike, AudioParamLike, AudioState, Channel, ChannelName, GainNodeLike, PlaySFXOptions, SFXHandle };
167
159
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/audio-manager.ts","../src/channels.ts","../src/music.ts","../src/sfx-pool.ts"],"mappings":";;;;;UAKiB;WACN;;UAGM;WACN,MAAM;EACf,QAAQ,MAAM,2BAA2B;EACzC;;UAGe;EACf;EACA,eAAe,eAAe;EAC9B,wBAAwB,eAAe;;UAGxB;WACN;WACA;WACA;WACA;;UAGM;EACf,QAAQ;EACR;;;;;WAKS;IAAiB;;EAC1B,QAAQ,MAAM,eAAe;EAC7B;EACA,MAAM;EACN,KAAK;EACL,WAAW,MAAM,2BAA2B;;UAG7B;WACN;WACA;WACA,aAAa;EACtB,cAAc;EACd,sBAAsB;EACtB,UAAU;EACV,WAAW;EACX,SAAS;;;KAIC;;;;;cAMC;UACH;;MAGJ,SAAS;;MAMT,WAAW;;MAKX;;EAKJ,KAAK,eAAe;;EAMd,WAAW;;EAOX,UAAU;;EAOV,SAAS;;;;;UClGA;WACN;;EAET;;WAES,MAAM;;;KAIL;;;;;iBAMI,eAAe,KAAK,mBAAmB,IAAI,aAAa;;;;;;;cCP3D;UACH;UACA;UACA;UACA;UACA;UACA;;MAGJ;;EAKJ,QAAQ,KAAK,kBAAkB,QAAQ;;EAMvC,SAAS,cAAc,QAAQ;;EAK/B,KAAK,cAAc;;EAgCnB;;;;;EAQA,YAAY,cAAc,kBAAkB;UA+CpC;;;;;UCxHO;;EAEf;;EAEA;;EAEA;;;UAIe;;EAEf;;;;;;cAaW;UACH;UACA;UACA;UACA;UACA;cAEI;;EAMZ,QAAQ,KAAK,kBAAkB,QAAQ;;EAMvC,SAAS,cAAc,QAAQ;;EAK/B,WAAW;;EAKX,IAAI;;MAKA;;MAKA;;EAKJ,KAAK,cAAc,OAAO,iBAAiB;;EA+D3C"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/audio-manager.ts","../src/channels.ts","../src/music.ts","../src/sfx-pool.ts"],"mappings":";;;;UAKiB;WACN;;UAGM;WACN,MAAM;EACf,QAAQ,MAAM,2BAA2B;EACzC;;UAGe;EACf;EACA,eAAe,eAAe;EAC9B,wBAAwB,eAAe;;UAGxB;WACN;WACA;WACA;WACA;;UAGM;EACf,QAAQ;EACR;;;;;WAKS;IAAiB;;EAC1B,QAAQ,MAAM,eAAe;EAC7B;EACA,MAAM;EACN,KAAK;EACL,WAAW,MAAM,2BAA2B;;UAG7B;WACN;WACA;WACA,aAAa;EACtB,cAAc;EACd,sBAAsB;EACtB,UAAU;EACV,WAAW;EACX,SAAS;;;KAIC;;;;;qBAMC;UACH;;MAGJ,SAAS;;MAMT,WAAW;;MAKX;;EAKJ,KAAK,eAAe;;EAMd,WAAW;;EAOX,UAAU;;EAOV,SAAS;;;UClGA;WACN;;EAET;;WAES,MAAM;;;KAIL;;;;;wBAMI,eAAe,KAAK,mBAAmB,IAAI,aAAa;;;;;qBCP3D;UACH;UACA;UACA;UACA;UACA;UACA;;MAGJ;;EAKJ,QAAQ,KAAK,kBAAkB,QAAQ;;EAMvC,SAAS,cAAc,QAAQ;;EAK/B,KAAK,cAAc;;EAgCnB;;;;;EAQA,YAAY,cAAc,kBAAkB;UA+CpC;;;UCxHO;;EAEf;;EAEA;;EAEA;;;UAIe;;EAEf;;;;;;qBAaW;UACH;UACA;UACA;UACA;UACA;EAEI,YAAA;;EAMZ,QAAQ,KAAK,kBAAkB,QAAQ;;EAMvC,SAAS,cAAc,QAAQ;;EAK/B,WAAW;;EAKX,IAAI;;MAKA;;MAKA;;EAKJ,KAAK,cAAc,OAAO,iBAAiB;;EA+D3C"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- //#region src/audio-manager.d.ts
2
1
  /**
3
2
  * Minimal interfaces for the Web Audio API subset we use.
4
3
  * At runtime these are provided by react-native-audio-api.
@@ -54,7 +53,7 @@ type AudioState = 'uninitialized' | 'running' | 'suspended' | 'closed';
54
53
  * AudioManager — manages the AudioContext lifecycle.
55
54
  * Wraps react-native-audio-api's AudioContext.
56
55
  */
57
- declare class AudioManager {
56
+ export declare class AudioManager {
58
57
  private ctx;
59
58
  /** Current audio state. */
60
59
  get state(): AudioState;
@@ -71,8 +70,6 @@ declare class AudioManager {
71
70
  /** Close and dispose the AudioContext. */
72
71
  close(): Promise<void>;
73
72
  }
74
- //#endregion
75
- //#region src/channels.d.ts
76
73
  /** A volume channel that wraps a GainNode. */
77
74
  interface Channel {
78
75
  readonly name: string;
@@ -87,14 +84,12 @@ type ChannelName = 'master' | 'sfx' | 'music';
87
84
  * Creates volume channels connected: sfx → master, music → master, master → destination.
88
85
  * Returns a map of channels by name.
89
86
  */
90
- declare function createChannels(ctx: AudioContextLike): Map<ChannelName, Channel>;
91
- //#endregion
92
- //#region src/music.d.ts
87
+ export declare function createChannels(ctx: AudioContextLike): Map<ChannelName, Channel>;
93
88
  /**
94
89
  * Music player — one track at a time, with crossfade support.
95
90
  * Loops by default.
96
91
  */
97
- declare class Music {
92
+ export declare class Music {
98
93
  private ctx;
99
94
  private output;
100
95
  private buffers;
@@ -118,8 +113,6 @@ declare class Music {
118
113
  crossfadeTo(name: string, duration: number, loop?: boolean): void;
119
114
  private stopInternal;
120
115
  }
121
- //#endregion
122
- //#region src/sfx-pool.d.ts
123
116
  /** Options for playing a sound effect. */
124
117
  interface PlaySFXOptions {
125
118
  /** Playback volume (0-1). Default: 1. */
@@ -138,7 +131,7 @@ interface SFXHandle {
138
131
  * SFX pool — pre-decoded audio buffers with polyphony management.
139
132
  * When max polyphony is reached, the oldest sound is killed.
140
133
  */
141
- declare class SFXPool {
134
+ export declare class SFXPool {
142
135
  private buffers;
143
136
  private active;
144
137
  private ctx;
@@ -162,6 +155,5 @@ declare class SFXPool {
162
155
  /** Stop all active sounds. */
163
156
  stopAll(): void;
164
157
  }
165
- //#endregion
166
- export { type AudioBufferLike, type AudioBufferSourceNodeLike, type AudioContextLike, type AudioDestinationNodeLike, AudioManager, type AudioParamLike, type AudioState, type Channel, type ChannelName, type GainNodeLike, Music, type PlaySFXOptions, type SFXHandle, SFXPool, createChannels };
158
+ export type { AudioBufferLike, AudioBufferSourceNodeLike, AudioContextLike, AudioDestinationNodeLike, AudioParamLike, AudioState, Channel, ChannelName, GainNodeLike, PlaySFXOptions, SFXHandle };
167
159
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/audio-manager.ts","../src/channels.ts","../src/music.ts","../src/sfx-pool.ts"],"mappings":";;;;;UAKiB;WACN;;UAGM;WACN,MAAM;EACf,QAAQ,MAAM,2BAA2B;EACzC;;UAGe;EACf;EACA,eAAe,eAAe;EAC9B,wBAAwB,eAAe;;UAGxB;WACN;WACA;WACA;WACA;;UAGM;EACf,QAAQ;EACR;;;;;WAKS;IAAiB;;EAC1B,QAAQ,MAAM,eAAe;EAC7B;EACA,MAAM;EACN,KAAK;EACL,WAAW,MAAM,2BAA2B;;UAG7B;WACN;WACA;WACA,aAAa;EACtB,cAAc;EACd,sBAAsB;EACtB,UAAU;EACV,WAAW;EACX,SAAS;;;KAIC;;;;;cAMC;UACH;;MAGJ,SAAS;;MAMT,WAAW;;MAKX;;EAKJ,KAAK,eAAe;;EAMd,WAAW;;EAOX,UAAU;;EAOV,SAAS;;;;;UClGA;WACN;;EAET;;WAES,MAAM;;;KAIL;;;;;iBAMI,eAAe,KAAK,mBAAmB,IAAI,aAAa;;;;;;;cCP3D;UACH;UACA;UACA;UACA;UACA;UACA;;MAGJ;;EAKJ,QAAQ,KAAK,kBAAkB,QAAQ;;EAMvC,SAAS,cAAc,QAAQ;;EAK/B,KAAK,cAAc;;EAgCnB;;;;;EAQA,YAAY,cAAc,kBAAkB;UA+CpC;;;;;UCxHO;;EAEf;;EAEA;;EAEA;;;UAIe;;EAEf;;;;;;cAaW;UACH;UACA;UACA;UACA;UACA;cAEI;;EAMZ,QAAQ,KAAK,kBAAkB,QAAQ;;EAMvC,SAAS,cAAc,QAAQ;;EAK/B,WAAW;;EAKX,IAAI;;MAKA;;MAKA;;EAKJ,KAAK,cAAc,OAAO,iBAAiB;;EA+D3C"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/audio-manager.ts","../src/channels.ts","../src/music.ts","../src/sfx-pool.ts"],"mappings":";;;;UAKiB;WACN;;UAGM;WACN,MAAM;EACf,QAAQ,MAAM,2BAA2B;EACzC;;UAGe;EACf;EACA,eAAe,eAAe;EAC9B,wBAAwB,eAAe;;UAGxB;WACN;WACA;WACA;WACA;;UAGM;EACf,QAAQ;EACR;;;;;WAKS;IAAiB;;EAC1B,QAAQ,MAAM,eAAe;EAC7B;EACA,MAAM;EACN,KAAK;EACL,WAAW,MAAM,2BAA2B;;UAG7B;WACN;WACA;WACA,aAAa;EACtB,cAAc;EACd,sBAAsB;EACtB,UAAU;EACV,WAAW;EACX,SAAS;;;KAIC;;;;;qBAMC;UACH;;MAGJ,SAAS;;MAMT,WAAW;;MAKX;;EAKJ,KAAK,eAAe;;EAMd,WAAW;;EAOX,UAAU;;EAOV,SAAS;;;UClGA;WACN;;EAET;;WAES,MAAM;;;KAIL;;;;;wBAMI,eAAe,KAAK,mBAAmB,IAAI,aAAa;;;;;qBCP3D;UACH;UACA;UACA;UACA;UACA;UACA;;MAGJ;;EAKJ,QAAQ,KAAK,kBAAkB,QAAQ;;EAMvC,SAAS,cAAc,QAAQ;;EAK/B,KAAK,cAAc;;EAgCnB;;;;;EAQA,YAAY,cAAc,kBAAkB;UA+CpC;;;UCxHO;;EAEf;;EAEA;;EAEA;;;UAIe;;EAEf;;;;;;qBAaW;UACH;UACA;UACA;UACA;UACA;EAEI,YAAA;;EAMZ,QAAQ,KAAK,kBAAkB,QAAQ;;EAMvC,SAAS,cAAc,QAAQ;;EAK/B,WAAW;;EAKX,IAAI;;MAKA;;MAKA;;EAKJ,KAAK,cAAc,OAAO,iBAAiB;;EA+D3C"}
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region src/audio-manager.ts
2
+ // src/audio-manager.ts
3
3
  /**
4
4
  * AudioManager — manages the AudioContext lifecycle.
5
5
  * Wraps react-native-audio-api's AudioContext.
@@ -40,8 +40,7 @@ var AudioManager = class {
40
40
  }
41
41
  }
42
42
  };
43
- //#endregion
44
- //#region src/channels.ts
43
+ // src/channels.ts
45
44
  /**
46
45
  * Creates volume channels connected: sfx → master, music → master, master → destination.
47
46
  * Returns a map of channels by name.
@@ -76,8 +75,7 @@ function createChannel(name, node) {
76
75
  node
77
76
  };
78
77
  }
79
- //#endregion
80
- //#region src/music.ts
78
+ // src/music.ts
81
79
  /**
82
80
  * Music player — one track at a time, with crossfade support.
83
81
  * Loops by default.
@@ -181,8 +179,7 @@ var Music = class {
181
179
  this.currentName = null;
182
180
  }
183
181
  };
184
- //#endregion
185
- //#region src/sfx-pool.ts
182
+ // src/sfx-pool.ts
186
183
  /**
187
184
  * SFX pool — pre-decoded audio buffers with polyphony management.
188
185
  * When max polyphony is reached, the oldest sound is killed.
@@ -264,7 +261,6 @@ var SFXPool = class {
264
261
  this.active.length = 0;
265
262
  }
266
263
  };
267
- //#endregion
268
264
  exports.AudioManager = AudioManager;
269
265
  exports.Music = Music;
270
266
  exports.SFXPool = SFXPool;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/audio-manager.ts","../src/channels.ts","../src/music.ts","../src/sfx-pool.ts"],"sourcesContent":["/**\n * Minimal interfaces for the Web Audio API subset we use.\n * At runtime these are provided by react-native-audio-api.\n */\n\nexport interface AudioDestinationNodeLike {\n readonly channelCount: number;\n}\n\nexport interface GainNodeLike {\n readonly gain: AudioParamLike;\n connect(dest: AudioDestinationNodeLike | GainNodeLike): void;\n disconnect(): void;\n}\n\nexport interface AudioParamLike {\n value: number;\n setValueAtTime(value: number, time: number): void;\n linearRampToValueAtTime(value: number, time: number): void;\n}\n\nexport interface AudioBufferLike {\n readonly duration: number;\n readonly numberOfChannels: number;\n readonly sampleRate: number;\n readonly length: number;\n}\n\nexport interface AudioBufferSourceNodeLike {\n buffer: AudioBufferLike | null;\n loop: boolean;\n /**\n * Playback-rate param (Web Audio shape). Optional — not every injected node\n * exposes it; `SFXPool.play`'s `rate` option is a no-op when this is absent.\n */\n readonly playbackRate?: { value: number };\n connect(dest: GainNodeLike | AudioDestinationNodeLike): void;\n disconnect(): void;\n start(when?: number): void;\n stop(when?: number): void;\n onended: ((this: AudioBufferSourceNodeLike, ev: unknown) => void) | null;\n}\n\nexport interface AudioContextLike {\n readonly state: 'suspended' | 'running' | 'closed';\n readonly currentTime: number;\n readonly destination: AudioDestinationNodeLike;\n createGain(): GainNodeLike;\n createBufferSource(): AudioBufferSourceNodeLike;\n resume(): Promise<void>;\n suspend(): Promise<void>;\n close(): Promise<void>;\n}\n\n/** Audio context state. */\nexport type AudioState = 'uninitialized' | 'running' | 'suspended' | 'closed';\n\n/**\n * AudioManager — manages the AudioContext lifecycle.\n * Wraps react-native-audio-api's AudioContext.\n */\nexport class AudioManager {\n private ctx: AudioContextLike | null = null;\n\n /** Current audio state. */\n get state(): AudioState {\n if (!this.ctx) return 'uninitialized';\n return this.ctx.state === 'closed' ? 'closed' : this.ctx.state;\n }\n\n /** The underlying AudioContext, or null if not initialized. */\n get context(): AudioContextLike | null {\n return this.ctx;\n }\n\n /** Current time from the AudioContext. */\n get currentTime(): number {\n return this.ctx?.currentTime ?? 0;\n }\n\n /** Initialize with a factory that creates the native AudioContext. */\n init(factory: () => AudioContextLike): void {\n if (this.ctx) return;\n this.ctx = factory();\n }\n\n /** Suspend audio. Call from your own background handler — no automatic wiring. */\n async suspend(): Promise<void> {\n if (this.ctx?.state === 'running') {\n await this.ctx.suspend();\n }\n }\n\n /** Resume audio. Call from your own foreground handler — no automatic wiring. */\n async resume(): Promise<void> {\n if (this.ctx?.state === 'suspended') {\n await this.ctx.resume();\n }\n }\n\n /** Close and dispose the AudioContext. */\n async close(): Promise<void> {\n if (this.ctx) {\n await this.ctx.close();\n this.ctx = null;\n }\n }\n}\n","import type { AudioContextLike, GainNodeLike } from './audio-manager.js';\n\n/** A volume channel that wraps a GainNode. */\nexport interface Channel {\n readonly name: string;\n /** Current volume (0.0 - 1.0). */\n volume: number;\n /** The underlying GainNode. */\n readonly node: GainNodeLike;\n}\n\n/** Standard channel names. */\nexport type ChannelName = 'master' | 'sfx' | 'music';\n\n/**\n * Creates volume channels connected: sfx → master, music → master, master → destination.\n * Returns a map of channels by name.\n */\nexport function createChannels(ctx: AudioContextLike): Map<ChannelName, Channel> {\n const masterGain = ctx.createGain();\n masterGain.gain.value = 1;\n masterGain.connect(ctx.destination);\n\n const sfxGain = ctx.createGain();\n sfxGain.gain.value = 1;\n sfxGain.connect(masterGain);\n\n const musicGain = ctx.createGain();\n musicGain.gain.value = 1;\n musicGain.connect(masterGain);\n\n const channels = new Map<ChannelName, Channel>();\n\n channels.set('master', createChannel('master', masterGain));\n channels.set('sfx', createChannel('sfx', sfxGain));\n channels.set('music', createChannel('music', musicGain));\n\n return channels;\n}\n\nfunction createChannel(name: string, node: GainNodeLike): Channel {\n let vol = 1;\n return {\n name,\n get volume() {\n return vol;\n },\n set volume(v: number) {\n vol = Math.max(0, Math.min(1, v));\n node.gain.value = vol;\n },\n node,\n };\n}\n","import type {\n AudioBufferLike,\n AudioBufferSourceNodeLike,\n AudioContextLike,\n GainNodeLike,\n} from './audio-manager.js';\n\n/**\n * Music player — one track at a time, with crossfade support.\n * Loops by default.\n */\nexport class Music {\n private ctx: AudioContextLike | null = null;\n private output: GainNodeLike | null = null;\n private buffers = new Map<string, AudioBufferLike>();\n private currentSource: AudioBufferSourceNodeLike | null = null;\n private currentGain: GainNodeLike | null = null;\n private currentName: string | null = null;\n\n /** Name of the currently playing track, or null. */\n get playing(): string | null {\n return this.currentName;\n }\n\n /** Connect to an AudioContext and output gain node. */\n connect(ctx: AudioContextLike, output: GainNodeLike): void {\n this.ctx = ctx;\n this.output = output;\n }\n\n /** Register a music track buffer. */\n register(name: string, buffer: AudioBufferLike): void {\n this.buffers.set(name, buffer);\n }\n\n /** Play a track. Stops any currently playing track. Loops by default. */\n play(name: string, loop = true): void {\n if (!this.ctx || !this.output) return;\n const buffer = this.buffers.get(name);\n if (!buffer) return;\n\n this.stopInternal();\n\n const source = this.ctx.createBufferSource();\n source.buffer = buffer;\n source.loop = loop;\n\n const gain = this.ctx.createGain();\n gain.gain.value = 1;\n source.connect(gain);\n gain.connect(this.output);\n\n source.start();\n this.currentSource = source;\n this.currentGain = gain;\n this.currentName = name;\n\n source.onended = () => {\n if (this.currentSource === source) {\n this.currentSource = null;\n this.currentGain = null;\n this.currentName = null;\n }\n gain.disconnect();\n };\n }\n\n /** Stop the current track. */\n stop(): void {\n this.stopInternal();\n }\n\n /**\n * Crossfade to another track over duration seconds.\n * Fades out current and fades in the new track simultaneously.\n */\n crossfadeTo(name: string, duration: number, loop = true): void {\n if (!this.ctx || !this.output) return;\n const buffer = this.buffers.get(name);\n if (!buffer) return;\n\n const now = this.ctx.currentTime;\n\n // Fade out current\n if (this.currentGain && this.currentSource) {\n const oldGain = this.currentGain;\n const oldSource = this.currentSource;\n oldGain.gain.setValueAtTime(oldGain.gain.value, now);\n oldGain.gain.linearRampToValueAtTime(0, now + duration);\n // Schedule stop after fade\n try {\n oldSource.stop(now + duration);\n } catch {\n // Already stopped\n }\n }\n\n // Start new track fading in\n const source = this.ctx.createBufferSource();\n source.buffer = buffer;\n source.loop = loop;\n\n const gain = this.ctx.createGain();\n gain.gain.setValueAtTime(0, now);\n gain.gain.linearRampToValueAtTime(1, now + duration);\n source.connect(gain);\n gain.connect(this.output);\n\n source.start();\n this.currentSource = source;\n this.currentGain = gain;\n this.currentName = name;\n\n source.onended = () => {\n if (this.currentSource === source) {\n this.currentSource = null;\n this.currentGain = null;\n this.currentName = null;\n }\n gain.disconnect();\n };\n }\n\n private stopInternal(): void {\n if (this.currentSource) {\n try {\n this.currentSource.stop();\n } catch {\n // Already stopped\n }\n }\n if (this.currentGain) {\n this.currentGain.disconnect();\n }\n this.currentSource = null;\n this.currentGain = null;\n this.currentName = null;\n }\n}\n","import type { AudioBufferLike, AudioContextLike, GainNodeLike } from './audio-manager.js';\n\n/** Options for playing a sound effect. */\nexport interface PlaySFXOptions {\n /** Playback volume (0-1). Default: 1. */\n volume?: number;\n /** Playback rate multiplier. Default: 1. Applied only when the audio node exposes a `playbackRate` param. */\n rate?: number;\n /** Whether to loop. Default: false. */\n loop?: boolean;\n}\n\n/** A handle to a playing SFX instance. */\nexport interface SFXHandle {\n /** Stop playback. */\n stop(): void;\n}\n\n/** Tracks an active playing source. */\ninterface ActiveSource {\n name: string;\n stop(): void;\n}\n\n/**\n * SFX pool — pre-decoded audio buffers with polyphony management.\n * When max polyphony is reached, the oldest sound is killed.\n */\nexport class SFXPool {\n private buffers = new Map<string, AudioBufferLike>();\n private active: ActiveSource[] = [];\n private ctx: AudioContextLike | null = null;\n private output: GainNodeLike | null = null;\n private maxPolyphony: number;\n\n constructor(maxPolyphony = 16) {\n if (maxPolyphony <= 0) throw new Error('SFXPool: maxPolyphony must be > 0');\n this.maxPolyphony = maxPolyphony;\n }\n\n /** Connect to an AudioContext and output GainNode. */\n connect(ctx: AudioContextLike, output: GainNodeLike): void {\n this.ctx = ctx;\n this.output = output;\n }\n\n /** Register a pre-decoded audio buffer. */\n register(name: string, buffer: AudioBufferLike): void {\n this.buffers.set(name, buffer);\n }\n\n /** Unregister a buffer. */\n unregister(name: string): void {\n this.buffers.delete(name);\n }\n\n /** Check if a buffer is registered. */\n has(name: string): boolean {\n return this.buffers.has(name);\n }\n\n /** Number of registered buffers. */\n get size(): number {\n return this.buffers.size;\n }\n\n /** Number of currently active sounds. */\n get activeCount(): number {\n return this.active.length;\n }\n\n /** Play a registered sound. Returns a handle, or null if not registered/no context. */\n play(name: string, opts?: PlaySFXOptions): SFXHandle | null {\n const buffer = this.buffers.get(name);\n if (!buffer || !this.ctx || !this.output) return null;\n\n // Kill oldest if at max polyphony\n while (this.active.length >= this.maxPolyphony) {\n const oldest = this.active.shift();\n oldest?.stop();\n }\n\n const source = this.ctx.createBufferSource();\n source.buffer = buffer;\n source.loop = opts?.loop ?? false;\n\n // Apply playback rate when the injected node exposes the param (Web Audio shape).\n const rateParam = source.playbackRate;\n if (rateParam && opts?.rate !== undefined) {\n rateParam.value = opts.rate;\n }\n\n // Create a per-source gain for volume control\n const gain = this.ctx.createGain();\n gain.gain.value = opts?.volume ?? 1;\n source.connect(gain);\n gain.connect(this.output);\n\n const entry: ActiveSource = {\n name,\n stop() {\n try {\n source.stop();\n } catch {\n // Already stopped\n }\n gain.disconnect();\n },\n };\n\n this.active.push(entry);\n\n // Clean up when playback ends\n source.onended = () => {\n const idx = this.active.indexOf(entry);\n if (idx !== -1) {\n this.active.splice(idx, 1);\n }\n gain.disconnect();\n };\n\n source.start();\n\n return {\n stop: () => {\n entry.stop();\n const idx = this.active.indexOf(entry);\n if (idx !== -1) {\n this.active.splice(idx, 1);\n }\n },\n };\n }\n\n /** Stop all active sounds. */\n stopAll(): void {\n for (const entry of this.active) {\n entry.stop();\n }\n this.active.length = 0;\n }\n}\n"],"mapp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AK,CAAC;EAE7B,EACF;CACF;;CAGA,UAAgB;EACd,KAAK,MAAM,SAAS,KAAK,QACvB,MAAM,KAAK;EAEb,KAAK,OAAO,SAAS;CACvB;AACF"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/audio-manager.ts","../src/channels.ts","../src/music.ts","../src/sfx-pool.ts"],"sourcesContent":["/**\n * Minimal interfaces for the Web Audio API subset we use.\n * At runtime these are provided by react-native-audio-api.\n */\n\nexport interface AudioDestinationNodeLike {\n readonly channelCount: number;\n}\n\nexport interface GainNodeLike {\n readonly gain: AudioParamLike;\n connect(dest: AudioDestinationNodeLike | GainNodeLike): void;\n disconnect(): void;\n}\n\nexport interface AudioParamLike {\n value: number;\n setValueAtTime(value: number, time: number): void;\n linearRampToValueAtTime(value: number, time: number): void;\n}\n\nexport interface AudioBufferLike {\n readonly duration: number;\n readonly numberOfChannels: number;\n readonly sampleRate: number;\n readonly length: number;\n}\n\nexport interface AudioBufferSourceNodeLike {\n buffer: AudioBufferLike | null;\n loop: boolean;\n /**\n * Playback-rate param (Web Audio shape). Optional — not every injected node\n * exposes it; `SFXPool.play`'s `rate` option is a no-op when this is absent.\n */\n readonly playbackRate?: { value: number };\n connect(dest: GainNodeLike | AudioDestinationNodeLike): void;\n disconnect(): void;\n start(when?: number): void;\n stop(when?: number): void;\n onended: ((this: AudioBufferSourceNodeLike, ev: unknown) => void) | null;\n}\n\nexport interface AudioContextLike {\n readonly state: 'suspended' | 'running' | 'closed';\n readonly currentTime: number;\n readonly destination: AudioDestinationNodeLike;\n createGain(): GainNodeLike;\n createBufferSource(): AudioBufferSourceNodeLike;\n resume(): Promise<void>;\n suspend(): Promise<void>;\n close(): Promise<void>;\n}\n\n/** Audio context state. */\nexport type AudioState = 'uninitialized' | 'running' | 'suspended' | 'closed';\n\n/**\n * AudioManager — manages the AudioContext lifecycle.\n * Wraps react-native-audio-api's AudioContext.\n */\nexport class AudioManager {\n private ctx: AudioContextLike | null = null;\n\n /** Current audio state. */\n get state(): AudioState {\n if (!this.ctx) return 'uninitialized';\n return this.ctx.state === 'closed' ? 'closed' : this.ctx.state;\n }\n\n /** The underlying AudioContext, or null if not initialized. */\n get context(): AudioContextLike | null {\n return this.ctx;\n }\n\n /** Current time from the AudioContext. */\n get currentTime(): number {\n return this.ctx?.currentTime ?? 0;\n }\n\n /** Initialize with a factory that creates the native AudioContext. */\n init(factory: () => AudioContextLike): void {\n if (this.ctx) return;\n this.ctx = factory();\n }\n\n /** Suspend audio. Call from your own background handler — no automatic wiring. */\n async suspend(): Promise<void> {\n if (this.ctx?.state === 'running') {\n await this.ctx.suspend();\n }\n }\n\n /** Resume audio. Call from your own foreground handler — no automatic wiring. */\n async resume(): Promise<void> {\n if (this.ctx?.state === 'suspended') {\n await this.ctx.resume();\n }\n }\n\n /** Close and dispose the AudioContext. */\n async close(): Promise<void> {\n if (this.ctx) {\n await this.ctx.close();\n this.ctx = null;\n }\n }\n}\n","import type { AudioContextLike, GainNodeLike } from './audio-manager.js';\n\n/** A volume channel that wraps a GainNode. */\nexport interface Channel {\n readonly name: string;\n /** Current volume (0.0 - 1.0). */\n volume: number;\n /** The underlying GainNode. */\n readonly node: GainNodeLike;\n}\n\n/** Standard channel names. */\nexport type ChannelName = 'master' | 'sfx' | 'music';\n\n/**\n * Creates volume channels connected: sfx → master, music → master, master → destination.\n * Returns a map of channels by name.\n */\nexport function createChannels(ctx: AudioContextLike): Map<ChannelName, Channel> {\n const masterGain = ctx.createGain();\n masterGain.gain.value = 1;\n masterGain.connect(ctx.destination);\n\n const sfxGain = ctx.createGain();\n sfxGain.gain.value = 1;\n sfxGain.connect(masterGain);\n\n const musicGain = ctx.createGain();\n musicGain.gain.value = 1;\n musicGain.connect(masterGain);\n\n const channels = new Map<ChannelName, Channel>();\n\n channels.set('master', createChannel('master', masterGain));\n channels.set('sfx', createChannel('sfx', sfxGain));\n channels.set('music', createChannel('music', musicGain));\n\n return channels;\n}\n\nfunction createChannel(name: string, node: GainNodeLike): Channel {\n let vol = 1;\n return {\n name,\n get volume() {\n return vol;\n },\n set volume(v: number) {\n vol = Math.max(0, Math.min(1, v));\n node.gain.value = vol;\n },\n node,\n };\n}\n","import type {\n AudioBufferLike,\n AudioBufferSourceNodeLike,\n AudioContextLike,\n GainNodeLike,\n} from './audio-manager.js';\n\n/**\n * Music player — one track at a time, with crossfade support.\n * Loops by default.\n */\nexport class Music {\n private ctx: AudioContextLike | null = null;\n private output: GainNodeLike | null = null;\n private buffers = new Map<string, AudioBufferLike>();\n private currentSource: AudioBufferSourceNodeLike | null = null;\n private currentGain: GainNodeLike | null = null;\n private currentName: string | null = null;\n\n /** Name of the currently playing track, or null. */\n get playing(): string | null {\n return this.currentName;\n }\n\n /** Connect to an AudioContext and output gain node. */\n connect(ctx: AudioContextLike, output: GainNodeLike): void {\n this.ctx = ctx;\n this.output = output;\n }\n\n /** Register a music track buffer. */\n register(name: string, buffer: AudioBufferLike): void {\n this.buffers.set(name, buffer);\n }\n\n /** Play a track. Stops any currently playing track. Loops by default. */\n play(name: string, loop = true): void {\n if (!this.ctx || !this.output) return;\n const buffer = this.buffers.get(name);\n if (!buffer) return;\n\n this.stopInternal();\n\n const source = this.ctx.createBufferSource();\n source.buffer = buffer;\n source.loop = loop;\n\n const gain = this.ctx.createGain();\n gain.gain.value = 1;\n source.connect(gain);\n gain.connect(this.output);\n\n source.start();\n this.currentSource = source;\n this.currentGain = gain;\n this.currentName = name;\n\n source.onended = () => {\n if (this.currentSource === source) {\n this.currentSource = null;\n this.currentGain = null;\n this.currentName = null;\n }\n gain.disconnect();\n };\n }\n\n /** Stop the current track. */\n stop(): void {\n this.stopInternal();\n }\n\n /**\n * Crossfade to another track over duration seconds.\n * Fades out current and fades in the new track simultaneously.\n */\n crossfadeTo(name: string, duration: number, loop = true): void {\n if (!this.ctx || !this.output) return;\n const buffer = this.buffers.get(name);\n if (!buffer) return;\n\n const now = this.ctx.currentTime;\n\n // Fade out current\n if (this.currentGain && this.currentSource) {\n const oldGain = this.currentGain;\n const oldSource = this.currentSource;\n oldGain.gain.setValueAtTime(oldGain.gain.value, now);\n oldGain.gain.linearRampToValueAtTime(0, now + duration);\n // Schedule stop after fade\n try {\n oldSource.stop(now + duration);\n } catch {\n // Already stopped\n }\n }\n\n // Start new track fading in\n const source = this.ctx.createBufferSource();\n source.buffer = buffer;\n source.loop = loop;\n\n const gain = this.ctx.createGain();\n gain.gain.setValueAtTime(0, now);\n gain.gain.linearRampToValueAtTime(1, now + duration);\n source.connect(gain);\n gain.connect(this.output);\n\n source.start();\n this.currentSource = source;\n this.currentGain = gain;\n this.currentName = name;\n\n source.onended = () => {\n if (this.currentSource === source) {\n this.currentSource = null;\n this.currentGain = null;\n this.currentName = null;\n }\n gain.disconnect();\n };\n }\n\n private stopInternal(): void {\n if (this.currentSource) {\n try {\n this.currentSource.stop();\n } catch {\n // Already stopped\n }\n }\n if (this.currentGain) {\n this.currentGain.disconnect();\n }\n this.currentSource = null;\n this.currentGain = null;\n this.currentName = null;\n }\n}\n","import type { AudioBufferLike, AudioContextLike, GainNodeLike } from './audio-manager.js';\n\n/** Options for playing a sound effect. */\nexport interface PlaySFXOptions {\n /** Playback volume (0-1). Default: 1. */\n volume?: number;\n /** Playback rate multiplier. Default: 1. Applied only when the audio node exposes a `playbackRate` param. */\n rate?: number;\n /** Whether to loop. Default: false. */\n loop?: boolean;\n}\n\n/** A handle to a playing SFX instance. */\nexport interface SFXHandle {\n /** Stop playback. */\n stop(): void;\n}\n\n/** Tracks an active playing source. */\ninterface ActiveSource {\n name: string;\n stop(): void;\n}\n\n/**\n * SFX pool — pre-decoded audio buffers with polyphony management.\n * When max polyphony is reached, the oldest sound is killed.\n */\nexport class SFXPool {\n private buffers = new Map<string, AudioBufferLike>();\n private active: ActiveSource[] = [];\n private ctx: AudioContextLike | null = null;\n private output: GainNodeLike | null = null;\n private maxPolyphony: number;\n\n constructor(maxPolyphony = 16) {\n if (maxPolyphony <= 0) throw new Error('SFXPool: maxPolyphony must be > 0');\n this.maxPolyphony = maxPolyphony;\n }\n\n /** Connect to an AudioContext and output GainNode. */\n connect(ctx: AudioContextLike, output: GainNodeLike): void {\n this.ctx = ctx;\n this.output = output;\n }\n\n /** Register a pre-decoded audio buffer. */\n register(name: string, buffer: AudioBufferLike): void {\n this.buffers.set(name, buffer);\n }\n\n /** Unregister a buffer. */\n unregister(name: string): void {\n this.buffers.delete(name);\n }\n\n /** Check if a buffer is registered. */\n has(name: string): boolean {\n return this.buffers.has(name);\n }\n\n /** Number of registered buffers. */\n get size(): number {\n return this.buffers.size;\n }\n\n /** Number of currently active sounds. */\n get activeCount(): number {\n return this.active.length;\n }\n\n /** Play a registered sound. Returns a handle, or null if not registered/no context. */\n play(name: string, opts?: PlaySFXOptions): SFXHandle | null {\n const buffer = this.buffers.get(name);\n if (!buffer || !this.ctx || !this.output) return null;\n\n // Kill oldest if at max polyphony\n while (this.active.length >= this.maxPolyphony) {\n const oldest = this.active.shift();\n oldest?.stop();\n }\n\n const source = this.ctx.createBufferSource();\n source.buffer = buffer;\n source.loop = opts?.loop ?? false;\n\n // Apply playback rate when the injected node exposes the param (Web Audio shape).\n const rateParam = source.playbackRate;\n if (rateParam && opts?.rate !== undefined) {\n rateParam.value = opts.rate;\n }\n\n // Create a per-source gain for volume control\n const gain = this.ctx.createGain();\n gain.gain.value = opts?.volume ?? 1;\n source.connect(gain);\n gain.connect(this.output);\n\n const entry: ActiveSource = {\n name,\n stop() {\n try {\n source.stop();\n } catch {\n // Already stopped\n }\n gain.disconnect();\n },\n };\n\n this.active.push(entry);\n\n // Clean up when playback ends\n source.onended = () => {\n const idx = this.active.indexOf(entry);\n if (idx !== -1) {\n this.active.splice(idx, 1);\n }\n gain.disconnect();\n };\n\n source.start();\n\n return {\n stop: () => {\n entry.stop();\n const idx = this.active.indexOf(entry);\n if (idx !== -1) {\n this.active.splice(idx, 1);\n }\n },\n };\n }\n\n /** Stop all active sounds. */\n stopAll(): void {\n for (const entry of this.active) {\n entry.stop();\n }\n this.active.length =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,OAAO,OAAO,KAAK,CAAC;EAE7B,EACF;CACF;;CAGA,UAAgB;EACd,KAAK,MAAM,SAAS,KAAK,QACvB,MAAM,KAAK;EAEb,KAAK,OAAO,SAAS;CACvB;AACF"}
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- //#region src/audio-manager.ts
1
+ // src/audio-manager.ts
2
2
  /**
3
3
  * AudioManager — manages the AudioContext lifecycle.
4
4
  * Wraps react-native-audio-api's AudioContext.
@@ -39,8 +39,7 @@ var AudioManager = class {
39
39
  }
40
40
  }
41
41
  };
42
- //#endregion
43
- //#region src/channels.ts
42
+ // src/channels.ts
44
43
  /**
45
44
  * Creates volume channels connected: sfx → master, music → master, master → destination.
46
45
  * Returns a map of channels by name.
@@ -75,8 +74,7 @@ function createChannel(name, node) {
75
74
  node
76
75
  };
77
76
  }
78
- //#endregion
79
- //#region src/music.ts
77
+ // src/music.ts
80
78
  /**
81
79
  * Music player — one track at a time, with crossfade support.
82
80
  * Loops by default.
@@ -180,8 +178,7 @@ var Music = class {
180
178
  this.currentName = null;
181
179
  }
182
180
  };
183
- //#endregion
184
- //#region src/sfx-pool.ts
181
+ // src/sfx-pool.ts
185
182
  /**
186
183
  * SFX pool — pre-decoded audio buffers with polyphony management.
187
184
  * When max polyphony is reached, the oldest sound is killed.
@@ -263,7 +260,6 @@ var SFXPool = class {
263
260
  this.active.length = 0;
264
261
  }
265
262
  };
266
- //#endregion
267
263
  export { AudioManager, Music, SFXPool, createChannels };
268
264
 
269
265
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/audio-manager.ts","../src/channels.ts","../src/music.ts","../src/sfx-pool.ts"],"sourcesContent":["/**\n * Minimal interfaces for the Web Audio API subset we use.\n * At runtime these are provided by react-native-audio-api.\n */\n\nexport interface AudioDestinationNodeLike {\n readonly channelCount: number;\n}\n\nexport interface GainNodeLike {\n readonly gain: AudioParamLike;\n connect(dest: AudioDestinationNodeLike | GainNodeLike): void;\n disconnect(): void;\n}\n\nexport interface AudioParamLike {\n value: number;\n setValueAtTime(value: number, time: number): void;\n linearRampToValueAtTime(value: number, time: number): void;\n}\n\nexport interface AudioBufferLike {\n readonly duration: number;\n readonly numberOfChannels: number;\n readonly sampleRate: number;\n readonly length: number;\n}\n\nexport interface AudioBufferSourceNodeLike {\n buffer: AudioBufferLike | null;\n loop: boolean;\n /**\n * Playback-rate param (Web Audio shape). Optional — not every injected node\n * exposes it; `SFXPool.play`'s `rate` option is a no-op when this is absent.\n */\n readonly playbackRate?: { value: number };\n connect(dest: GainNodeLike | AudioDestinationNodeLike): void;\n disconnect(): void;\n start(when?: number): void;\n stop(when?: number): void;\n onended: ((this: AudioBufferSourceNodeLike, ev: unknown) => void) | null;\n}\n\nexport interface AudioContextLike {\n readonly state: 'suspended' | 'running' | 'closed';\n readonly currentTime: number;\n readonly destination: AudioDestinationNodeLike;\n createGain(): GainNodeLike;\n createBufferSource(): AudioBufferSourceNodeLike;\n resume(): Promise<void>;\n suspend(): Promise<void>;\n close(): Promise<void>;\n}\n\n/** Audio context state. */\nexport type AudioState = 'uninitialized' | 'running' | 'suspended' | 'closed';\n\n/**\n * AudioManager — manages the AudioContext lifecycle.\n * Wraps react-native-audio-api's AudioContext.\n */\nexport class AudioManager {\n private ctx: AudioContextLike | null = null;\n\n /** Current audio state. */\n get state(): AudioState {\n if (!this.ctx) return 'uninitialized';\n return this.ctx.state === 'closed' ? 'closed' : this.ctx.state;\n }\n\n /** The underlying AudioContext, or null if not initialized. */\n get context(): AudioContextLike | null {\n return this.ctx;\n }\n\n /** Current time from the AudioContext. */\n get currentTime(): number {\n return this.ctx?.currentTime ?? 0;\n }\n\n /** Initialize with a factory that creates the native AudioContext. */\n init(factory: () => AudioContextLike): void {\n if (this.ctx) return;\n this.ctx = factory();\n }\n\n /** Suspend audio. Call from your own background handler — no automatic wiring. */\n async suspend(): Promise<void> {\n if (this.ctx?.state === 'running') {\n await this.ctx.suspend();\n }\n }\n\n /** Resume audio. Call from your own foreground handler — no automatic wiring. */\n async resume(): Promise<void> {\n if (this.ctx?.state === 'suspended') {\n await this.ctx.resume();\n }\n }\n\n /** Close and dispose the AudioContext. */\n async close(): Promise<void> {\n if (this.ctx) {\n await this.ctx.close();\n this.ctx = null;\n }\n }\n}\n","import type { AudioContextLike, GainNodeLike } from './audio-manager.js';\n\n/** A volume channel that wraps a GainNode. */\nexport interface Channel {\n readonly name: string;\n /** Current volume (0.0 - 1.0). */\n volume: number;\n /** The underlying GainNode. */\n readonly node: GainNodeLike;\n}\n\n/** Standard channel names. */\nexport type ChannelName = 'master' | 'sfx' | 'music';\n\n/**\n * Creates volume channels connected: sfx → master, music → master, master → destination.\n * Returns a map of channels by name.\n */\nexport function createChannels(ctx: AudioContextLike): Map<ChannelName, Channel> {\n const masterGain = ctx.createGain();\n masterGain.gain.value = 1;\n masterGain.connect(ctx.destination);\n\n const sfxGain = ctx.createGain();\n sfxGain.gain.value = 1;\n sfxGain.connect(masterGain);\n\n const musicGain = ctx.createGain();\n musicGain.gain.value = 1;\n musicGain.connect(masterGain);\n\n const channels = new Map<ChannelName, Channel>();\n\n channels.set('master', createChannel('master', masterGain));\n channels.set('sfx', createChannel('sfx', sfxGain));\n channels.set('music', createChannel('music', musicGain));\n\n return channels;\n}\n\nfunction createChannel(name: string, node: GainNodeLike): Channel {\n let vol = 1;\n return {\n name,\n get volume() {\n return vol;\n },\n set volume(v: number) {\n vol = Math.max(0, Math.min(1, v));\n node.gain.value = vol;\n },\n node,\n };\n}\n","import type {\n AudioBufferLike,\n AudioBufferSourceNodeLike,\n AudioContextLike,\n GainNodeLike,\n} from './audio-manager.js';\n\n/**\n * Music player — one track at a time, with crossfade support.\n * Loops by default.\n */\nexport class Music {\n private ctx: AudioContextLike | null = null;\n private output: GainNodeLike | null = null;\n private buffers = new Map<string, AudioBufferLike>();\n private currentSource: AudioBufferSourceNodeLike | null = null;\n private currentGain: GainNodeLike | null = null;\n private currentName: string | null = null;\n\n /** Name of the currently playing track, or null. */\n get playing(): string | null {\n return this.currentName;\n }\n\n /** Connect to an AudioContext and output gain node. */\n connect(ctx: AudioContextLike, output: GainNodeLike): void {\n this.ctx = ctx;\n this.output = output;\n }\n\n /** Register a music track buffer. */\n register(name: string, buffer: AudioBufferLike): void {\n this.buffers.set(name, buffer);\n }\n\n /** Play a track. Stops any currently playing track. Loops by default. */\n play(name: string, loop = true): void {\n if (!this.ctx || !this.output) return;\n const buffer = this.buffers.get(name);\n if (!buffer) return;\n\n this.stopInternal();\n\n const source = this.ctx.createBufferSource();\n source.buffer = buffer;\n source.loop = loop;\n\n const gain = this.ctx.createGain();\n gain.gain.value = 1;\n source.connect(gain);\n gain.connect(this.output);\n\n source.start();\n this.currentSource = source;\n this.currentGain = gain;\n this.currentName = name;\n\n source.onended = () => {\n if (this.currentSource === source) {\n this.currentSource = null;\n this.currentGain = null;\n this.currentName = null;\n }\n gain.disconnect();\n };\n }\n\n /** Stop the current track. */\n stop(): void {\n this.stopInternal();\n }\n\n /**\n * Crossfade to another track over duration seconds.\n * Fades out current and fades in the new track simultaneously.\n */\n crossfadeTo(name: string, duration: number, loop = true): void {\n if (!this.ctx || !this.output) return;\n const buffer = this.buffers.get(name);\n if (!buffer) return;\n\n const now = this.ctx.currentTime;\n\n // Fade out current\n if (this.currentGain && this.currentSource) {\n const oldGain = this.currentGain;\n const oldSource = this.currentSource;\n oldGain.gain.setValueAtTime(oldGain.gain.value, now);\n oldGain.gain.linearRampToValueAtTime(0, now + duration);\n // Schedule stop after fade\n try {\n oldSource.stop(now + duration);\n } catch {\n // Already stopped\n }\n }\n\n // Start new track fading in\n const source = this.ctx.createBufferSource();\n source.buffer = buffer;\n source.loop = loop;\n\n const gain = this.ctx.createGain();\n gain.gain.setValueAtTime(0, now);\n gain.gain.linearRampToValueAtTime(1, now + duration);\n source.connect(gain);\n gain.connect(this.output);\n\n source.start();\n this.currentSource = source;\n this.currentGain = gain;\n this.currentName = name;\n\n source.onended = () => {\n if (this.currentSource === source) {\n this.currentSource = null;\n this.currentGain = null;\n this.currentName = null;\n }\n gain.disconnect();\n };\n }\n\n private stopInternal(): void {\n if (this.currentSource) {\n try {\n this.currentSource.stop();\n } catch {\n // Already stopped\n }\n }\n if (this.currentGain) {\n this.currentGain.disconnect();\n }\n this.currentSource = null;\n this.currentGain = null;\n this.currentName = null;\n }\n}\n","import type { AudioBufferLike, AudioContextLike, GainNodeLike } from './audio-manager.js';\n\n/** Options for playing a sound effect. */\nexport interface PlaySFXOptions {\n /** Playback volume (0-1). Default: 1. */\n volume?: number;\n /** Playback rate multiplier. Default: 1. Applied only when the audio node exposes a `playbackRate` param. */\n rate?: number;\n /** Whether to loop. Default: false. */\n loop?: boolean;\n}\n\n/** A handle to a playing SFX instance. */\nexport interface SFXHandle {\n /** Stop playback. */\n stop(): void;\n}\n\n/** Tracks an active playing source. */\ninterface ActiveSource {\n name: string;\n stop(): void;\n}\n\n/**\n * SFX pool — pre-decoded audio buffers with polyphony management.\n * When max polyphony is reached, the oldest sound is killed.\n */\nexport class SFXPool {\n private buffers = new Map<string, AudioBufferLike>();\n private active: ActiveSource[] = [];\n private ctx: AudioContextLike | null = null;\n private output: GainNodeLike | null = null;\n private maxPolyphony: number;\n\n constructor(maxPolyphony = 16) {\n if (maxPolyphony <= 0) throw new Error('SFXPool: maxPolyphony must be > 0');\n this.maxPolyphony = maxPolyphony;\n }\n\n /** Connect to an AudioContext and output GainNode. */\n connect(ctx: AudioContextLike, output: GainNodeLike): void {\n this.ctx = ctx;\n this.output = output;\n }\n\n /** Register a pre-decoded audio buffer. */\n register(name: string, buffer: AudioBufferLike): void {\n this.buffers.set(name, buffer);\n }\n\n /** Unregister a buffer. */\n unregister(name: string): void {\n this.buffers.delete(name);\n }\n\n /** Check if a buffer is registered. */\n has(name: string): boolean {\n return this.buffers.has(name);\n }\n\n /** Number of registered buffers. */\n get size(): number {\n return this.buffers.size;\n }\n\n /** Number of currently active sounds. */\n get activeCount(): number {\n return this.active.length;\n }\n\n /** Play a registered sound. Returns a handle, or null if not registered/no context. */\n play(name: string, opts?: PlaySFXOptions): SFXHandle | null {\n const buffer = this.buffers.get(name);\n if (!buffer || !this.ctx || !this.output) return null;\n\n // Kill oldest if at max polyphony\n while (this.active.length >= this.maxPolyphony) {\n const oldest = this.active.shift();\n oldest?.stop();\n }\n\n const source = this.ctx.createBufferSource();\n source.buffer = buffer;\n source.loop = opts?.loop ?? false;\n\n // Apply playback rate when the injected node exposes the param (Web Audio shape).\n const rateParam = source.playbackRate;\n if (rateParam && opts?.rate !== undefined) {\n rateParam.value = opts.rate;\n }\n\n // Create a per-source gain for volume control\n const gain = this.ctx.createGain();\n gain.gain.value = opts?.volume ?? 1;\n source.connect(gain);\n gain.connect(this.output);\n\n const entry: ActiveSource = {\n name,\n stop() {\n try {\n source.stop();\n } catch {\n // Already stopped\n }\n gain.disconnect();\n },\n };\n\n this.active.push(entry);\n\n // Clean up when playback ends\n source.onended = () => {\n const idx = this.active.indexOf(entry);\n if (idx !== -1) {\n this.active.splice(idx, 1);\n }\n gain.disconnect();\n };\n\n source.start();\n\n return {\n stop: () => {\n entry.stop();\n const idx = this.active.indexOf(entry);\n if (idx !== -1) {\n this.active.splice(idx, 1);\n }\n },\n };\n }\n\n /** Stop all active sounds. */\n stopAll(): void {\n for (const entry of this.active) {\n entry.stop();\n }\n this.active.length = 0;\n }\n}\n"],"mappings":";;;;;AA6DA,IAAa,eAAb,MAA0B;CACxB,MAAuC;;CAGvC,IAAI,QAAoB;EACtB,IAAI,CAAC,KAAK,KAAK,OAAO;EACtB,OAAO,KAAK,IAAI,UAAU,WAAW,WAAW,KAAK,IAAI;CAC3D;;CAGA,IAAI,UAAmC;EACrC,OAAO,KAAK;CACd;;CAGA,IAAI,cAAsB;EACxB,OAAO,KAAK,KAAK,eAAe;CAClC;;CAGA,KAAK,SAAuC;EAC1C,IAAI,KAAK,KAAK;EACd,KAAK,MAAM,QAAQ;CACrB;;CAGA,MAAM,UAAyB;EA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AAU,CAAC,KAAK,OAAO,CAAC,KAAK,QAAQ,OAAO;EAGjD,OAAO,KAAK,OAAO,UAAU,KAAK,cAEhC,KADoB,OAAO,MACtB,CAAC,EAAE,KAAK;EAGf,MAAM,SAAS,KAAK,IAAI,mBAAmB;EAC3C,OAAO,SAAS;EAChB,OAAO,OAAO,MAAM,QAAQ;EAG5B,MAAM,YAAY,OAAO;EACzB,IAAI,aAAa,MAAM,SAAS,KAAA,GAC9B,UAAU,QAAQ,KAAK;EAIzB,MAAM,OAAO,KAAK,IAAI,WAAW;EACjC,KAAK,KAAK,QAAQ,MAAM,UAAU;EAClC,OAAO,QAAQ,IAAI;EACnB,KAAK,QAAQ,KAAK,MAAM;EAExB,MAAM,QAAsB;GAC1B;GACA,OAAO;IACL,IAAI;KACF,OAAO,KAAK;IACd,QAAQ,CAER;IACA,KAAK,WAAW;GAClB;EACF;EAEA,KAAK,OAAO,KAAK,KAAK;EAGtB,OAAO,gBAAgB;GACrB,MAAM,MAAM,KAAK,OAAO,QAAQ,KAAK;GACrC,IAAI,QAAQ,IACV,KAAK,OAAO,OAAO,KAAK,CAAC;GAE3B,KAAK,WAAW;EAClB;EAEA,OAAO,MAAM;EAEb,OAAO,EACL,YAAY;GACV,MAAM,KAAK;GACX,MAAM,MAAM,KAAK,OAAO,QAAQ,KAAK;GACrC,IAAI,QAAQ,IACV,KAAK,OAAO,OAAO,KAAK,CAAC;EAE7B,EACF;CACF;;CAGA,UAAgB;EACd,KAAK,MAAM,SAAS,KAAK,QACvB,MAAM,KAAK;EAEb,KAAK,OAAO,SAAS;CACvB;AACF"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/audio-manager.ts","../src/channels.ts","../src/music.ts","../src/sfx-pool.ts"],"sourcesContent":["/**\n * Minimal interfaces for the Web Audio API subset we use.\n * At runtime these are provided by react-native-audio-api.\n */\n\nexport interface AudioDestinationNodeLike {\n readonly channelCount: number;\n}\n\nexport interface GainNodeLike {\n readonly gain: AudioParamLike;\n connect(dest: AudioDestinationNodeLike | GainNodeLike): void;\n disconnect(): void;\n}\n\nexport interface AudioParamLike {\n value: number;\n setValueAtTime(value: number, time: number): void;\n linearRampToValueAtTime(value: number, time: number): void;\n}\n\nexport interface AudioBufferLike {\n readonly duration: number;\n readonly numberOfChannels: number;\n readonly sampleRate: number;\n readonly length: number;\n}\n\nexport interface AudioBufferSourceNodeLike {\n buffer: AudioBufferLike | null;\n loop: boolean;\n /**\n * Playback-rate param (Web Audio shape). Optional — not every injected node\n * exposes it; `SFXPool.play`'s `rate` option is a no-op when this is absent.\n */\n readonly playbackRate?: { value: number };\n connect(dest: GainNodeLike | AudioDestinationNodeLike): void;\n disconnect(): void;\n start(when?: number): void;\n stop(when?: number): void;\n onended: ((this: AudioBufferSourceNodeLike, ev: unknown) => void) | null;\n}\n\nexport interface AudioContextLike {\n readonly state: 'suspended' | 'running' | 'closed';\n readonly currentTime: number;\n readonly destination: AudioDestinationNodeLike;\n createGain(): GainNodeLike;\n createBufferSource(): AudioBufferSourceNodeLike;\n resume(): Promise<void>;\n suspend(): Promise<void>;\n close(): Promise<void>;\n}\n\n/** Audio context state. */\nexport type AudioState = 'uninitialized' | 'running' | 'suspended' | 'closed';\n\n/**\n * AudioManager — manages the AudioContext lifecycle.\n * Wraps react-native-audio-api's AudioContext.\n */\nexport class AudioManager {\n private ctx: AudioContextLike | null = null;\n\n /** Current audio state. */\n get state(): AudioState {\n if (!this.ctx) return 'uninitialized';\n return this.ctx.state === 'closed' ? 'closed' : this.ctx.state;\n }\n\n /** The underlying AudioContext, or null if not initialized. */\n get context(): AudioContextLike | null {\n return this.ctx;\n }\n\n /** Current time from the AudioContext. */\n get currentTime(): number {\n return this.ctx?.currentTime ?? 0;\n }\n\n /** Initialize with a factory that creates the native AudioContext. */\n init(factory: () => AudioContextLike): void {\n if (this.ctx) return;\n this.ctx = factory();\n }\n\n /** Suspend audio. Call from your own background handler — no automatic wiring. */\n async suspend(): Promise<void> {\n if (this.ctx?.state === 'running') {\n await this.ctx.suspend();\n }\n }\n\n /** Resume audio. Call from your own foreground handler — no automatic wiring. */\n async resume(): Promise<void> {\n if (this.ctx?.state === 'suspended') {\n await this.ctx.resume();\n }\n }\n\n /** Close and dispose the AudioContext. */\n async close(): Promise<void> {\n if (this.ctx) {\n await this.ctx.close();\n this.ctx = null;\n }\n }\n}\n","import type { AudioContextLike, GainNodeLike } from './audio-manager.js';\n\n/** A volume channel that wraps a GainNode. */\nexport interface Channel {\n readonly name: string;\n /** Current volume (0.0 - 1.0). */\n volume: number;\n /** The underlying GainNode. */\n readonly node: GainNodeLike;\n}\n\n/** Standard channel names. */\nexport type ChannelName = 'master' | 'sfx' | 'music';\n\n/**\n * Creates volume channels connected: sfx → master, music → master, master → destination.\n * Returns a map of channels by name.\n */\nexport function createChannels(ctx: AudioContextLike): Map<ChannelName, Channel> {\n const masterGain = ctx.createGain();\n masterGain.gain.value = 1;\n masterGain.connect(ctx.destination);\n\n const sfxGain = ctx.createGain();\n sfxGain.gain.value = 1;\n sfxGain.connect(masterGain);\n\n const musicGain = ctx.createGain();\n musicGain.gain.value = 1;\n musicGain.connect(masterGain);\n\n const channels = new Map<ChannelName, Channel>();\n\n channels.set('master', createChannel('master', masterGain));\n channels.set('sfx', createChannel('sfx', sfxGain));\n channels.set('music', createChannel('music', musicGain));\n\n return channels;\n}\n\nfunction createChannel(name: string, node: GainNodeLike): Channel {\n let vol = 1;\n return {\n name,\n get volume() {\n return vol;\n },\n set volume(v: number) {\n vol = Math.max(0, Math.min(1, v));\n node.gain.value = vol;\n },\n node,\n };\n}\n","import type {\n AudioBufferLike,\n AudioBufferSourceNodeLike,\n AudioContextLike,\n GainNodeLike,\n} from './audio-manager.js';\n\n/**\n * Music player — one track at a time, with crossfade support.\n * Loops by default.\n */\nexport class Music {\n private ctx: AudioContextLike | null = null;\n private output: GainNodeLike | null = null;\n private buffers = new Map<string, AudioBufferLike>();\n private currentSource: AudioBufferSourceNodeLike | null = null;\n private currentGain: GainNodeLike | null = null;\n private currentName: string | null = null;\n\n /** Name of the currently playing track, or null. */\n get playing(): string | null {\n return this.currentName;\n }\n\n /** Connect to an AudioContext and output gain node. */\n connect(ctx: AudioContextLike, output: GainNodeLike): void {\n this.ctx = ctx;\n this.output = output;\n }\n\n /** Register a music track buffer. */\n register(name: string, buffer: AudioBufferLike): void {\n this.buffers.set(name, buffer);\n }\n\n /** Play a track. Stops any currently playing track. Loops by default. */\n play(name: string, loop = true): void {\n if (!this.ctx || !this.output) return;\n const buffer = this.buffers.get(name);\n if (!buffer) return;\n\n this.stopInternal();\n\n const source = this.ctx.createBufferSource();\n source.buffer = buffer;\n source.loop = loop;\n\n const gain = this.ctx.createGain();\n gain.gain.value = 1;\n source.connect(gain);\n gain.connect(this.output);\n\n source.start();\n this.currentSource = source;\n this.currentGain = gain;\n this.currentName = name;\n\n source.onended = () => {\n if (this.currentSource === source) {\n this.currentSource = null;\n this.currentGain = null;\n this.currentName = null;\n }\n gain.disconnect();\n };\n }\n\n /** Stop the current track. */\n stop(): void {\n this.stopInternal();\n }\n\n /**\n * Crossfade to another track over duration seconds.\n * Fades out current and fades in the new track simultaneously.\n */\n crossfadeTo(name: string, duration: number, loop = true): void {\n if (!this.ctx || !this.output) return;\n const buffer = this.buffers.get(name);\n if (!buffer) return;\n\n const now = this.ctx.currentTime;\n\n // Fade out current\n if (this.currentGain && this.currentSource) {\n const oldGain = this.currentGain;\n const oldSource = this.currentSource;\n oldGain.gain.setValueAtTime(oldGain.gain.value, now);\n oldGain.gain.linearRampToValueAtTime(0, now + duration);\n // Schedule stop after fade\n try {\n oldSource.stop(now + duration);\n } catch {\n // Already stopped\n }\n }\n\n // Start new track fading in\n const source = this.ctx.createBufferSource();\n source.buffer = buffer;\n source.loop = loop;\n\n const gain = this.ctx.createGain();\n gain.gain.setValueAtTime(0, now);\n gain.gain.linearRampToValueAtTime(1, now + duration);\n source.connect(gain);\n gain.connect(this.output);\n\n source.start();\n this.currentSource = source;\n this.currentGain = gain;\n this.currentName = name;\n\n source.onended = () => {\n if (this.currentSource === source) {\n this.currentSource = null;\n this.currentGain = null;\n this.currentName = null;\n }\n gain.disconnect();\n };\n }\n\n private stopInternal(): void {\n if (this.currentSource) {\n try {\n this.currentSource.stop();\n } catch {\n // Already stopped\n }\n }\n if (this.currentGain) {\n this.currentGain.disconnect();\n }\n this.currentSource = null;\n this.currentGain = null;\n this.currentName = null;\n }\n}\n","import type { AudioBufferLike, AudioContextLike, GainNodeLike } from './audio-manager.js';\n\n/** Options for playing a sound effect. */\nexport interface PlaySFXOptions {\n /** Playback volume (0-1). Default: 1. */\n volume?: number;\n /** Playback rate multiplier. Default: 1. Applied only when the audio node exposes a `playbackRate` param. */\n rate?: number;\n /** Whether to loop. Default: false. */\n loop?: boolean;\n}\n\n/** A handle to a playing SFX instance. */\nexport interface SFXHandle {\n /** Stop playback. */\n stop(): void;\n}\n\n/** Tracks an active playing source. */\ninterface ActiveSource {\n name: string;\n stop(): void;\n}\n\n/**\n * SFX pool — pre-decoded audio buffers with polyphony management.\n * When max polyphony is reached, the oldest sound is killed.\n */\nexport class SFXPool {\n private buffers = new Map<string, AudioBufferLike>();\n private active: ActiveSource[] = [];\n private ctx: AudioContextLike | null = null;\n private output: GainNodeLike | null = null;\n private maxPolyphony: number;\n\n constructor(maxPolyphony = 16) {\n if (maxPolyphony <= 0) throw new Error('SFXPool: maxPolyphony must be > 0');\n this.maxPolyphony = maxPolyphony;\n }\n\n /** Connect to an AudioContext and output GainNode. */\n connect(ctx: AudioContextLike, output: GainNodeLike): void {\n this.ctx = ctx;\n this.output = output;\n }\n\n /** Register a pre-decoded audio buffer. */\n register(name: string, buffer: AudioBufferLike): void {\n this.buffers.set(name, buffer);\n }\n\n /** Unregister a buffer. */\n unregister(name: string): void {\n this.buffers.delete(name);\n }\n\n /** Check if a buffer is registered. */\n has(name: string): boolean {\n return this.buffers.has(name);\n }\n\n /** Number of registered buffers. */\n get size(): number {\n return this.buffers.size;\n }\n\n /** Number of currently active sounds. */\n get activeCount(): number {\n return this.active.length;\n }\n\n /** Play a registered sound. Returns a handle, or null if not registered/no context. */\n play(name: string, opts?: PlaySFXOptions): SFXHandle | null {\n const buffer = this.buffers.get(name);\n if (!buffer || !this.ctx || !this.output) return null;\n\n // Kill oldest if at max polyphony\n while (this.active.length >= this.maxPolyphony) {\n const oldest = this.active.shift();\n oldest?.stop();\n }\n\n const source = this.ctx.createBufferSource();\n source.buffer = buffer;\n source.loop = opts?.loop ?? false;\n\n // Apply playback rate when the injected node exposes the param (Web Audio shape).\n const rateParam = source.playbackRate;\n if (rateParam && opts?.rate !== undefined) {\n rateParam.value = opts.rate;\n }\n\n // Create a per-source gain for volume control\n const gain = this.ctx.createGain();\n gain.gain.value = opts?.volume ?? 1;\n source.connect(gain);\n gain.connect(this.output);\n\n const entry: ActiveSource = {\n name,\n stop() {\n try {\n source.stop();\n } catch {\n // Already stopped\n }\n gain.disconnect();\n },\n };\n\n this.active.push(entry);\n\n // Clean up when playback ends\n source.onended = () => {\n const idx = this.active.indexOf(entry);\n if (idx !== -1) {\n this.active.splice(idx, 1);\n }\n gain.disconnect();\n };\n\n source.start();\n\n return {\n stop: () => {\n entry.stop();\n const idx = this.active.indexOf(entry);\n if (idx !== -1) {\n this.active.splice(idx, 1);\n }\n },\n };\n }\n\n /** Stop all active sounds. */\n stopAll(): void {\n for (const entry of this.active) {\n entry.stop();\n }\n this.active.length = 0;\n }\n}\n"],"mappings":";;;;;AA6DA,IAAa,eAAb,MAA0B;CACxB,MAAuC;;CAGvC,IAAI,QAAoB;EACtB,IAAI,CAAC,KAAK,KAAK,OAAO;EACtB,OAAO,KAAK,IAAI,UAAU,WAAW,WAAW,KAAK,IAAI;CAC3D;;CAGA,IAAI,UAAmC;EACrC,OAAO,KAAK;CACd;;CAGA,IAAI,cAAsB;EACxB,OAAO,KAAK,KAAK,eAAe;CAClC;;CAGA,KAAK,SAAuC;EAC1C,IAAI,KAAK,KAAK;EACd,KAAK,MAAM,QAAQ;CACrB;;C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pC,IAAI,CAAC,UAAU,CAAC,KAAK,OAAO,CAAC,KAAK,QAAQ,OAAO;EAGjD,OAAO,KAAK,OAAO,UAAU,KAAK,cAEhC,KADoB,OAAO,MACtB,CAAC,EAAE,KAAK;EAGf,MAAM,SAAS,KAAK,IAAI,mBAAmB;EAC3C,OAAO,SAAS;EAChB,OAAO,OAAO,MAAM,QAAQ;EAG5B,MAAM,YAAY,OAAO;EACzB,IAAI,aAAa,MAAM,SAAS,KAAA,GAC9B,UAAU,QAAQ,KAAK;EAIzB,MAAM,OAAO,KAAK,IAAI,WAAW;EACjC,KAAK,KAAK,QAAQ,MAAM,UAAU;EAClC,OAAO,QAAQ,IAAI;EACnB,KAAK,QAAQ,KAAK,MAAM;EAExB,MAAM,QAAsB;GAC1B;GACA,OAAO;IACL,IAAI;KACF,OAAO,KAAK;IACd,QAAQ,CAER;IACA,KAAK,WAAW;GAClB;EACF;EAEA,KAAK,OAAO,KAAK,KAAK;EAGtB,OAAO,gBAAgB;GACrB,MAAM,MAAM,KAAK,OAAO,QAAQ,KAAK;GACrC,IAAI,QAAQ,IACV,KAAK,OAAO,OAAO,KAAK,CAAC;GAE3B,KAAK,WAAW;EAClB;EAEA,OAAO,MAAM;EAEb,OAAO,EACL,YAAY;GACV,MAAM,KAAK;GACX,MAAM,MAAM,KAAK,OAAO,QAAQ,KAAK;GACrC,IAAI,QAAQ,IACV,KAAK,OAAO,OAAO,KAAK,CAAC;EAE7B,EACF;CACF;;CAGA,UAAgB;EACd,KAAK,MAAM,SAAS,KAAK,QACvB,MAAM,KAAK;EAEb,KAAK,OAAO,SAAS;CACvB;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flare-engine/audio",
3
- "version": "0.4.6",
3
+ "version": "0.4.7",
4
4
  "description": "AudioManager, SFX pool, music crossfade",
5
5
  "keywords": ["flare-engine", "audio", "sfx", "music"],
6
6
  "license": "Apache-2.0",