@dudgy/podcast-widget 0.1.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 +347 -0
- package/dist/index.cjs +1088 -0
- package/dist/index.d.cts +342 -0
- package/dist/index.d.ts +342 -0
- package/dist/index.js +1088 -0
- package/dist/podcast-index.cjs +65 -0
- package/dist/podcast-index.d.cts +57 -0
- package/dist/podcast-index.d.ts +57 -0
- package/dist/podcast-index.js +65 -0
- package/dist/podcast-player.css +773 -0
- package/package.json +54 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lightweight typed event emitter.
|
|
3
|
+
* Avoids extending EventTarget which has quirks with CustomEvent wrapping.
|
|
4
|
+
*/
|
|
5
|
+
declare class EventEmitter<TMap extends {}> {
|
|
6
|
+
private listeners;
|
|
7
|
+
on<K extends keyof TMap>(event: K, handler: (data: TMap[K]) => void): void;
|
|
8
|
+
off<K extends keyof TMap>(event: K, handler: (data: TMap[K]) => void): void;
|
|
9
|
+
protected emit<K extends keyof TMap>(event: K, data: TMap[K]): void;
|
|
10
|
+
removeAllListeners(): void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** A single podcast episode. */
|
|
14
|
+
interface Episode {
|
|
15
|
+
id: string;
|
|
16
|
+
feedId: number;
|
|
17
|
+
feedName: string;
|
|
18
|
+
title: string;
|
|
19
|
+
audioUrl: string;
|
|
20
|
+
pubDate: string;
|
|
21
|
+
pubDateTime?: string;
|
|
22
|
+
pubTimestamp?: number;
|
|
23
|
+
duration?: number;
|
|
24
|
+
image?: string;
|
|
25
|
+
feedImage?: string;
|
|
26
|
+
artwork?: string;
|
|
27
|
+
}
|
|
28
|
+
/** Persisted player state (current episode + volume). */
|
|
29
|
+
interface PlayerState {
|
|
30
|
+
currentEpisodeIndex: number;
|
|
31
|
+
volume: number;
|
|
32
|
+
}
|
|
33
|
+
/** Configuration for the player and its sub-modules. */
|
|
34
|
+
interface PlayerConfig {
|
|
35
|
+
/** Prefix for all localStorage keys. Default: "podcast" */
|
|
36
|
+
storagePrefix?: string;
|
|
37
|
+
/** Max saved resume positions. Default: 100 */
|
|
38
|
+
maxStoredPositions?: number;
|
|
39
|
+
/** Interval (ms) for saving position during playback. Default: 5000 */
|
|
40
|
+
positionSaveInterval?: number;
|
|
41
|
+
/** Skip forward/backward amount in seconds. Default: 30 */
|
|
42
|
+
skipSeconds?: number;
|
|
43
|
+
/** Client-side episode cache TTL in ms. Default: 3600000 (1 hour) */
|
|
44
|
+
episodeCacheTTL?: number;
|
|
45
|
+
}
|
|
46
|
+
/** Resolved config with all defaults applied. */
|
|
47
|
+
type ResolvedConfig = Required<PlayerConfig>;
|
|
48
|
+
declare const DEFAULT_CONFIG: ResolvedConfig;
|
|
49
|
+
declare function resolveConfig(config?: PlayerConfig): ResolvedConfig;
|
|
50
|
+
interface AudioEventMap {
|
|
51
|
+
play: {
|
|
52
|
+
episode?: Episode;
|
|
53
|
+
};
|
|
54
|
+
pause: {
|
|
55
|
+
currentTime: number;
|
|
56
|
+
};
|
|
57
|
+
stop: void;
|
|
58
|
+
ended: void;
|
|
59
|
+
'time-update': {
|
|
60
|
+
currentTime: number;
|
|
61
|
+
duration: number;
|
|
62
|
+
percentage: number;
|
|
63
|
+
};
|
|
64
|
+
'loaded-metadata': {
|
|
65
|
+
duration: number;
|
|
66
|
+
};
|
|
67
|
+
error: {
|
|
68
|
+
error: Error;
|
|
69
|
+
context: string;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
interface PlayerEventMap {
|
|
73
|
+
'episode-change': {
|
|
74
|
+
episode: Episode;
|
|
75
|
+
index: number;
|
|
76
|
+
};
|
|
77
|
+
'episodes-loaded': {
|
|
78
|
+
episodes: Episode[];
|
|
79
|
+
};
|
|
80
|
+
'episode-display': {
|
|
81
|
+
imageUrl: string;
|
|
82
|
+
title: string;
|
|
83
|
+
show: string;
|
|
84
|
+
};
|
|
85
|
+
expand: void;
|
|
86
|
+
close: void;
|
|
87
|
+
}
|
|
88
|
+
interface EpisodeProvider {
|
|
89
|
+
getEpisodes(): Promise<Episode[]>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Pure audio engine — wraps HTMLAudioElement with typed events,
|
|
94
|
+
* proper error handling, and seek support. Zero DOM queries.
|
|
95
|
+
*/
|
|
96
|
+
declare class AudioEngine extends EventEmitter<AudioEventMap> {
|
|
97
|
+
private audio;
|
|
98
|
+
private _isPlaying;
|
|
99
|
+
private skipSeconds;
|
|
100
|
+
private onTimeUpdate;
|
|
101
|
+
private onEnded;
|
|
102
|
+
private onLoadedMetadata;
|
|
103
|
+
private onError;
|
|
104
|
+
constructor(skipSeconds?: number);
|
|
105
|
+
load(url: string, startPosition?: number): void;
|
|
106
|
+
play(): Promise<void>;
|
|
107
|
+
pause(): void;
|
|
108
|
+
stop(): void;
|
|
109
|
+
skipForward(seconds?: number): void;
|
|
110
|
+
skipBackward(seconds?: number): void;
|
|
111
|
+
seek(seconds: number): void;
|
|
112
|
+
seekToPercentage(pct: number): void;
|
|
113
|
+
get currentTime(): number;
|
|
114
|
+
get duration(): number;
|
|
115
|
+
get isPlaying(): boolean;
|
|
116
|
+
get volume(): number;
|
|
117
|
+
set volume(v: number);
|
|
118
|
+
private _playbackRate;
|
|
119
|
+
get playbackRate(): number;
|
|
120
|
+
set playbackRate(r: number);
|
|
121
|
+
get hasSrc(): boolean;
|
|
122
|
+
destroy(): void;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Manages localStorage for episode resume positions.
|
|
127
|
+
* All keys are namespaced by the configured prefix.
|
|
128
|
+
*/
|
|
129
|
+
declare class PlaybackStorage {
|
|
130
|
+
private storageKey;
|
|
131
|
+
private maxItems;
|
|
132
|
+
constructor(config: ResolvedConfig);
|
|
133
|
+
getPositions(): Record<string, number>;
|
|
134
|
+
savePosition(episodeId: string, position: number, duration?: number): void;
|
|
135
|
+
getPosition(episodeId: string): number | null;
|
|
136
|
+
removePosition(episodeId: string): void;
|
|
137
|
+
cleanupPositions(currentEpisodeIds: string[]): void;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Manages localStorage for player-level state (current episode index, volume)
|
|
142
|
+
* and playback speed preference.
|
|
143
|
+
*/
|
|
144
|
+
declare class PlayerStateStorage {
|
|
145
|
+
private stateKey;
|
|
146
|
+
private speedKey;
|
|
147
|
+
constructor(config: ResolvedConfig);
|
|
148
|
+
saveState(state: PlayerState): void;
|
|
149
|
+
loadState(): PlayerState | null;
|
|
150
|
+
saveSpeed(speed: number): void;
|
|
151
|
+
loadSpeed(): number | null;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Fetches episodes from a URL endpoint.
|
|
156
|
+
* Includes localStorage caching with configurable TTL and one retry on failure.
|
|
157
|
+
*/
|
|
158
|
+
declare class FetchEpisodeProvider implements EpisodeProvider {
|
|
159
|
+
private url;
|
|
160
|
+
private cacheKey;
|
|
161
|
+
private cacheTTL;
|
|
162
|
+
constructor(url: string, config: ResolvedConfig);
|
|
163
|
+
getEpisodes(): Promise<Episode[]>;
|
|
164
|
+
private readCache;
|
|
165
|
+
private writeCache;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Which controls to show. All default to false — opt-in. */
|
|
169
|
+
interface ControlsConfig {
|
|
170
|
+
playPause?: boolean;
|
|
171
|
+
skipForward?: boolean;
|
|
172
|
+
skipBackward?: boolean;
|
|
173
|
+
volume?: boolean;
|
|
174
|
+
speed?: boolean;
|
|
175
|
+
progress?: boolean;
|
|
176
|
+
playlist?: boolean;
|
|
177
|
+
expand?: boolean;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* The core player controller. Manages the relationship between
|
|
181
|
+
* AudioEngine, PlaybackStorage, EpisodeProvider, and DOM elements.
|
|
182
|
+
*
|
|
183
|
+
* This is framework-agnostic — it takes element references, not IDs.
|
|
184
|
+
* Consumers can use createMiniPlayer/createFullPlayer for convenience,
|
|
185
|
+
* or instantiate this directly for full control.
|
|
186
|
+
*/
|
|
187
|
+
declare class PlayerController extends EventEmitter<PlayerEventMap> {
|
|
188
|
+
readonly engine: AudioEngine;
|
|
189
|
+
readonly storage: PlaybackStorage;
|
|
190
|
+
readonly stateStorage: PlayerStateStorage;
|
|
191
|
+
readonly config: ResolvedConfig;
|
|
192
|
+
private provider;
|
|
193
|
+
private episodes;
|
|
194
|
+
private currentIndex;
|
|
195
|
+
private saveInterval;
|
|
196
|
+
private cleanupFns;
|
|
197
|
+
constructor(engine: AudioEngine, provider: EpisodeProvider, config?: PlayerConfig);
|
|
198
|
+
loadEpisodes(): Promise<Episode[]>;
|
|
199
|
+
getEpisodes(): Episode[];
|
|
200
|
+
getCurrentEpisode(): Episode | null;
|
|
201
|
+
getCurrentIndex(): number;
|
|
202
|
+
loadEpisode(index: number, autoPlay?: boolean): void;
|
|
203
|
+
playEpisode(index: number): void;
|
|
204
|
+
play(): Promise<void>;
|
|
205
|
+
pause(): void;
|
|
206
|
+
setSpeed(speed: number): void;
|
|
207
|
+
setVolume(v: number): void;
|
|
208
|
+
getPlaylistHtml(feedPageUrl?: (feedId: number) => string): string;
|
|
209
|
+
private startPositionSaving;
|
|
210
|
+
private stopPositionSaving;
|
|
211
|
+
private saveCurrentPosition;
|
|
212
|
+
destroy(): void;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
interface MiniPlayerOptions {
|
|
216
|
+
container: HTMLElement;
|
|
217
|
+
controller: PlayerController;
|
|
218
|
+
controls?: ControlsConfig;
|
|
219
|
+
/** URL builder for podcast profile pages. If omitted, info links are hidden. */
|
|
220
|
+
feedPageUrl?: (feedId: number) => string;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Mini player mode — compact bar with configurable controls.
|
|
224
|
+
* Renders into the provided container.
|
|
225
|
+
*/
|
|
226
|
+
declare class MiniPlayer extends EventEmitter<Pick<PlayerEventMap, 'expand'>> {
|
|
227
|
+
private container;
|
|
228
|
+
private controller;
|
|
229
|
+
private controls;
|
|
230
|
+
private feedPageUrl?;
|
|
231
|
+
private cleanupFns;
|
|
232
|
+
private artworkEl;
|
|
233
|
+
private titleEl;
|
|
234
|
+
private showEl;
|
|
235
|
+
private playBtn;
|
|
236
|
+
private pauseBtn;
|
|
237
|
+
private progressBar;
|
|
238
|
+
private progressContainer;
|
|
239
|
+
private playlistContainer;
|
|
240
|
+
private playlistOpen;
|
|
241
|
+
constructor(opts: MiniPlayerOptions);
|
|
242
|
+
private render;
|
|
243
|
+
private bindEvents;
|
|
244
|
+
private updateDisplay;
|
|
245
|
+
private updatePlayPauseState;
|
|
246
|
+
private togglePlaylist;
|
|
247
|
+
private bindPlaylistClicks;
|
|
248
|
+
private updatePlaylistHighlight;
|
|
249
|
+
private addClick;
|
|
250
|
+
private addInput;
|
|
251
|
+
private addChange;
|
|
252
|
+
destroy(): void;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
interface FullPlayerOptions {
|
|
256
|
+
container: HTMLElement;
|
|
257
|
+
/** Optional separate backdrop element. If not provided, one is created inside container. */
|
|
258
|
+
backdrop?: HTMLElement;
|
|
259
|
+
controller: PlayerController;
|
|
260
|
+
controls?: ControlsConfig;
|
|
261
|
+
/** URL builder for podcast profile pages. */
|
|
262
|
+
feedPageUrl?: (feedId: number) => string;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Full player mode — overlay with hero section, controls, and playlist.
|
|
266
|
+
* Renders into the provided container.
|
|
267
|
+
*/
|
|
268
|
+
declare class FullPlayer extends EventEmitter<Pick<PlayerEventMap, 'close'>> {
|
|
269
|
+
private container;
|
|
270
|
+
private backdrop;
|
|
271
|
+
private controller;
|
|
272
|
+
private controls;
|
|
273
|
+
private feedPageUrl?;
|
|
274
|
+
private cleanupFns;
|
|
275
|
+
private artworkEl;
|
|
276
|
+
private trackNameEl;
|
|
277
|
+
private trackTimeEl;
|
|
278
|
+
private playBtn;
|
|
279
|
+
private pauseBtn;
|
|
280
|
+
private progressBar;
|
|
281
|
+
private progressContainer;
|
|
282
|
+
private playlistEl;
|
|
283
|
+
private heroBg;
|
|
284
|
+
constructor(opts: FullPlayerOptions);
|
|
285
|
+
show(): void;
|
|
286
|
+
hide(): void;
|
|
287
|
+
get isVisible(): boolean;
|
|
288
|
+
private render;
|
|
289
|
+
private bindEvents;
|
|
290
|
+
private updateDisplay;
|
|
291
|
+
private updatePlayPauseState;
|
|
292
|
+
private refreshPlaylist;
|
|
293
|
+
private bindPlaylistClicks;
|
|
294
|
+
private updatePlaylistHighlight;
|
|
295
|
+
private addClick;
|
|
296
|
+
private addInput;
|
|
297
|
+
private addChange;
|
|
298
|
+
destroy(): void;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/** SVG icon paths used across player modes. */
|
|
302
|
+
declare const ICONS: {
|
|
303
|
+
play: string;
|
|
304
|
+
pause: string;
|
|
305
|
+
skipBack: string;
|
|
306
|
+
skipForward: string;
|
|
307
|
+
expand: string;
|
|
308
|
+
close: string;
|
|
309
|
+
volume: string;
|
|
310
|
+
info: string;
|
|
311
|
+
playlist: string;
|
|
312
|
+
};
|
|
313
|
+
/** Speed options for the speed select dropdown. */
|
|
314
|
+
declare const SPEED_OPTIONS: number[];
|
|
315
|
+
/** Render a single playlist item. */
|
|
316
|
+
declare function renderPlaylistItem(episode: Episode, index: number, opts: {
|
|
317
|
+
isPlaying: boolean;
|
|
318
|
+
savedPosition: number | null;
|
|
319
|
+
feedPageUrl?: (feedId: number) => string;
|
|
320
|
+
}): string;
|
|
321
|
+
/** Render the full playlist HTML. */
|
|
322
|
+
declare function renderPlaylist(episodes: Episode[], currentIndex: number, getPosition: (id: string) => number | null, feedPageUrl?: (feedId: number) => string): string;
|
|
323
|
+
|
|
324
|
+
/** Format seconds to MM:SS or HH:MM:SS. */
|
|
325
|
+
declare function formatTime(seconds: number): string;
|
|
326
|
+
/** Format duration as "X min". */
|
|
327
|
+
declare function formatDuration(seconds: number | undefined): string;
|
|
328
|
+
/** Format a date for playlist display. */
|
|
329
|
+
declare function formatDate(pubDateTime?: string, pubDate?: string): {
|
|
330
|
+
short: string;
|
|
331
|
+
full: string;
|
|
332
|
+
};
|
|
333
|
+
/** Escape HTML to prevent XSS in innerHTML. */
|
|
334
|
+
declare function escapeHtml(str: string): string;
|
|
335
|
+
/** Get the best image URL for an episode. */
|
|
336
|
+
declare function getEpisodeImage(episode: {
|
|
337
|
+
image?: string;
|
|
338
|
+
feedImage?: string;
|
|
339
|
+
artwork?: string;
|
|
340
|
+
}): string;
|
|
341
|
+
|
|
342
|
+
export { AudioEngine, type AudioEventMap, type ControlsConfig, DEFAULT_CONFIG, type Episode, type EpisodeProvider, EventEmitter, FetchEpisodeProvider, FullPlayer, type FullPlayerOptions, ICONS, MiniPlayer, type MiniPlayerOptions, PlaybackStorage, type PlayerConfig, PlayerController, type PlayerEventMap, type PlayerState, PlayerStateStorage, type ResolvedConfig, SPEED_OPTIONS, escapeHtml, formatDate, formatDuration, formatTime, getEpisodeImage, renderPlaylist, renderPlaylistItem, resolveConfig };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lightweight typed event emitter.
|
|
3
|
+
* Avoids extending EventTarget which has quirks with CustomEvent wrapping.
|
|
4
|
+
*/
|
|
5
|
+
declare class EventEmitter<TMap extends {}> {
|
|
6
|
+
private listeners;
|
|
7
|
+
on<K extends keyof TMap>(event: K, handler: (data: TMap[K]) => void): void;
|
|
8
|
+
off<K extends keyof TMap>(event: K, handler: (data: TMap[K]) => void): void;
|
|
9
|
+
protected emit<K extends keyof TMap>(event: K, data: TMap[K]): void;
|
|
10
|
+
removeAllListeners(): void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** A single podcast episode. */
|
|
14
|
+
interface Episode {
|
|
15
|
+
id: string;
|
|
16
|
+
feedId: number;
|
|
17
|
+
feedName: string;
|
|
18
|
+
title: string;
|
|
19
|
+
audioUrl: string;
|
|
20
|
+
pubDate: string;
|
|
21
|
+
pubDateTime?: string;
|
|
22
|
+
pubTimestamp?: number;
|
|
23
|
+
duration?: number;
|
|
24
|
+
image?: string;
|
|
25
|
+
feedImage?: string;
|
|
26
|
+
artwork?: string;
|
|
27
|
+
}
|
|
28
|
+
/** Persisted player state (current episode + volume). */
|
|
29
|
+
interface PlayerState {
|
|
30
|
+
currentEpisodeIndex: number;
|
|
31
|
+
volume: number;
|
|
32
|
+
}
|
|
33
|
+
/** Configuration for the player and its sub-modules. */
|
|
34
|
+
interface PlayerConfig {
|
|
35
|
+
/** Prefix for all localStorage keys. Default: "podcast" */
|
|
36
|
+
storagePrefix?: string;
|
|
37
|
+
/** Max saved resume positions. Default: 100 */
|
|
38
|
+
maxStoredPositions?: number;
|
|
39
|
+
/** Interval (ms) for saving position during playback. Default: 5000 */
|
|
40
|
+
positionSaveInterval?: number;
|
|
41
|
+
/** Skip forward/backward amount in seconds. Default: 30 */
|
|
42
|
+
skipSeconds?: number;
|
|
43
|
+
/** Client-side episode cache TTL in ms. Default: 3600000 (1 hour) */
|
|
44
|
+
episodeCacheTTL?: number;
|
|
45
|
+
}
|
|
46
|
+
/** Resolved config with all defaults applied. */
|
|
47
|
+
type ResolvedConfig = Required<PlayerConfig>;
|
|
48
|
+
declare const DEFAULT_CONFIG: ResolvedConfig;
|
|
49
|
+
declare function resolveConfig(config?: PlayerConfig): ResolvedConfig;
|
|
50
|
+
interface AudioEventMap {
|
|
51
|
+
play: {
|
|
52
|
+
episode?: Episode;
|
|
53
|
+
};
|
|
54
|
+
pause: {
|
|
55
|
+
currentTime: number;
|
|
56
|
+
};
|
|
57
|
+
stop: void;
|
|
58
|
+
ended: void;
|
|
59
|
+
'time-update': {
|
|
60
|
+
currentTime: number;
|
|
61
|
+
duration: number;
|
|
62
|
+
percentage: number;
|
|
63
|
+
};
|
|
64
|
+
'loaded-metadata': {
|
|
65
|
+
duration: number;
|
|
66
|
+
};
|
|
67
|
+
error: {
|
|
68
|
+
error: Error;
|
|
69
|
+
context: string;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
interface PlayerEventMap {
|
|
73
|
+
'episode-change': {
|
|
74
|
+
episode: Episode;
|
|
75
|
+
index: number;
|
|
76
|
+
};
|
|
77
|
+
'episodes-loaded': {
|
|
78
|
+
episodes: Episode[];
|
|
79
|
+
};
|
|
80
|
+
'episode-display': {
|
|
81
|
+
imageUrl: string;
|
|
82
|
+
title: string;
|
|
83
|
+
show: string;
|
|
84
|
+
};
|
|
85
|
+
expand: void;
|
|
86
|
+
close: void;
|
|
87
|
+
}
|
|
88
|
+
interface EpisodeProvider {
|
|
89
|
+
getEpisodes(): Promise<Episode[]>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Pure audio engine — wraps HTMLAudioElement with typed events,
|
|
94
|
+
* proper error handling, and seek support. Zero DOM queries.
|
|
95
|
+
*/
|
|
96
|
+
declare class AudioEngine extends EventEmitter<AudioEventMap> {
|
|
97
|
+
private audio;
|
|
98
|
+
private _isPlaying;
|
|
99
|
+
private skipSeconds;
|
|
100
|
+
private onTimeUpdate;
|
|
101
|
+
private onEnded;
|
|
102
|
+
private onLoadedMetadata;
|
|
103
|
+
private onError;
|
|
104
|
+
constructor(skipSeconds?: number);
|
|
105
|
+
load(url: string, startPosition?: number): void;
|
|
106
|
+
play(): Promise<void>;
|
|
107
|
+
pause(): void;
|
|
108
|
+
stop(): void;
|
|
109
|
+
skipForward(seconds?: number): void;
|
|
110
|
+
skipBackward(seconds?: number): void;
|
|
111
|
+
seek(seconds: number): void;
|
|
112
|
+
seekToPercentage(pct: number): void;
|
|
113
|
+
get currentTime(): number;
|
|
114
|
+
get duration(): number;
|
|
115
|
+
get isPlaying(): boolean;
|
|
116
|
+
get volume(): number;
|
|
117
|
+
set volume(v: number);
|
|
118
|
+
private _playbackRate;
|
|
119
|
+
get playbackRate(): number;
|
|
120
|
+
set playbackRate(r: number);
|
|
121
|
+
get hasSrc(): boolean;
|
|
122
|
+
destroy(): void;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Manages localStorage for episode resume positions.
|
|
127
|
+
* All keys are namespaced by the configured prefix.
|
|
128
|
+
*/
|
|
129
|
+
declare class PlaybackStorage {
|
|
130
|
+
private storageKey;
|
|
131
|
+
private maxItems;
|
|
132
|
+
constructor(config: ResolvedConfig);
|
|
133
|
+
getPositions(): Record<string, number>;
|
|
134
|
+
savePosition(episodeId: string, position: number, duration?: number): void;
|
|
135
|
+
getPosition(episodeId: string): number | null;
|
|
136
|
+
removePosition(episodeId: string): void;
|
|
137
|
+
cleanupPositions(currentEpisodeIds: string[]): void;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Manages localStorage for player-level state (current episode index, volume)
|
|
142
|
+
* and playback speed preference.
|
|
143
|
+
*/
|
|
144
|
+
declare class PlayerStateStorage {
|
|
145
|
+
private stateKey;
|
|
146
|
+
private speedKey;
|
|
147
|
+
constructor(config: ResolvedConfig);
|
|
148
|
+
saveState(state: PlayerState): void;
|
|
149
|
+
loadState(): PlayerState | null;
|
|
150
|
+
saveSpeed(speed: number): void;
|
|
151
|
+
loadSpeed(): number | null;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Fetches episodes from a URL endpoint.
|
|
156
|
+
* Includes localStorage caching with configurable TTL and one retry on failure.
|
|
157
|
+
*/
|
|
158
|
+
declare class FetchEpisodeProvider implements EpisodeProvider {
|
|
159
|
+
private url;
|
|
160
|
+
private cacheKey;
|
|
161
|
+
private cacheTTL;
|
|
162
|
+
constructor(url: string, config: ResolvedConfig);
|
|
163
|
+
getEpisodes(): Promise<Episode[]>;
|
|
164
|
+
private readCache;
|
|
165
|
+
private writeCache;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Which controls to show. All default to false — opt-in. */
|
|
169
|
+
interface ControlsConfig {
|
|
170
|
+
playPause?: boolean;
|
|
171
|
+
skipForward?: boolean;
|
|
172
|
+
skipBackward?: boolean;
|
|
173
|
+
volume?: boolean;
|
|
174
|
+
speed?: boolean;
|
|
175
|
+
progress?: boolean;
|
|
176
|
+
playlist?: boolean;
|
|
177
|
+
expand?: boolean;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* The core player controller. Manages the relationship between
|
|
181
|
+
* AudioEngine, PlaybackStorage, EpisodeProvider, and DOM elements.
|
|
182
|
+
*
|
|
183
|
+
* This is framework-agnostic — it takes element references, not IDs.
|
|
184
|
+
* Consumers can use createMiniPlayer/createFullPlayer for convenience,
|
|
185
|
+
* or instantiate this directly for full control.
|
|
186
|
+
*/
|
|
187
|
+
declare class PlayerController extends EventEmitter<PlayerEventMap> {
|
|
188
|
+
readonly engine: AudioEngine;
|
|
189
|
+
readonly storage: PlaybackStorage;
|
|
190
|
+
readonly stateStorage: PlayerStateStorage;
|
|
191
|
+
readonly config: ResolvedConfig;
|
|
192
|
+
private provider;
|
|
193
|
+
private episodes;
|
|
194
|
+
private currentIndex;
|
|
195
|
+
private saveInterval;
|
|
196
|
+
private cleanupFns;
|
|
197
|
+
constructor(engine: AudioEngine, provider: EpisodeProvider, config?: PlayerConfig);
|
|
198
|
+
loadEpisodes(): Promise<Episode[]>;
|
|
199
|
+
getEpisodes(): Episode[];
|
|
200
|
+
getCurrentEpisode(): Episode | null;
|
|
201
|
+
getCurrentIndex(): number;
|
|
202
|
+
loadEpisode(index: number, autoPlay?: boolean): void;
|
|
203
|
+
playEpisode(index: number): void;
|
|
204
|
+
play(): Promise<void>;
|
|
205
|
+
pause(): void;
|
|
206
|
+
setSpeed(speed: number): void;
|
|
207
|
+
setVolume(v: number): void;
|
|
208
|
+
getPlaylistHtml(feedPageUrl?: (feedId: number) => string): string;
|
|
209
|
+
private startPositionSaving;
|
|
210
|
+
private stopPositionSaving;
|
|
211
|
+
private saveCurrentPosition;
|
|
212
|
+
destroy(): void;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
interface MiniPlayerOptions {
|
|
216
|
+
container: HTMLElement;
|
|
217
|
+
controller: PlayerController;
|
|
218
|
+
controls?: ControlsConfig;
|
|
219
|
+
/** URL builder for podcast profile pages. If omitted, info links are hidden. */
|
|
220
|
+
feedPageUrl?: (feedId: number) => string;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Mini player mode — compact bar with configurable controls.
|
|
224
|
+
* Renders into the provided container.
|
|
225
|
+
*/
|
|
226
|
+
declare class MiniPlayer extends EventEmitter<Pick<PlayerEventMap, 'expand'>> {
|
|
227
|
+
private container;
|
|
228
|
+
private controller;
|
|
229
|
+
private controls;
|
|
230
|
+
private feedPageUrl?;
|
|
231
|
+
private cleanupFns;
|
|
232
|
+
private artworkEl;
|
|
233
|
+
private titleEl;
|
|
234
|
+
private showEl;
|
|
235
|
+
private playBtn;
|
|
236
|
+
private pauseBtn;
|
|
237
|
+
private progressBar;
|
|
238
|
+
private progressContainer;
|
|
239
|
+
private playlistContainer;
|
|
240
|
+
private playlistOpen;
|
|
241
|
+
constructor(opts: MiniPlayerOptions);
|
|
242
|
+
private render;
|
|
243
|
+
private bindEvents;
|
|
244
|
+
private updateDisplay;
|
|
245
|
+
private updatePlayPauseState;
|
|
246
|
+
private togglePlaylist;
|
|
247
|
+
private bindPlaylistClicks;
|
|
248
|
+
private updatePlaylistHighlight;
|
|
249
|
+
private addClick;
|
|
250
|
+
private addInput;
|
|
251
|
+
private addChange;
|
|
252
|
+
destroy(): void;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
interface FullPlayerOptions {
|
|
256
|
+
container: HTMLElement;
|
|
257
|
+
/** Optional separate backdrop element. If not provided, one is created inside container. */
|
|
258
|
+
backdrop?: HTMLElement;
|
|
259
|
+
controller: PlayerController;
|
|
260
|
+
controls?: ControlsConfig;
|
|
261
|
+
/** URL builder for podcast profile pages. */
|
|
262
|
+
feedPageUrl?: (feedId: number) => string;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Full player mode — overlay with hero section, controls, and playlist.
|
|
266
|
+
* Renders into the provided container.
|
|
267
|
+
*/
|
|
268
|
+
declare class FullPlayer extends EventEmitter<Pick<PlayerEventMap, 'close'>> {
|
|
269
|
+
private container;
|
|
270
|
+
private backdrop;
|
|
271
|
+
private controller;
|
|
272
|
+
private controls;
|
|
273
|
+
private feedPageUrl?;
|
|
274
|
+
private cleanupFns;
|
|
275
|
+
private artworkEl;
|
|
276
|
+
private trackNameEl;
|
|
277
|
+
private trackTimeEl;
|
|
278
|
+
private playBtn;
|
|
279
|
+
private pauseBtn;
|
|
280
|
+
private progressBar;
|
|
281
|
+
private progressContainer;
|
|
282
|
+
private playlistEl;
|
|
283
|
+
private heroBg;
|
|
284
|
+
constructor(opts: FullPlayerOptions);
|
|
285
|
+
show(): void;
|
|
286
|
+
hide(): void;
|
|
287
|
+
get isVisible(): boolean;
|
|
288
|
+
private render;
|
|
289
|
+
private bindEvents;
|
|
290
|
+
private updateDisplay;
|
|
291
|
+
private updatePlayPauseState;
|
|
292
|
+
private refreshPlaylist;
|
|
293
|
+
private bindPlaylistClicks;
|
|
294
|
+
private updatePlaylistHighlight;
|
|
295
|
+
private addClick;
|
|
296
|
+
private addInput;
|
|
297
|
+
private addChange;
|
|
298
|
+
destroy(): void;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/** SVG icon paths used across player modes. */
|
|
302
|
+
declare const ICONS: {
|
|
303
|
+
play: string;
|
|
304
|
+
pause: string;
|
|
305
|
+
skipBack: string;
|
|
306
|
+
skipForward: string;
|
|
307
|
+
expand: string;
|
|
308
|
+
close: string;
|
|
309
|
+
volume: string;
|
|
310
|
+
info: string;
|
|
311
|
+
playlist: string;
|
|
312
|
+
};
|
|
313
|
+
/** Speed options for the speed select dropdown. */
|
|
314
|
+
declare const SPEED_OPTIONS: number[];
|
|
315
|
+
/** Render a single playlist item. */
|
|
316
|
+
declare function renderPlaylistItem(episode: Episode, index: number, opts: {
|
|
317
|
+
isPlaying: boolean;
|
|
318
|
+
savedPosition: number | null;
|
|
319
|
+
feedPageUrl?: (feedId: number) => string;
|
|
320
|
+
}): string;
|
|
321
|
+
/** Render the full playlist HTML. */
|
|
322
|
+
declare function renderPlaylist(episodes: Episode[], currentIndex: number, getPosition: (id: string) => number | null, feedPageUrl?: (feedId: number) => string): string;
|
|
323
|
+
|
|
324
|
+
/** Format seconds to MM:SS or HH:MM:SS. */
|
|
325
|
+
declare function formatTime(seconds: number): string;
|
|
326
|
+
/** Format duration as "X min". */
|
|
327
|
+
declare function formatDuration(seconds: number | undefined): string;
|
|
328
|
+
/** Format a date for playlist display. */
|
|
329
|
+
declare function formatDate(pubDateTime?: string, pubDate?: string): {
|
|
330
|
+
short: string;
|
|
331
|
+
full: string;
|
|
332
|
+
};
|
|
333
|
+
/** Escape HTML to prevent XSS in innerHTML. */
|
|
334
|
+
declare function escapeHtml(str: string): string;
|
|
335
|
+
/** Get the best image URL for an episode. */
|
|
336
|
+
declare function getEpisodeImage(episode: {
|
|
337
|
+
image?: string;
|
|
338
|
+
feedImage?: string;
|
|
339
|
+
artwork?: string;
|
|
340
|
+
}): string;
|
|
341
|
+
|
|
342
|
+
export { AudioEngine, type AudioEventMap, type ControlsConfig, DEFAULT_CONFIG, type Episode, type EpisodeProvider, EventEmitter, FetchEpisodeProvider, FullPlayer, type FullPlayerOptions, ICONS, MiniPlayer, type MiniPlayerOptions, PlaybackStorage, type PlayerConfig, PlayerController, type PlayerEventMap, type PlayerState, PlayerStateStorage, type ResolvedConfig, SPEED_OPTIONS, escapeHtml, formatDate, formatDuration, formatTime, getEpisodeImage, renderPlaylist, renderPlaylistItem, resolveConfig };
|