@scarlett-player/core 0.1.0 → 0.1.2
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 +87 -0
- package/dist/error-handler.d.ts +229 -0
- package/dist/events/event-bus.d.ts +212 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +234 -0
- package/dist/scarlett-player.d.ts +3 -2
- package/dist/scarlett-player.d.ts.map +1 -1
- package/dist/scarlett-player.js.map +1 -1
- package/dist/state/computed.d.ts +85 -0
- package/dist/state/effect.d.ts +47 -0
- package/dist/state/index.d.ts +9 -0
- package/dist/state/signal.d.ts +92 -0
- package/dist/state/state-manager.d.ts +199 -0
- package/package.json +3 -3
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StateManager - Centralized reactive state management for Scarlett Player.
|
|
3
|
+
*
|
|
4
|
+
* Manages all player state using reactive signals. Each state property
|
|
5
|
+
* is a Signal that can be observed for changes.
|
|
6
|
+
*
|
|
7
|
+
* Target size: ~1-2KB (excluding type definitions)
|
|
8
|
+
*/
|
|
9
|
+
import { type Signal } from './signal';
|
|
10
|
+
import type { StateStore, StateKey, StateValue, StateUpdate, StateChangeEvent } from '../types/state';
|
|
11
|
+
/**
|
|
12
|
+
* StateManager manages all player state using reactive signals.
|
|
13
|
+
*
|
|
14
|
+
* Each state property is a Signal that automatically tracks dependencies
|
|
15
|
+
* and notifies subscribers when changed.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const state = new StateManager();
|
|
20
|
+
*
|
|
21
|
+
* // Get a signal
|
|
22
|
+
* const playingSignal = state.get('playing');
|
|
23
|
+
* playingSignal.get(); // false
|
|
24
|
+
*
|
|
25
|
+
* // Set a value
|
|
26
|
+
* state.set('playing', true);
|
|
27
|
+
*
|
|
28
|
+
* // Subscribe to changes
|
|
29
|
+
* state.subscribe((event) => {
|
|
30
|
+
* console.log(`${event.key} changed to`, event.value);
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* // Batch updates
|
|
34
|
+
* state.update({
|
|
35
|
+
* playing: true,
|
|
36
|
+
* currentTime: 10,
|
|
37
|
+
* volume: 0.8,
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare class StateManager {
|
|
42
|
+
/** Internal map of state signals */
|
|
43
|
+
private signals;
|
|
44
|
+
/** Global state change subscribers */
|
|
45
|
+
private changeSubscribers;
|
|
46
|
+
/**
|
|
47
|
+
* Create a new StateManager with default initial state.
|
|
48
|
+
*
|
|
49
|
+
* @param initialState - Optional partial initial state (merged with defaults)
|
|
50
|
+
*/
|
|
51
|
+
constructor(initialState?: Partial<StateStore>);
|
|
52
|
+
/**
|
|
53
|
+
* Initialize all state signals with default or provided values.
|
|
54
|
+
* @private
|
|
55
|
+
*/
|
|
56
|
+
private initializeSignals;
|
|
57
|
+
/**
|
|
58
|
+
* Get the signal for a state property.
|
|
59
|
+
*
|
|
60
|
+
* @param key - State property key
|
|
61
|
+
* @returns Signal for the property
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* const playingSignal = state.get('playing');
|
|
66
|
+
* playingSignal.get(); // false
|
|
67
|
+
* playingSignal.set(true);
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
get<K extends StateKey>(key: K): Signal<StateValue<K>>;
|
|
71
|
+
/**
|
|
72
|
+
* Get the current value of a state property (convenience method).
|
|
73
|
+
*
|
|
74
|
+
* @param key - State property key
|
|
75
|
+
* @returns Current value
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* state.getValue('playing'); // false
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
getValue<K extends StateKey>(key: K): StateValue<K>;
|
|
83
|
+
/**
|
|
84
|
+
* Set the value of a state property.
|
|
85
|
+
*
|
|
86
|
+
* @param key - State property key
|
|
87
|
+
* @param value - New value
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* state.set('playing', true);
|
|
92
|
+
* state.set('currentTime', 10.5);
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
set<K extends StateKey>(key: K, value: StateValue<K>): void;
|
|
96
|
+
/**
|
|
97
|
+
* Update multiple state properties at once (batch update).
|
|
98
|
+
*
|
|
99
|
+
* More efficient than calling set() multiple times.
|
|
100
|
+
*
|
|
101
|
+
* @param updates - Partial state object with updates
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* state.update({
|
|
106
|
+
* playing: true,
|
|
107
|
+
* currentTime: 0,
|
|
108
|
+
* volume: 1.0,
|
|
109
|
+
* });
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
update(updates: StateUpdate): void;
|
|
113
|
+
/**
|
|
114
|
+
* Subscribe to changes on a specific state property.
|
|
115
|
+
*
|
|
116
|
+
* @param key - State property key
|
|
117
|
+
* @param callback - Callback function receiving new value
|
|
118
|
+
* @returns Unsubscribe function
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* const unsub = state.subscribe('playing', (value) => {
|
|
123
|
+
* console.log('Playing:', value);
|
|
124
|
+
* });
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
subscribeToKey<K extends StateKey>(key: K, callback: (value: StateValue<K>) => void): () => void;
|
|
128
|
+
/**
|
|
129
|
+
* Subscribe to all state changes.
|
|
130
|
+
*
|
|
131
|
+
* Receives a StateChangeEvent for every state property change.
|
|
132
|
+
*
|
|
133
|
+
* @param callback - Callback function receiving change events
|
|
134
|
+
* @returns Unsubscribe function
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* const unsub = state.subscribe((event) => {
|
|
139
|
+
* console.log(`${event.key} changed:`, event.value);
|
|
140
|
+
* });
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
subscribe(callback: (event: StateChangeEvent) => void): () => void;
|
|
144
|
+
/**
|
|
145
|
+
* Notify all global change subscribers.
|
|
146
|
+
* @private
|
|
147
|
+
*/
|
|
148
|
+
private notifyChangeSubscribers;
|
|
149
|
+
/**
|
|
150
|
+
* Reset all state to default values.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```ts
|
|
154
|
+
* state.reset();
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
reset(): void;
|
|
158
|
+
/**
|
|
159
|
+
* Reset a specific state property to its default value.
|
|
160
|
+
*
|
|
161
|
+
* @param key - State property key
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```ts
|
|
165
|
+
* state.resetKey('playing');
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
resetKey<K extends StateKey>(key: K): void;
|
|
169
|
+
/**
|
|
170
|
+
* Get a snapshot of all current state values.
|
|
171
|
+
*
|
|
172
|
+
* @returns Frozen snapshot of current state
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* const snapshot = state.snapshot();
|
|
177
|
+
* console.log(snapshot.playing, snapshot.currentTime);
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
snapshot(): Readonly<StateStore>;
|
|
181
|
+
/**
|
|
182
|
+
* Get the number of subscribers for a state property (for debugging).
|
|
183
|
+
*
|
|
184
|
+
* @param key - State property key
|
|
185
|
+
* @returns Number of subscribers
|
|
186
|
+
* @internal
|
|
187
|
+
*/
|
|
188
|
+
getSubscriberCount(key: StateKey): number;
|
|
189
|
+
/**
|
|
190
|
+
* Destroy the state manager and cleanup all signals.
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```ts
|
|
194
|
+
* state.destroy();
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
destroy(): void;
|
|
198
|
+
}
|
|
199
|
+
//# sourceMappingURL=state-manager.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scarlett-player/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Core player with plugin system for Scarlett Player",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"scripts": {
|
|
20
20
|
"dev": "vite",
|
|
21
21
|
"demo": "vite",
|
|
22
|
-
"build": "tsc && vite build",
|
|
22
|
+
"build": "rm -f tsconfig.tsbuildinfo && tsc && vite build",
|
|
23
23
|
"test": "vitest --run",
|
|
24
24
|
"test:watch": "vitest",
|
|
25
25
|
"test:coverage": "vitest --coverage",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"bugs": {
|
|
48
48
|
"url": "https://github.com/Hackney-Enterprises-Inc/scarlett-player/issues"
|
|
49
49
|
},
|
|
50
|
-
"homepage": "https://
|
|
50
|
+
"homepage": "https://scarlettplayer.com",
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/node": "^20.0.0",
|
|
53
53
|
"@vitest/coverage-v8": "^1.1.0",
|