@react-text-game/core 0.4.0 → 0.5.0
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/README.md +389 -0
- package/dist/audio/audioTrack.d.ts +407 -0
- package/dist/audio/audioTrack.d.ts.map +1 -0
- package/dist/audio/audioTrack.js +656 -0
- package/dist/audio/audioTrack.js.map +1 -0
- package/dist/audio/constants.d.ts +19 -0
- package/dist/audio/constants.d.ts.map +1 -0
- package/dist/audio/constants.js +20 -0
- package/dist/audio/constants.js.map +1 -0
- package/dist/audio/fabric.d.ts +35 -0
- package/dist/audio/fabric.d.ts.map +1 -0
- package/dist/audio/fabric.js +36 -0
- package/dist/audio/fabric.js.map +1 -0
- package/dist/audio/index.d.ts +33 -0
- package/dist/audio/index.d.ts.map +1 -0
- package/dist/audio/index.js +32 -0
- package/dist/audio/index.js.map +1 -0
- package/dist/audio/types.d.ts +105 -0
- package/dist/audio/types.d.ts.map +1 -0
- package/dist/audio/types.js +2 -0
- package/dist/audio/types.js.map +1 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/useAudio.d.ts +50 -0
- package/dist/hooks/useAudio.d.ts.map +1 -0
- package/dist/hooks/useAudio.js +42 -0
- package/dist/hooks/useAudio.js.map +1 -0
- package/dist/hooks/useAudioManager.d.ts +66 -0
- package/dist/hooks/useAudioManager.d.ts.map +1 -0
- package/dist/hooks/useAudioManager.js +70 -0
- package/dist/hooks/useAudioManager.js.map +1 -0
- package/dist/i18n/utils.d.ts.map +1 -1
- package/dist/i18n/utils.js +6 -0
- package/dist/i18n/utils.js.map +1 -1
- package/dist/tests/audio.test.d.ts +2 -0
- package/dist/tests/audio.test.d.ts.map +1 -0
- package/dist/tests/audio.test.js +605 -0
- package/dist/tests/audio.test.js.map +1 -0
- package/package.json +6 -2
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { STORAGE_SYSTEM_PATH } from "../constants";
|
|
2
|
+
/**
|
|
3
|
+
* Base JSONPath for audio storage within the system path.
|
|
4
|
+
*
|
|
5
|
+
* All audio tracks with IDs will be stored under this path.
|
|
6
|
+
* Individual tracks are stored at: $._system.audio.{id}
|
|
7
|
+
*/
|
|
8
|
+
export const AUDIO_STORAGE_PATH = `${STORAGE_SYSTEM_PATH}.audio`;
|
|
9
|
+
/**
|
|
10
|
+
* Default audio configuration values.
|
|
11
|
+
*/
|
|
12
|
+
export const DEFAULT_AUDIO_OPTIONS = {
|
|
13
|
+
volume: 1.0,
|
|
14
|
+
loop: false,
|
|
15
|
+
playbackRate: 1.0,
|
|
16
|
+
muted: false,
|
|
17
|
+
autoPlay: false,
|
|
18
|
+
preload: "metadata",
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/audio/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAGjD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,mBAAmB,QAAoC,CAAC;AAE7F;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACjC,MAAM,EAAE,GAAG;IACX,IAAI,EAAE,KAAK;IACX,YAAY,EAAE,GAAG;IACjB,KAAK,EAAE,KAAK;IACZ,QAAQ,EAAE,KAAK;IACf,OAAO,EAAE,UAAmB;CACtB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { AudioTrack } from "./audioTrack";
|
|
2
|
+
import type { AudioOptions } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Factory function to create a new audio track.
|
|
5
|
+
*
|
|
6
|
+
* Follows the project's factory-first pattern similar to createEntity() and newStory().
|
|
7
|
+
* Creates an AudioTrack instance with reactive state management and automatic
|
|
8
|
+
* registration with the AudioManager.
|
|
9
|
+
*
|
|
10
|
+
* @param src - Path to the audio file (relative or absolute URL)
|
|
11
|
+
* @param options - Optional audio configuration
|
|
12
|
+
* @returns A reactive AudioTrack instance
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // Create background music with auto-save
|
|
17
|
+
* const bgMusic = createAudio('assets/music/theme.mp3', {
|
|
18
|
+
* id: 'bg-music',
|
|
19
|
+
* loop: true,
|
|
20
|
+
* volume: 0.5,
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* await bgMusic.play();
|
|
24
|
+
* bgMusic.setVolume(0.7);
|
|
25
|
+
*
|
|
26
|
+
* // Create sound effect (no ID = no auto-save)
|
|
27
|
+
* const clickSound = createAudio('assets/sfx/click.mp3', {
|
|
28
|
+
* volume: 0.8,
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* clickSound.play();
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare const createAudio: (src: string, options?: AudioOptions) => AudioTrack;
|
|
35
|
+
//# sourceMappingURL=fabric.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fabric.d.ts","sourceRoot":"","sources":["../../src/audio/fabric.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,WAAW,GACpB,KAAK,MAAM,EACX,UAAU,YAAY,KACvB,UAEF,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { AudioTrack } from "./audioTrack";
|
|
2
|
+
/**
|
|
3
|
+
* Factory function to create a new audio track.
|
|
4
|
+
*
|
|
5
|
+
* Follows the project's factory-first pattern similar to createEntity() and newStory().
|
|
6
|
+
* Creates an AudioTrack instance with reactive state management and automatic
|
|
7
|
+
* registration with the AudioManager.
|
|
8
|
+
*
|
|
9
|
+
* @param src - Path to the audio file (relative or absolute URL)
|
|
10
|
+
* @param options - Optional audio configuration
|
|
11
|
+
* @returns A reactive AudioTrack instance
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // Create background music with auto-save
|
|
16
|
+
* const bgMusic = createAudio('assets/music/theme.mp3', {
|
|
17
|
+
* id: 'bg-music',
|
|
18
|
+
* loop: true,
|
|
19
|
+
* volume: 0.5,
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* await bgMusic.play();
|
|
23
|
+
* bgMusic.setVolume(0.7);
|
|
24
|
+
*
|
|
25
|
+
* // Create sound effect (no ID = no auto-save)
|
|
26
|
+
* const clickSound = createAudio('assets/sfx/click.mp3', {
|
|
27
|
+
* volume: 0.8,
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* clickSound.play();
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export const createAudio = (src, options) => {
|
|
34
|
+
return new AudioTrack(src, options);
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=fabric.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fabric.js","sourceRoot":"","sources":["../../src/audio/fabric.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CACvB,GAAW,EACX,OAAsB,EACZ,EAAE;IACZ,OAAO,IAAI,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AACxC,CAAC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Audio module for the react-text-game engine.
|
|
3
|
+
*
|
|
4
|
+
* Provides comprehensive audio support with reactive state management,
|
|
5
|
+
* automatic persistence, and global controls.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { createAudio, AudioManager } from '@react-text-game/core/audio';
|
|
10
|
+
*
|
|
11
|
+
* // Create and control audio tracks
|
|
12
|
+
* const music = createAudio('music.mp3', {
|
|
13
|
+
* id: 'bg-music',
|
|
14
|
+
* loop: true,
|
|
15
|
+
* volume: 0.7,
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* await music.play();
|
|
19
|
+
* music.pause();
|
|
20
|
+
* music.setVolume(0.5);
|
|
21
|
+
*
|
|
22
|
+
* // Global controls
|
|
23
|
+
* AudioManager.setMasterVolume(0.8);
|
|
24
|
+
* AudioManager.muteAll();
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @module audio
|
|
28
|
+
*/
|
|
29
|
+
export { AudioManager, AudioTrack } from "./audioTrack";
|
|
30
|
+
export { AUDIO_STORAGE_PATH, DEFAULT_AUDIO_OPTIONS } from "./constants";
|
|
31
|
+
export { createAudio } from "./fabric";
|
|
32
|
+
export type { AudioOptions, AudioSaveState, AudioState, } from "./types";
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/audio/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,YAAY,EACR,YAAY,EACZ,cAAc,EACd,UAAU,GACb,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Audio module for the react-text-game engine.
|
|
3
|
+
*
|
|
4
|
+
* Provides comprehensive audio support with reactive state management,
|
|
5
|
+
* automatic persistence, and global controls.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { createAudio, AudioManager } from '@react-text-game/core/audio';
|
|
10
|
+
*
|
|
11
|
+
* // Create and control audio tracks
|
|
12
|
+
* const music = createAudio('music.mp3', {
|
|
13
|
+
* id: 'bg-music',
|
|
14
|
+
* loop: true,
|
|
15
|
+
* volume: 0.7,
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* await music.play();
|
|
19
|
+
* music.pause();
|
|
20
|
+
* music.setVolume(0.5);
|
|
21
|
+
*
|
|
22
|
+
* // Global controls
|
|
23
|
+
* AudioManager.setMasterVolume(0.8);
|
|
24
|
+
* AudioManager.muteAll();
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @module audio
|
|
28
|
+
*/
|
|
29
|
+
export { AudioManager, AudioTrack } from "./audioTrack";
|
|
30
|
+
export { AUDIO_STORAGE_PATH, DEFAULT_AUDIO_OPTIONS } from "./constants";
|
|
31
|
+
export { createAudio } from "./fabric";
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/audio/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for creating an audio track.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* const audio = createAudio('music.mp3', {
|
|
7
|
+
* id: 'bg-music',
|
|
8
|
+
* volume: 0.7,
|
|
9
|
+
* loop: true,
|
|
10
|
+
* autoPlay: false,
|
|
11
|
+
* });
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export interface AudioOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Unique identifier for the audio track.
|
|
17
|
+
* Required for save/load functionality.
|
|
18
|
+
* If not provided, a random ID will be generated.
|
|
19
|
+
*/
|
|
20
|
+
id?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Initial volume level (0.0 to 1.0).
|
|
23
|
+
* @default 1.0
|
|
24
|
+
*/
|
|
25
|
+
volume?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Whether to loop the audio automatically.
|
|
28
|
+
* @default false
|
|
29
|
+
*/
|
|
30
|
+
loop?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Playback rate multiplier (0.5 = half speed, 2.0 = double speed).
|
|
33
|
+
* @default 1.0
|
|
34
|
+
*/
|
|
35
|
+
playbackRate?: number;
|
|
36
|
+
/**
|
|
37
|
+
* Whether to start muted.
|
|
38
|
+
* @default false
|
|
39
|
+
*/
|
|
40
|
+
muted?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Auto-play on creation.
|
|
43
|
+
* Note: May be blocked by browser autoplay policies.
|
|
44
|
+
* @default false
|
|
45
|
+
*/
|
|
46
|
+
autoPlay?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Preload strategy for the audio file.
|
|
49
|
+
* - 'none': Don't preload
|
|
50
|
+
* - 'metadata': Preload only metadata
|
|
51
|
+
* - 'auto': Let browser decide
|
|
52
|
+
* @default 'metadata'
|
|
53
|
+
*/
|
|
54
|
+
preload?: "none" | "metadata" | "auto";
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Reactive state of an audio track.
|
|
58
|
+
*
|
|
59
|
+
* This interface represents the observable state that can be used
|
|
60
|
+
* with React hooks for reactive updates.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const state = audio.getState();
|
|
65
|
+
* console.log(state.isPlaying); // true/false
|
|
66
|
+
* console.log(state.currentTime); // 45.2
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export interface AudioState {
|
|
70
|
+
/** Whether audio is currently playing */
|
|
71
|
+
isPlaying: boolean;
|
|
72
|
+
/** Whether audio is paused */
|
|
73
|
+
isPaused: boolean;
|
|
74
|
+
/** Whether audio is stopped */
|
|
75
|
+
isStopped: boolean;
|
|
76
|
+
/** Current playback position in seconds */
|
|
77
|
+
currentTime: number;
|
|
78
|
+
/** Total duration in seconds */
|
|
79
|
+
duration: number;
|
|
80
|
+
/** Current volume (0.0 to 1.0) */
|
|
81
|
+
volume: number;
|
|
82
|
+
/** Whether audio is looping */
|
|
83
|
+
loop: boolean;
|
|
84
|
+
/** Current playback rate multiplier */
|
|
85
|
+
playbackRate: number;
|
|
86
|
+
/** Whether audio is muted */
|
|
87
|
+
muted: boolean;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Saved state for audio track persistence.
|
|
91
|
+
*
|
|
92
|
+
* This is a subset of AudioState that gets persisted to storage.
|
|
93
|
+
*/
|
|
94
|
+
export interface AudioSaveState {
|
|
95
|
+
id: string;
|
|
96
|
+
src: string;
|
|
97
|
+
volume: number;
|
|
98
|
+
loop: boolean;
|
|
99
|
+
playbackRate: number;
|
|
100
|
+
muted: boolean;
|
|
101
|
+
currentTime: number;
|
|
102
|
+
isPlaying: boolean;
|
|
103
|
+
isPaused: boolean;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/audio/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,YAAY;IACzB;;;;OAIG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,CAAC;CAC1C;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,UAAU;IACvB,yCAAyC;IACzC,SAAS,EAAE,OAAO,CAAC;IAEnB,8BAA8B;IAC9B,QAAQ,EAAE,OAAO,CAAC;IAElB,+BAA+B;IAC/B,SAAS,EAAE,OAAO,CAAC;IAEnB,2CAA2C;IAC3C,WAAW,EAAE,MAAM,CAAC;IAEpB,gCAAgC;IAChC,QAAQ,EAAE,MAAM,CAAC;IAEjB,kCAAkC;IAClC,MAAM,EAAE,MAAM,CAAC;IAEf,+BAA+B;IAC/B,IAAI,EAAE,OAAO,CAAC;IAEd,uCAAuC;IACvC,YAAY,EAAE,MAAM,CAAC;IAErB,6BAA6B;IAC7B,KAAK,EAAE,OAAO,CAAC;CAClB;AAED;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,OAAO,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;CACrB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/audio/types.ts"],"names":[],"mappings":""}
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC"}
|
package/dist/hooks/index.js
CHANGED
package/dist/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { AudioTrack } from "../audio";
|
|
2
|
+
/**
|
|
3
|
+
* React hook to access reactive audio state.
|
|
4
|
+
*
|
|
5
|
+
* This hook makes audio state observable in React components, automatically
|
|
6
|
+
* triggering re-renders when the audio state changes (playback position,
|
|
7
|
+
* volume, playing status, etc.).
|
|
8
|
+
*
|
|
9
|
+
* @param audio - The audio track to observe
|
|
10
|
+
* @returns Reactive audio state snapshot
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { createAudio } from '@react-text-game/core/audio';
|
|
15
|
+
* import { useAudio } from '@react-text-game/core';
|
|
16
|
+
*
|
|
17
|
+
* const bgMusic = createAudio('music.mp3', {
|
|
18
|
+
* id: 'bg-music',
|
|
19
|
+
* loop: true,
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* function MusicPlayer() {
|
|
23
|
+
* const audioState = useAudio(bgMusic);
|
|
24
|
+
*
|
|
25
|
+
* return (
|
|
26
|
+
* <div>
|
|
27
|
+
* <p>Playing: {audioState.isPlaying ? 'Yes' : 'No'}</p>
|
|
28
|
+
* <p>Time: {audioState.currentTime.toFixed(1)}s / {audioState.duration.toFixed(1)}s</p>
|
|
29
|
+
* <p>Volume: {(audioState.volume * 100).toFixed(0)}%</p>
|
|
30
|
+
*
|
|
31
|
+
* <button onClick={() => bgMusic.play()}>Play</button>
|
|
32
|
+
* <button onClick={() => bgMusic.pause()}>Pause</button>
|
|
33
|
+
* <button onClick={() => bgMusic.stop()}>Stop</button>
|
|
34
|
+
* </div>
|
|
35
|
+
* );
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare const useAudio: (audio: AudioTrack) => {
|
|
40
|
+
readonly isPlaying: boolean;
|
|
41
|
+
readonly isPaused: boolean;
|
|
42
|
+
readonly isStopped: boolean;
|
|
43
|
+
readonly currentTime: number;
|
|
44
|
+
readonly duration: number;
|
|
45
|
+
readonly volume: number;
|
|
46
|
+
readonly loop: boolean;
|
|
47
|
+
readonly playbackRate: number;
|
|
48
|
+
readonly muted: boolean;
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=useAudio.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAudio.d.ts","sourceRoot":"","sources":["../../src/hooks/useAudio.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,QAAQ,GAAI,OAAO,UAAU;;;;;;;;;;CAEzC,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useSnapshot } from "valtio";
|
|
2
|
+
/**
|
|
3
|
+
* React hook to access reactive audio state.
|
|
4
|
+
*
|
|
5
|
+
* This hook makes audio state observable in React components, automatically
|
|
6
|
+
* triggering re-renders when the audio state changes (playback position,
|
|
7
|
+
* volume, playing status, etc.).
|
|
8
|
+
*
|
|
9
|
+
* @param audio - The audio track to observe
|
|
10
|
+
* @returns Reactive audio state snapshot
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { createAudio } from '@react-text-game/core/audio';
|
|
15
|
+
* import { useAudio } from '@react-text-game/core';
|
|
16
|
+
*
|
|
17
|
+
* const bgMusic = createAudio('music.mp3', {
|
|
18
|
+
* id: 'bg-music',
|
|
19
|
+
* loop: true,
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* function MusicPlayer() {
|
|
23
|
+
* const audioState = useAudio(bgMusic);
|
|
24
|
+
*
|
|
25
|
+
* return (
|
|
26
|
+
* <div>
|
|
27
|
+
* <p>Playing: {audioState.isPlaying ? 'Yes' : 'No'}</p>
|
|
28
|
+
* <p>Time: {audioState.currentTime.toFixed(1)}s / {audioState.duration.toFixed(1)}s</p>
|
|
29
|
+
* <p>Volume: {(audioState.volume * 100).toFixed(0)}%</p>
|
|
30
|
+
*
|
|
31
|
+
* <button onClick={() => bgMusic.play()}>Play</button>
|
|
32
|
+
* <button onClick={() => bgMusic.pause()}>Pause</button>
|
|
33
|
+
* <button onClick={() => bgMusic.stop()}>Stop</button>
|
|
34
|
+
* </div>
|
|
35
|
+
* );
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export const useAudio = (audio) => {
|
|
40
|
+
return useSnapshot(audio.getState());
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=useAudio.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAudio.js","sourceRoot":"","sources":["../../src/hooks/useAudio.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAIrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAiB,EAAE,EAAE;IAC1C,OAAO,WAAW,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;AACzC,CAAC,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React hook to access global audio manager state and controls.
|
|
3
|
+
*
|
|
4
|
+
* This hook provides access to the AudioManager's reactive state
|
|
5
|
+
* (master volume, mute status) and bound control methods.
|
|
6
|
+
*
|
|
7
|
+
* @returns Reactive audio manager state and control methods
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { useAudioManager } from '@react-text-game/core';
|
|
12
|
+
*
|
|
13
|
+
* function AudioSettingsMenu() {
|
|
14
|
+
* const audioManager = useAudioManager();
|
|
15
|
+
*
|
|
16
|
+
* return (
|
|
17
|
+
* <div>
|
|
18
|
+
* <h2>Audio Settings</h2>
|
|
19
|
+
*
|
|
20
|
+
* <label>
|
|
21
|
+
* Master Volume: {(audioManager.masterVolume * 100).toFixed(0)}%
|
|
22
|
+
* <input
|
|
23
|
+
* type="range"
|
|
24
|
+
* min="0"
|
|
25
|
+
* max="1"
|
|
26
|
+
* step="0.01"
|
|
27
|
+
* value={audioManager.masterVolume}
|
|
28
|
+
* onChange={(e) => audioManager.setMasterVolume(parseFloat(e.target.value))}
|
|
29
|
+
* />
|
|
30
|
+
* </label>
|
|
31
|
+
*
|
|
32
|
+
* <button onClick={audioManager.muteAll}>
|
|
33
|
+
* Mute All
|
|
34
|
+
* </button>
|
|
35
|
+
* <button onClick={audioManager.unmuteAll}>
|
|
36
|
+
* Unmute All
|
|
37
|
+
* </button>
|
|
38
|
+
* <button onClick={audioManager.pauseAll}>
|
|
39
|
+
* Pause All
|
|
40
|
+
* </button>
|
|
41
|
+
* <button onClick={audioManager.resumeAll}>
|
|
42
|
+
* Resume All
|
|
43
|
+
* </button>
|
|
44
|
+
*
|
|
45
|
+
* <p>Muted: {audioManager.isMuted ? 'Yes' : 'No'}</p>
|
|
46
|
+
* <p>Total Tracks: {audioManager.getAllTracks().length}</p>
|
|
47
|
+
* </div>
|
|
48
|
+
* );
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare const useAudioManager: () => {
|
|
53
|
+
setMasterVolume: (volume: number) => void;
|
|
54
|
+
getMasterVolume: () => number;
|
|
55
|
+
muteAll: () => void;
|
|
56
|
+
unmuteAll: () => void;
|
|
57
|
+
pauseAll: () => void;
|
|
58
|
+
resumeAll: () => void;
|
|
59
|
+
stopAll: () => void;
|
|
60
|
+
getAllTracks: () => Array<import("../audio").AudioTrack>;
|
|
61
|
+
getTrackById: (id: string) => import("../audio").AudioTrack | undefined;
|
|
62
|
+
disposeAll: () => void;
|
|
63
|
+
masterVolume: number;
|
|
64
|
+
isMuted: boolean;
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=useAudioManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAudioManager.d.ts","sourceRoot":"","sources":["../../src/hooks/useAudioManager.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;CAgB3B,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { useSnapshot } from "valtio";
|
|
2
|
+
import { AudioManager } from "../audio";
|
|
3
|
+
/**
|
|
4
|
+
* React hook to access global audio manager state and controls.
|
|
5
|
+
*
|
|
6
|
+
* This hook provides access to the AudioManager's reactive state
|
|
7
|
+
* (master volume, mute status) and bound control methods.
|
|
8
|
+
*
|
|
9
|
+
* @returns Reactive audio manager state and control methods
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { useAudioManager } from '@react-text-game/core';
|
|
14
|
+
*
|
|
15
|
+
* function AudioSettingsMenu() {
|
|
16
|
+
* const audioManager = useAudioManager();
|
|
17
|
+
*
|
|
18
|
+
* return (
|
|
19
|
+
* <div>
|
|
20
|
+
* <h2>Audio Settings</h2>
|
|
21
|
+
*
|
|
22
|
+
* <label>
|
|
23
|
+
* Master Volume: {(audioManager.masterVolume * 100).toFixed(0)}%
|
|
24
|
+
* <input
|
|
25
|
+
* type="range"
|
|
26
|
+
* min="0"
|
|
27
|
+
* max="1"
|
|
28
|
+
* step="0.01"
|
|
29
|
+
* value={audioManager.masterVolume}
|
|
30
|
+
* onChange={(e) => audioManager.setMasterVolume(parseFloat(e.target.value))}
|
|
31
|
+
* />
|
|
32
|
+
* </label>
|
|
33
|
+
*
|
|
34
|
+
* <button onClick={audioManager.muteAll}>
|
|
35
|
+
* Mute All
|
|
36
|
+
* </button>
|
|
37
|
+
* <button onClick={audioManager.unmuteAll}>
|
|
38
|
+
* Unmute All
|
|
39
|
+
* </button>
|
|
40
|
+
* <button onClick={audioManager.pauseAll}>
|
|
41
|
+
* Pause All
|
|
42
|
+
* </button>
|
|
43
|
+
* <button onClick={audioManager.resumeAll}>
|
|
44
|
+
* Resume All
|
|
45
|
+
* </button>
|
|
46
|
+
*
|
|
47
|
+
* <p>Muted: {audioManager.isMuted ? 'Yes' : 'No'}</p>
|
|
48
|
+
* <p>Total Tracks: {audioManager.getAllTracks().length}</p>
|
|
49
|
+
* </div>
|
|
50
|
+
* );
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export const useAudioManager = () => {
|
|
55
|
+
const state = useSnapshot(AudioManager.getState());
|
|
56
|
+
return {
|
|
57
|
+
...state,
|
|
58
|
+
setMasterVolume: AudioManager.setMasterVolume.bind(AudioManager),
|
|
59
|
+
getMasterVolume: AudioManager.getMasterVolume.bind(AudioManager),
|
|
60
|
+
muteAll: AudioManager.muteAll.bind(AudioManager),
|
|
61
|
+
unmuteAll: AudioManager.unmuteAll.bind(AudioManager),
|
|
62
|
+
pauseAll: AudioManager.pauseAll.bind(AudioManager),
|
|
63
|
+
resumeAll: AudioManager.resumeAll.bind(AudioManager),
|
|
64
|
+
stopAll: AudioManager.stopAll.bind(AudioManager),
|
|
65
|
+
getAllTracks: AudioManager.getAllTracks.bind(AudioManager),
|
|
66
|
+
getTrackById: AudioManager.getTrackById.bind(AudioManager),
|
|
67
|
+
disposeAll: AudioManager.disposeAll.bind(AudioManager),
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=useAudioManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAudioManager.js","sourceRoot":"","sources":["../../src/hooks/useAudioManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,EAAE;IAChC,MAAM,KAAK,GAAG,WAAW,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC,CAAC;IAEnD,OAAO;QACH,GAAG,KAAK;QACR,eAAe,EAAE,YAAY,CAAC,eAAe,CAAC,IAAI,CAAC,YAAY,CAAC;QAChE,eAAe,EAAE,YAAY,CAAC,eAAe,CAAC,IAAI,CAAC,YAAY,CAAC;QAChE,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC;QAChD,SAAS,EAAE,YAAY,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC;QACpD,QAAQ,EAAE,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC;QAClD,SAAS,EAAE,YAAY,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC;QACpD,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC;QAChD,YAAY,EAAE,YAAY,CAAC,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC;QAC1D,YAAY,EAAE,YAAY,CAAC,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC;QAC1D,UAAU,EAAE,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC;KACzD,CAAC;AACN,CAAC,CAAC"}
|
package/dist/i18n/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/i18n/utils.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,kBAAkB,IAAI,OAAO,CAC/C,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CACzC,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/i18n/utils.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,kBAAkB,IAAI,OAAO,CAC/C,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CACzC,CAeA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,kBAAkB,GAAI,YAAW,MAAmB,mDAGhE,CAAC"}
|
package/dist/i18n/utils.js
CHANGED
|
@@ -22,6 +22,12 @@ import i18next from "i18next";
|
|
|
22
22
|
*/
|
|
23
23
|
export async function loadUITranslations() {
|
|
24
24
|
try {
|
|
25
|
+
// UI package is a peer dependency and may not be installed.
|
|
26
|
+
// This dynamic import will fail gracefully at runtime if UI package is not available.
|
|
27
|
+
// Using @ts-ignore instead of @ts-expect-error because the error may or may not exist
|
|
28
|
+
// depending on whether the UI package is built/installed.
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
30
|
+
// @ts-ignore
|
|
25
31
|
const { uiTranslations } = await import("@react-text-game/ui/i18n");
|
|
26
32
|
return uiTranslations;
|
|
27
33
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
package/dist/i18n/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/i18n/utils.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB;IAGpC,IAAI,CAAC;QACD,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,MAAM,CAAC,0BAA0B,CAAC,CAAC;QACpE,OAAO,cAAc,CAAC;QACtB,6DAA6D;IACjE,CAAC;IAAC,OAAO,EAAE,EAAE,CAAC;QACV,0EAA0E;QAC1E,OAAO,EAAE,CAAC;IACd,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,YAAoB,UAAU,EAAE,EAAE;IACjE,+DAA+D;IAC/D,OAAO,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;AAC1D,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/i18n/utils.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB;IAGpC,IAAI,CAAC;QACD,4DAA4D;QAC5D,sFAAsF;QACtF,sFAAsF;QACtF,0DAA0D;QAC1D,6DAA6D;QAC7D,aAAa;QACb,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,MAAM,CAAC,0BAA0B,CAAC,CAAC;QACpE,OAAO,cAAc,CAAC;QACtB,6DAA6D;IACjE,CAAC;IAAC,OAAO,EAAE,EAAE,CAAC;QACV,0EAA0E;QAC1E,OAAO,EAAE,CAAC;IACd,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,YAAoB,UAAU,EAAE,EAAE;IACjE,+DAA+D;IAC/D,OAAO,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;AAC1D,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audio.test.d.ts","sourceRoot":"","sources":["../../src/tests/audio.test.ts"],"names":[],"mappings":""}
|