@dudgy/podcast-widget 0.2.0 → 0.3.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 +28 -3
- package/dist/index.cjs +186 -103
- package/dist/index.d.cts +31 -5
- package/dist/index.d.ts +31 -5
- package/dist/index.js +155 -72
- package/dist/podcast-player.css +136 -36
- package/package.json +5 -2
package/dist/index.d.cts
CHANGED
|
@@ -25,9 +25,19 @@ interface Episode {
|
|
|
25
25
|
feedImage?: string;
|
|
26
26
|
artwork?: string;
|
|
27
27
|
}
|
|
28
|
-
/**
|
|
28
|
+
/** Current version of the persisted {@link PlayerState} format. */
|
|
29
|
+
declare const PLAYER_STATE_VERSION = 2;
|
|
30
|
+
/**
|
|
31
|
+
* Persisted player state (current episode + volume).
|
|
32
|
+
*
|
|
33
|
+
* The current episode is stored as a full snapshot, not a reference into the
|
|
34
|
+
* episode list: the list reorders and drops episodes as feeds publish, but the
|
|
35
|
+
* player should still restore what the listener had loaded.
|
|
36
|
+
*/
|
|
29
37
|
interface PlayerState {
|
|
30
|
-
|
|
38
|
+
v: typeof PLAYER_STATE_VERSION;
|
|
39
|
+
/** Snapshot of the loaded episode, or null if none. */
|
|
40
|
+
episode: Episode | null;
|
|
31
41
|
volume: number;
|
|
32
42
|
}
|
|
33
43
|
/** Configuration for the player and its sub-modules. */
|
|
@@ -134,11 +144,12 @@ declare class PlaybackStorage {
|
|
|
134
144
|
savePosition(episodeId: string, position: number, duration?: number): void;
|
|
135
145
|
getPosition(episodeId: string): number | null;
|
|
136
146
|
removePosition(episodeId: string): void;
|
|
137
|
-
|
|
147
|
+
/** Remove saved positions for episodes whose IDs aren't in `keepIds`. */
|
|
148
|
+
cleanupPositions(keepIds: string[]): void;
|
|
138
149
|
}
|
|
139
150
|
|
|
140
151
|
/**
|
|
141
|
-
* Manages localStorage for player-level state (current episode
|
|
152
|
+
* Manages localStorage for player-level state (current episode, volume)
|
|
142
153
|
* and playback speed preference.
|
|
143
154
|
*/
|
|
144
155
|
declare class PlayerStateStorage {
|
|
@@ -146,6 +157,13 @@ declare class PlayerStateStorage {
|
|
|
146
157
|
private speedKey;
|
|
147
158
|
constructor(config: ResolvedConfig);
|
|
148
159
|
saveState(state: PlayerState): void;
|
|
160
|
+
/**
|
|
161
|
+
* Load saved state, migrating older formats. Returns null if nothing usable
|
|
162
|
+
* is saved.
|
|
163
|
+
*
|
|
164
|
+
* Unversioned (v1) state stored only an index into the episode list, which
|
|
165
|
+
* can't be trusted once the list changes, so only its volume is kept.
|
|
166
|
+
*/
|
|
149
167
|
loadState(): PlayerState | null;
|
|
150
168
|
saveSpeed(speed: number): void;
|
|
151
169
|
loadSpeed(): number | null;
|
|
@@ -192,6 +210,9 @@ declare class PlayerController extends EventEmitter<PlayerEventMap> {
|
|
|
192
210
|
readonly config: ResolvedConfig;
|
|
193
211
|
private provider;
|
|
194
212
|
private episodes;
|
|
213
|
+
/** The loaded episode. May not be in `episodes` (e.g. restored after its feed moved on). */
|
|
214
|
+
private currentEpisode;
|
|
215
|
+
/** Index of `currentEpisode` in `episodes`, or -1 if it isn't in the list. */
|
|
195
216
|
private currentIndex;
|
|
196
217
|
private saveInterval;
|
|
197
218
|
private cleanupFns;
|
|
@@ -199,13 +220,16 @@ declare class PlayerController extends EventEmitter<PlayerEventMap> {
|
|
|
199
220
|
loadEpisodes(): Promise<Episode[]>;
|
|
200
221
|
getEpisodes(): Episode[];
|
|
201
222
|
getCurrentEpisode(): Episode | null;
|
|
223
|
+
/** Index of the current episode in the list, or -1 if none or not listed. */
|
|
202
224
|
getCurrentIndex(): number;
|
|
203
225
|
loadEpisode(index: number, autoPlay?: boolean): void;
|
|
226
|
+
private select;
|
|
204
227
|
playEpisode(index: number): void;
|
|
205
228
|
play(): Promise<void>;
|
|
206
229
|
pause(): void;
|
|
207
230
|
setSpeed(speed: number): void;
|
|
208
231
|
setVolume(v: number): void;
|
|
232
|
+
private persistState;
|
|
209
233
|
getPlaylistHtml(feedPageUrl?: (feedId: number) => string): string;
|
|
210
234
|
private startPositionSaving;
|
|
211
235
|
private stopPositionSaving;
|
|
@@ -289,6 +313,7 @@ declare class FullPlayer extends EventEmitter<Pick<PlayerEventMap, 'close'>> {
|
|
|
289
313
|
private render;
|
|
290
314
|
private bindEvents;
|
|
291
315
|
private updateDisplay;
|
|
316
|
+
private setHeroBackground;
|
|
292
317
|
private updatePlayPauseState;
|
|
293
318
|
private refreshPlaylist;
|
|
294
319
|
private bindPlaylistClicks;
|
|
@@ -311,6 +336,7 @@ declare const ICONS: {
|
|
|
311
336
|
volume: string;
|
|
312
337
|
info: string;
|
|
313
338
|
playlist: string;
|
|
339
|
+
note: string;
|
|
314
340
|
download: string;
|
|
315
341
|
};
|
|
316
342
|
/** Speed options for the speed select dropdown. */
|
|
@@ -342,4 +368,4 @@ declare function getEpisodeImage(episode: {
|
|
|
342
368
|
artwork?: string;
|
|
343
369
|
}): string;
|
|
344
370
|
|
|
345
|
-
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 };
|
|
371
|
+
export { AudioEngine, type AudioEventMap, type ControlsConfig, DEFAULT_CONFIG, type Episode, type EpisodeProvider, EventEmitter, FetchEpisodeProvider, FullPlayer, type FullPlayerOptions, ICONS, MiniPlayer, type MiniPlayerOptions, PLAYER_STATE_VERSION, 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
CHANGED
|
@@ -25,9 +25,19 @@ interface Episode {
|
|
|
25
25
|
feedImage?: string;
|
|
26
26
|
artwork?: string;
|
|
27
27
|
}
|
|
28
|
-
/**
|
|
28
|
+
/** Current version of the persisted {@link PlayerState} format. */
|
|
29
|
+
declare const PLAYER_STATE_VERSION = 2;
|
|
30
|
+
/**
|
|
31
|
+
* Persisted player state (current episode + volume).
|
|
32
|
+
*
|
|
33
|
+
* The current episode is stored as a full snapshot, not a reference into the
|
|
34
|
+
* episode list: the list reorders and drops episodes as feeds publish, but the
|
|
35
|
+
* player should still restore what the listener had loaded.
|
|
36
|
+
*/
|
|
29
37
|
interface PlayerState {
|
|
30
|
-
|
|
38
|
+
v: typeof PLAYER_STATE_VERSION;
|
|
39
|
+
/** Snapshot of the loaded episode, or null if none. */
|
|
40
|
+
episode: Episode | null;
|
|
31
41
|
volume: number;
|
|
32
42
|
}
|
|
33
43
|
/** Configuration for the player and its sub-modules. */
|
|
@@ -134,11 +144,12 @@ declare class PlaybackStorage {
|
|
|
134
144
|
savePosition(episodeId: string, position: number, duration?: number): void;
|
|
135
145
|
getPosition(episodeId: string): number | null;
|
|
136
146
|
removePosition(episodeId: string): void;
|
|
137
|
-
|
|
147
|
+
/** Remove saved positions for episodes whose IDs aren't in `keepIds`. */
|
|
148
|
+
cleanupPositions(keepIds: string[]): void;
|
|
138
149
|
}
|
|
139
150
|
|
|
140
151
|
/**
|
|
141
|
-
* Manages localStorage for player-level state (current episode
|
|
152
|
+
* Manages localStorage for player-level state (current episode, volume)
|
|
142
153
|
* and playback speed preference.
|
|
143
154
|
*/
|
|
144
155
|
declare class PlayerStateStorage {
|
|
@@ -146,6 +157,13 @@ declare class PlayerStateStorage {
|
|
|
146
157
|
private speedKey;
|
|
147
158
|
constructor(config: ResolvedConfig);
|
|
148
159
|
saveState(state: PlayerState): void;
|
|
160
|
+
/**
|
|
161
|
+
* Load saved state, migrating older formats. Returns null if nothing usable
|
|
162
|
+
* is saved.
|
|
163
|
+
*
|
|
164
|
+
* Unversioned (v1) state stored only an index into the episode list, which
|
|
165
|
+
* can't be trusted once the list changes, so only its volume is kept.
|
|
166
|
+
*/
|
|
149
167
|
loadState(): PlayerState | null;
|
|
150
168
|
saveSpeed(speed: number): void;
|
|
151
169
|
loadSpeed(): number | null;
|
|
@@ -192,6 +210,9 @@ declare class PlayerController extends EventEmitter<PlayerEventMap> {
|
|
|
192
210
|
readonly config: ResolvedConfig;
|
|
193
211
|
private provider;
|
|
194
212
|
private episodes;
|
|
213
|
+
/** The loaded episode. May not be in `episodes` (e.g. restored after its feed moved on). */
|
|
214
|
+
private currentEpisode;
|
|
215
|
+
/** Index of `currentEpisode` in `episodes`, or -1 if it isn't in the list. */
|
|
195
216
|
private currentIndex;
|
|
196
217
|
private saveInterval;
|
|
197
218
|
private cleanupFns;
|
|
@@ -199,13 +220,16 @@ declare class PlayerController extends EventEmitter<PlayerEventMap> {
|
|
|
199
220
|
loadEpisodes(): Promise<Episode[]>;
|
|
200
221
|
getEpisodes(): Episode[];
|
|
201
222
|
getCurrentEpisode(): Episode | null;
|
|
223
|
+
/** Index of the current episode in the list, or -1 if none or not listed. */
|
|
202
224
|
getCurrentIndex(): number;
|
|
203
225
|
loadEpisode(index: number, autoPlay?: boolean): void;
|
|
226
|
+
private select;
|
|
204
227
|
playEpisode(index: number): void;
|
|
205
228
|
play(): Promise<void>;
|
|
206
229
|
pause(): void;
|
|
207
230
|
setSpeed(speed: number): void;
|
|
208
231
|
setVolume(v: number): void;
|
|
232
|
+
private persistState;
|
|
209
233
|
getPlaylistHtml(feedPageUrl?: (feedId: number) => string): string;
|
|
210
234
|
private startPositionSaving;
|
|
211
235
|
private stopPositionSaving;
|
|
@@ -289,6 +313,7 @@ declare class FullPlayer extends EventEmitter<Pick<PlayerEventMap, 'close'>> {
|
|
|
289
313
|
private render;
|
|
290
314
|
private bindEvents;
|
|
291
315
|
private updateDisplay;
|
|
316
|
+
private setHeroBackground;
|
|
292
317
|
private updatePlayPauseState;
|
|
293
318
|
private refreshPlaylist;
|
|
294
319
|
private bindPlaylistClicks;
|
|
@@ -311,6 +336,7 @@ declare const ICONS: {
|
|
|
311
336
|
volume: string;
|
|
312
337
|
info: string;
|
|
313
338
|
playlist: string;
|
|
339
|
+
note: string;
|
|
314
340
|
download: string;
|
|
315
341
|
};
|
|
316
342
|
/** Speed options for the speed select dropdown. */
|
|
@@ -342,4 +368,4 @@ declare function getEpisodeImage(episode: {
|
|
|
342
368
|
artwork?: string;
|
|
343
369
|
}): string;
|
|
344
370
|
|
|
345
|
-
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 };
|
|
371
|
+
export { AudioEngine, type AudioEventMap, type ControlsConfig, DEFAULT_CONFIG, type Episode, type EpisodeProvider, EventEmitter, FetchEpisodeProvider, FullPlayer, type FullPlayerOptions, ICONS, MiniPlayer, type MiniPlayerOptions, PLAYER_STATE_VERSION, PlaybackStorage, type PlayerConfig, PlayerController, type PlayerEventMap, type PlayerState, PlayerStateStorage, type ResolvedConfig, SPEED_OPTIONS, escapeHtml, formatDate, formatDuration, formatTime, getEpisodeImage, renderPlaylist, renderPlaylistItem, resolveConfig };
|
package/dist/index.js
CHANGED
|
@@ -198,10 +198,11 @@ var PlaybackStorage = class {
|
|
|
198
198
|
} catch {
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
|
-
|
|
201
|
+
/** Remove saved positions for episodes whose IDs aren't in `keepIds`. */
|
|
202
|
+
cleanupPositions(keepIds) {
|
|
202
203
|
try {
|
|
203
204
|
const positions = this.getPositions();
|
|
204
|
-
const currentSet = new Set(
|
|
205
|
+
const currentSet = new Set(keepIds);
|
|
205
206
|
let changed = false;
|
|
206
207
|
for (const id of Object.keys(positions)) {
|
|
207
208
|
if (!currentSet.has(id)) {
|
|
@@ -217,6 +218,19 @@ var PlaybackStorage = class {
|
|
|
217
218
|
}
|
|
218
219
|
};
|
|
219
220
|
|
|
221
|
+
// src/core/types.ts
|
|
222
|
+
var PLAYER_STATE_VERSION = 2;
|
|
223
|
+
var DEFAULT_CONFIG = {
|
|
224
|
+
storagePrefix: "podcast",
|
|
225
|
+
maxStoredPositions: 100,
|
|
226
|
+
positionSaveInterval: 5e3,
|
|
227
|
+
skipSeconds: 30,
|
|
228
|
+
episodeCacheTTL: 60 * 60 * 1e3
|
|
229
|
+
};
|
|
230
|
+
function resolveConfig(config) {
|
|
231
|
+
return { ...DEFAULT_CONFIG, ...config };
|
|
232
|
+
}
|
|
233
|
+
|
|
220
234
|
// src/core/player-state.ts
|
|
221
235
|
var PlayerStateStorage = class {
|
|
222
236
|
stateKey;
|
|
@@ -231,11 +245,22 @@ var PlayerStateStorage = class {
|
|
|
231
245
|
} catch {
|
|
232
246
|
}
|
|
233
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* Load saved state, migrating older formats. Returns null if nothing usable
|
|
250
|
+
* is saved.
|
|
251
|
+
*
|
|
252
|
+
* Unversioned (v1) state stored only an index into the episode list, which
|
|
253
|
+
* can't be trusted once the list changes, so only its volume is kept.
|
|
254
|
+
*/
|
|
234
255
|
loadState() {
|
|
235
256
|
try {
|
|
236
257
|
const raw = localStorage.getItem(this.stateKey);
|
|
237
258
|
if (!raw) return null;
|
|
238
|
-
|
|
259
|
+
const data = JSON.parse(raw);
|
|
260
|
+
if (!data || typeof data !== "object") return null;
|
|
261
|
+
const volume = isVolume(data.volume) ? data.volume : 1;
|
|
262
|
+
const episode = data.v === PLAYER_STATE_VERSION && isEpisode(data.episode) ? data.episode : null;
|
|
263
|
+
return { v: PLAYER_STATE_VERSION, episode, volume };
|
|
239
264
|
} catch {
|
|
240
265
|
return null;
|
|
241
266
|
}
|
|
@@ -257,6 +282,14 @@ var PlayerStateStorage = class {
|
|
|
257
282
|
}
|
|
258
283
|
}
|
|
259
284
|
};
|
|
285
|
+
function isVolume(v) {
|
|
286
|
+
return typeof v === "number" && v >= 0 && v <= 1;
|
|
287
|
+
}
|
|
288
|
+
function isEpisode(e) {
|
|
289
|
+
if (!e || typeof e !== "object") return false;
|
|
290
|
+
const ep = e;
|
|
291
|
+
return typeof ep.id === "string" && typeof ep.audioUrl === "string" && typeof ep.title === "string" && typeof ep.feedName === "string";
|
|
292
|
+
}
|
|
260
293
|
|
|
261
294
|
// src/core/episode-provider.ts
|
|
262
295
|
var FetchEpisodeProvider = class {
|
|
@@ -314,18 +347,6 @@ var FetchEpisodeProvider = class {
|
|
|
314
347
|
}
|
|
315
348
|
};
|
|
316
349
|
|
|
317
|
-
// src/core/types.ts
|
|
318
|
-
var DEFAULT_CONFIG = {
|
|
319
|
-
storagePrefix: "podcast",
|
|
320
|
-
maxStoredPositions: 100,
|
|
321
|
-
positionSaveInterval: 5e3,
|
|
322
|
-
skipSeconds: 30,
|
|
323
|
-
episodeCacheTTL: 60 * 60 * 1e3
|
|
324
|
-
};
|
|
325
|
-
function resolveConfig(config) {
|
|
326
|
-
return { ...DEFAULT_CONFIG, ...config };
|
|
327
|
-
}
|
|
328
|
-
|
|
329
350
|
// src/ui/utils.ts
|
|
330
351
|
function formatTime(seconds) {
|
|
331
352
|
if (isNaN(seconds) || seconds < 0) return "00:00";
|
|
@@ -368,20 +389,75 @@ function escapeHtml(str) {
|
|
|
368
389
|
function getEpisodeImage(episode) {
|
|
369
390
|
return episode.image || episode.feedImage || episode.artwork || "";
|
|
370
391
|
}
|
|
392
|
+
function setArtwork(img, url) {
|
|
393
|
+
if (!img) return;
|
|
394
|
+
img.hidden = !url;
|
|
395
|
+
if (url) img.src = url;
|
|
396
|
+
else img.removeAttribute("src");
|
|
397
|
+
}
|
|
398
|
+
function hideBrokenImages(root) {
|
|
399
|
+
const onError = (e) => {
|
|
400
|
+
const t = e.target;
|
|
401
|
+
if (t instanceof HTMLImageElement && t.parentElement?.classList.contains("pw-art")) t.hidden = true;
|
|
402
|
+
};
|
|
403
|
+
root.addEventListener("error", onError, true);
|
|
404
|
+
return () => root.removeEventListener("error", onError, true);
|
|
405
|
+
}
|
|
406
|
+
function attachSeekTooltip(bar, getDuration) {
|
|
407
|
+
const tip = document.createElement("div");
|
|
408
|
+
tip.className = "pw-seek-tooltip";
|
|
409
|
+
tip.setAttribute("aria-hidden", "true");
|
|
410
|
+
tip.hidden = true;
|
|
411
|
+
bar.appendChild(tip);
|
|
412
|
+
const onMove = (e) => {
|
|
413
|
+
const duration = getDuration();
|
|
414
|
+
if (e.pointerType === "touch" || !(duration > 0)) {
|
|
415
|
+
tip.hidden = true;
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
const rect = bar.getBoundingClientRect();
|
|
419
|
+
const frac = Math.min(1, Math.max(0, (e.clientX - rect.left) / rect.width));
|
|
420
|
+
tip.textContent = formatTime(frac * duration);
|
|
421
|
+
tip.hidden = false;
|
|
422
|
+
const half = tip.offsetWidth / 2;
|
|
423
|
+
tip.style.left = `${Math.min(rect.width - half, Math.max(half, frac * rect.width))}px`;
|
|
424
|
+
};
|
|
425
|
+
const onLeave = () => {
|
|
426
|
+
tip.hidden = true;
|
|
427
|
+
};
|
|
428
|
+
bar.addEventListener("pointermove", onMove);
|
|
429
|
+
bar.addEventListener("pointerleave", onLeave);
|
|
430
|
+
return () => {
|
|
431
|
+
bar.removeEventListener("pointermove", onMove);
|
|
432
|
+
bar.removeEventListener("pointerleave", onLeave);
|
|
433
|
+
tip.remove();
|
|
434
|
+
};
|
|
435
|
+
}
|
|
371
436
|
|
|
372
437
|
// src/ui/html-templates.ts
|
|
373
438
|
var ICONS = {
|
|
374
439
|
play: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>',
|
|
375
440
|
pause: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M6 19h4V5H6v14zm8-14v14h4V5h-4z"/></svg>',
|
|
376
|
-
|
|
377
|
-
|
|
441
|
+
// Plain circular arrows; the seconds are drawn as text on top (see renderSkipButton)
|
|
442
|
+
skipBack: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M12 5V1L7 6l5 5V7c3.31 0 6 2.69 6 6s-2.69 6-6 6-6-2.69-6-6H4c0 4.42 3.58 8 8 8s8-3.58 8-8-3.58-8-8-8z"/></svg>',
|
|
443
|
+
skipForward: '<svg viewBox="0 0 24 24" fill="currentColor"><path transform="matrix(-1 0 0 1 24 0)" d="M12 5V1L7 6l5 5V7c3.31 0 6 2.69 6 6s-2.69 6-6 6-6-2.69-6-6H4c0 4.42 3.58 8 8 8s8-3.58 8-8-3.58-8-8-8z"/></svg>',
|
|
378
444
|
expand: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z"/></svg>',
|
|
379
445
|
close: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg>',
|
|
380
446
|
volume: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02z"/></svg>',
|
|
381
447
|
info: '<svg viewBox="0 0 24 24" fill="currentColor" width="16" height="16"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z"/></svg>',
|
|
382
448
|
playlist: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M3 13h2v-2H3v2zm0 4h2v-2H3v2zm0-8h2V7H3v2zm4 4h14v-2H7v2zm0 4h14v-2H7v2zM7 7v2h14V7H7z"/></svg>',
|
|
449
|
+
note: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M12 3v10.55c-.59-.34-1.27-.55-2-.55-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4V7h4V3h-6z"/></svg>',
|
|
383
450
|
download: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z"/></svg>'
|
|
384
451
|
};
|
|
452
|
+
function renderArtwork(className, imageUrl) {
|
|
453
|
+
const img = imageUrl ? `<img src="${escapeHtml(imageUrl)}" alt="">` : '<img alt="" hidden>';
|
|
454
|
+
return `<span class="pw-art ${className}">${img}${ICONS.note}</span>`;
|
|
455
|
+
}
|
|
456
|
+
function renderSkipButton(direction, seconds, extraClass = "") {
|
|
457
|
+
const label = `${direction === "back" ? "Back" : "Forward"} ${seconds} seconds`;
|
|
458
|
+
const icon = direction === "back" ? ICONS.skipBack : ICONS.skipForward;
|
|
459
|
+
return `<button class="pw-btn pw-btn--skip pw-btn--skip-${direction} ${extraClass}" aria-label="${label}">${icon}<span class="pw-skip-label" aria-hidden="true">${seconds}</span></button>`;
|
|
460
|
+
}
|
|
385
461
|
var SPEED_OPTIONS = [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.5, 3];
|
|
386
462
|
function renderPlaylistItem(episode, index, opts) {
|
|
387
463
|
const imageUrl = getEpisodeImage(episode);
|
|
@@ -397,7 +473,7 @@ function renderPlaylistItem(episode, index, opts) {
|
|
|
397
473
|
const feedLinkHtml = opts.feedPageUrl ? `<a href="${opts.feedPageUrl(episode.feedId)}" class="pw-view-feed" title="View show info" data-feed-link>${ICONS.info}</a>` : "";
|
|
398
474
|
return `
|
|
399
475
|
<div class="pw-playlist-item ${opts.isPlaying ? "pw-playing" : ""} ${hasSaved ? "pw-has-saved" : ""}" data-index="${index}">
|
|
400
|
-
${
|
|
476
|
+
${renderArtwork("pw-episode-image", imageUrl)}
|
|
401
477
|
<div class="pw-episode-info">
|
|
402
478
|
<div class="pw-episode-show">${escapeHtml(episode.feedName || "Unknown Show")}</div>
|
|
403
479
|
<div class="pw-episode-title">${escapeHtml(episode.title)}</div>
|
|
@@ -433,6 +509,9 @@ var PlayerController = class extends EventEmitter {
|
|
|
433
509
|
config;
|
|
434
510
|
provider;
|
|
435
511
|
episodes = [];
|
|
512
|
+
/** The loaded episode. May not be in `episodes` (e.g. restored after its feed moved on). */
|
|
513
|
+
currentEpisode = null;
|
|
514
|
+
/** Index of `currentEpisode` in `episodes`, or -1 if it isn't in the list. */
|
|
436
515
|
currentIndex = -1;
|
|
437
516
|
saveInterval = null;
|
|
438
517
|
cleanupFns = [];
|
|
@@ -452,8 +531,8 @@ var PlayerController = class extends EventEmitter {
|
|
|
452
531
|
this.engine.volume = savedState.volume;
|
|
453
532
|
}
|
|
454
533
|
this.engine.on("ended", () => {
|
|
455
|
-
if (this.
|
|
456
|
-
this.storage.removePosition(this.
|
|
534
|
+
if (this.currentEpisode) {
|
|
535
|
+
this.storage.removePosition(this.currentEpisode.id);
|
|
457
536
|
}
|
|
458
537
|
this.stopPositionSaving();
|
|
459
538
|
});
|
|
@@ -467,11 +546,17 @@ var PlayerController = class extends EventEmitter {
|
|
|
467
546
|
// ─── Episode management ────────────────────────────────────────
|
|
468
547
|
async loadEpisodes() {
|
|
469
548
|
this.episodes = await this.provider.getEpisodes();
|
|
470
|
-
this.
|
|
549
|
+
const saved = this.stateStorage.loadState()?.episode ?? null;
|
|
550
|
+
const keepIds = this.episodes.map((ep) => ep.id);
|
|
551
|
+
if (saved) keepIds.push(saved.id);
|
|
552
|
+
this.storage.cleanupPositions(keepIds);
|
|
471
553
|
this.emit("episodes-loaded", { episodes: this.episodes });
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
this.loadEpisode(
|
|
554
|
+
if (saved) {
|
|
555
|
+
const index = this.episodes.findIndex((ep) => ep.id === saved.id);
|
|
556
|
+
if (index >= 0) this.loadEpisode(index, false);
|
|
557
|
+
else this.select(saved, -1, false);
|
|
558
|
+
} else if (this.episodes.length > 0) {
|
|
559
|
+
this.loadEpisode(0, false);
|
|
475
560
|
}
|
|
476
561
|
return this.episodes;
|
|
477
562
|
}
|
|
@@ -479,21 +564,22 @@ var PlayerController = class extends EventEmitter {
|
|
|
479
564
|
return this.episodes;
|
|
480
565
|
}
|
|
481
566
|
getCurrentEpisode() {
|
|
482
|
-
return this.
|
|
567
|
+
return this.currentEpisode;
|
|
483
568
|
}
|
|
569
|
+
/** Index of the current episode in the list, or -1 if none or not listed. */
|
|
484
570
|
getCurrentIndex() {
|
|
485
571
|
return this.currentIndex;
|
|
486
572
|
}
|
|
487
573
|
loadEpisode(index, autoPlay = false) {
|
|
488
574
|
if (index < 0 || index >= this.episodes.length) return;
|
|
489
|
-
|
|
575
|
+
this.select(this.episodes[index], index, autoPlay);
|
|
576
|
+
}
|
|
577
|
+
select(episode, index, autoPlay) {
|
|
578
|
+
this.currentEpisode = episode;
|
|
490
579
|
this.currentIndex = index;
|
|
491
580
|
const savedPosition = this.storage.getPosition(episode.id);
|
|
492
581
|
this.engine.load(episode.audioUrl, savedPosition ?? void 0);
|
|
493
|
-
this.
|
|
494
|
-
currentEpisodeIndex: this.currentIndex,
|
|
495
|
-
volume: this.engine.volume
|
|
496
|
-
});
|
|
582
|
+
this.persistState();
|
|
497
583
|
this.emit("episode-change", { episode, index });
|
|
498
584
|
this.emit("episode-display", {
|
|
499
585
|
imageUrl: getEpisodeImage(episode),
|
|
@@ -508,9 +594,8 @@ var PlayerController = class extends EventEmitter {
|
|
|
508
594
|
this.loadEpisode(index, true);
|
|
509
595
|
}
|
|
510
596
|
async play() {
|
|
511
|
-
if (this.
|
|
512
|
-
|
|
513
|
-
this.playEpisode(0);
|
|
597
|
+
if (!this.currentEpisode) {
|
|
598
|
+
if (this.episodes.length > 0) this.playEpisode(0);
|
|
514
599
|
return;
|
|
515
600
|
}
|
|
516
601
|
await this.engine.play();
|
|
@@ -526,9 +611,13 @@ var PlayerController = class extends EventEmitter {
|
|
|
526
611
|
}
|
|
527
612
|
setVolume(v) {
|
|
528
613
|
this.engine.volume = v;
|
|
614
|
+
this.persistState();
|
|
615
|
+
}
|
|
616
|
+
persistState() {
|
|
529
617
|
this.stateStorage.saveState({
|
|
530
|
-
|
|
531
|
-
|
|
618
|
+
v: PLAYER_STATE_VERSION,
|
|
619
|
+
episode: this.currentEpisode,
|
|
620
|
+
volume: this.engine.volume
|
|
532
621
|
});
|
|
533
622
|
}
|
|
534
623
|
getPlaylistHtml(feedPageUrl) {
|
|
@@ -554,8 +643,8 @@ var PlayerController = class extends EventEmitter {
|
|
|
554
643
|
}
|
|
555
644
|
}
|
|
556
645
|
saveCurrentPosition() {
|
|
557
|
-
|
|
558
|
-
|
|
646
|
+
const episode = this.currentEpisode;
|
|
647
|
+
if (!episode || !this.engine.hasSrc) return;
|
|
559
648
|
if (this.engine.currentTime > 10) {
|
|
560
649
|
this.storage.savePosition(episode.id, this.engine.currentTime, episode.duration);
|
|
561
650
|
}
|
|
@@ -604,16 +693,16 @@ var MiniPlayer = class extends EventEmitter {
|
|
|
604
693
|
const c = this.controls;
|
|
605
694
|
let controlsHtml = "";
|
|
606
695
|
if (c.skipBackward) {
|
|
607
|
-
controlsHtml +=
|
|
696
|
+
controlsHtml += renderSkipButton("back", this.controller.config.skipSeconds, "pw-btn--mini");
|
|
608
697
|
}
|
|
609
698
|
if (c.playPause) {
|
|
610
699
|
controlsHtml += `
|
|
611
|
-
<button class="pw-btn pw-btn--mini pw-play-btn" aria-label="Play">${ICONS.play}</button>
|
|
612
|
-
<button class="pw-btn pw-btn--mini pw-pause-btn" aria-label="Pause" style="display:none">${ICONS.pause}</button>
|
|
700
|
+
<button class="pw-btn pw-btn--mini pw-btn--play pw-play-btn" aria-label="Play">${ICONS.play}</button>
|
|
701
|
+
<button class="pw-btn pw-btn--mini pw-btn--play pw-pause-btn" aria-label="Pause" style="display:none">${ICONS.pause}</button>
|
|
613
702
|
`;
|
|
614
703
|
}
|
|
615
704
|
if (c.skipForward) {
|
|
616
|
-
controlsHtml +=
|
|
705
|
+
controlsHtml += renderSkipButton("fwd", this.controller.config.skipSeconds, "pw-btn--mini");
|
|
617
706
|
}
|
|
618
707
|
if (c.volume) {
|
|
619
708
|
controlsHtml += `
|
|
@@ -639,7 +728,7 @@ var MiniPlayer = class extends EventEmitter {
|
|
|
639
728
|
const progressHtml = c.progress ? `<div class="pw-mini-progress pw-progress-container" role="slider" aria-label="Seek" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"><div class="pw-mini-progress-bar"></div></div>` : "";
|
|
640
729
|
this.container.innerHTML = `
|
|
641
730
|
<div class="pw-mini">
|
|
642
|
-
|
|
731
|
+
${renderArtwork("pw-mini-artwork")}
|
|
643
732
|
<div class="pw-mini-info">
|
|
644
733
|
<div class="pw-mini-title">No episode playing</div>
|
|
645
734
|
<div class="pw-mini-show"></div>
|
|
@@ -649,7 +738,7 @@ var MiniPlayer = class extends EventEmitter {
|
|
|
649
738
|
</div>
|
|
650
739
|
${c.playlist ? '<div class="pw-mini-playlist" style="display:none"></div>' : ""}
|
|
651
740
|
`;
|
|
652
|
-
this.artworkEl = this.container.querySelector(".pw-mini-artwork");
|
|
741
|
+
this.artworkEl = this.container.querySelector(".pw-mini-artwork img");
|
|
653
742
|
this.titleEl = this.container.querySelector(".pw-mini-title");
|
|
654
743
|
this.showEl = this.container.querySelector(".pw-mini-show");
|
|
655
744
|
this.playBtn = this.container.querySelector(".pw-play-btn");
|
|
@@ -660,6 +749,7 @@ var MiniPlayer = class extends EventEmitter {
|
|
|
660
749
|
}
|
|
661
750
|
bindEvents() {
|
|
662
751
|
const { engine } = this.controller;
|
|
752
|
+
this.cleanupFns.push(hideBrokenImages(this.container));
|
|
663
753
|
this.addClick(".pw-play-btn", () => this.controller.play());
|
|
664
754
|
this.addClick(".pw-pause-btn", () => this.controller.pause());
|
|
665
755
|
this.addClick(".pw-btn--skip-back", () => engine.skipBackward());
|
|
@@ -676,6 +766,7 @@ var MiniPlayer = class extends EventEmitter {
|
|
|
676
766
|
};
|
|
677
767
|
this.progressContainer.addEventListener("click", handler);
|
|
678
768
|
this.cleanupFns.push(() => this.progressContainer?.removeEventListener("click", handler));
|
|
769
|
+
this.cleanupFns.push(attachSeekTooltip(this.progressContainer, () => engine.duration));
|
|
679
770
|
}
|
|
680
771
|
const onTimeUpdate = (d) => {
|
|
681
772
|
if (this.progressBar) {
|
|
@@ -719,14 +810,7 @@ var MiniPlayer = class extends EventEmitter {
|
|
|
719
810
|
const imageUrl = getEpisodeImage(episode);
|
|
720
811
|
if (this.titleEl) this.titleEl.textContent = episode.title;
|
|
721
812
|
if (this.showEl) this.showEl.textContent = episode.feedName;
|
|
722
|
-
|
|
723
|
-
if (imageUrl) {
|
|
724
|
-
this.artworkEl.src = imageUrl;
|
|
725
|
-
this.artworkEl.style.display = "block";
|
|
726
|
-
} else {
|
|
727
|
-
this.artworkEl.style.display = "none";
|
|
728
|
-
}
|
|
729
|
-
}
|
|
813
|
+
setArtwork(this.artworkEl, imageUrl);
|
|
730
814
|
}
|
|
731
815
|
updatePlayPauseState(playing) {
|
|
732
816
|
if (this.playBtn) this.playBtn.style.display = playing ? "none" : "flex";
|
|
@@ -845,7 +929,7 @@ var FullPlayer = class extends EventEmitter {
|
|
|
845
929
|
const c = this.controls;
|
|
846
930
|
let mainControlsHtml = "";
|
|
847
931
|
if (c.skipBackward) {
|
|
848
|
-
mainControlsHtml +=
|
|
932
|
+
mainControlsHtml += renderSkipButton("back", this.controller.config.skipSeconds);
|
|
849
933
|
}
|
|
850
934
|
if (c.playPause) {
|
|
851
935
|
mainControlsHtml += `
|
|
@@ -854,7 +938,7 @@ var FullPlayer = class extends EventEmitter {
|
|
|
854
938
|
`;
|
|
855
939
|
}
|
|
856
940
|
if (c.skipForward) {
|
|
857
|
-
mainControlsHtml +=
|
|
941
|
+
mainControlsHtml += renderSkipButton("fwd", this.controller.config.skipSeconds);
|
|
858
942
|
}
|
|
859
943
|
let secondaryHtml = "";
|
|
860
944
|
if (c.volume) {
|
|
@@ -882,7 +966,7 @@ var FullPlayer = class extends EventEmitter {
|
|
|
882
966
|
<div class="pw-hero-bg"></div>
|
|
883
967
|
<button class="pw-btn-close" aria-label="Minimize player">${ICONS.close}</button>
|
|
884
968
|
<div class="pw-now-playing">
|
|
885
|
-
|
|
969
|
+
${renderArtwork("pw-artwork")}
|
|
886
970
|
<div class="pw-track-info">
|
|
887
971
|
<div class="pw-track-name" aria-live="polite">Select an episode to play</div>
|
|
888
972
|
<div class="pw-track-time" aria-live="off">00:00 / 00:00</div>
|
|
@@ -896,7 +980,7 @@ var FullPlayer = class extends EventEmitter {
|
|
|
896
980
|
</div>
|
|
897
981
|
${playlistHtml}
|
|
898
982
|
`;
|
|
899
|
-
this.artworkEl = this.container.querySelector(".pw-artwork");
|
|
983
|
+
this.artworkEl = this.container.querySelector(".pw-artwork img");
|
|
900
984
|
this.trackNameEl = this.container.querySelector(".pw-track-name");
|
|
901
985
|
this.trackTimeEl = this.container.querySelector(".pw-track-time");
|
|
902
986
|
this.playBtn = this.container.querySelector(".pw-play-btn");
|
|
@@ -908,6 +992,13 @@ var FullPlayer = class extends EventEmitter {
|
|
|
908
992
|
}
|
|
909
993
|
bindEvents() {
|
|
910
994
|
const { engine } = this.controller;
|
|
995
|
+
this.cleanupFns.push(hideBrokenImages(this.container));
|
|
996
|
+
const art = this.artworkEl;
|
|
997
|
+
if (art) {
|
|
998
|
+
const onArtLoad = () => this.setHeroBackground(art.currentSrc || art.src);
|
|
999
|
+
art.addEventListener("load", onArtLoad);
|
|
1000
|
+
this.cleanupFns.push(() => art.removeEventListener("load", onArtLoad));
|
|
1001
|
+
}
|
|
911
1002
|
this.addClick(".pw-btn-close", () => this.hide());
|
|
912
1003
|
if (this.backdrop) {
|
|
913
1004
|
const handler = () => this.hide();
|
|
@@ -934,6 +1025,7 @@ var FullPlayer = class extends EventEmitter {
|
|
|
934
1025
|
};
|
|
935
1026
|
this.progressContainer.addEventListener("click", handler);
|
|
936
1027
|
this.cleanupFns.push(() => this.progressContainer?.removeEventListener("click", handler));
|
|
1028
|
+
this.cleanupFns.push(attachSeekTooltip(this.progressContainer, () => engine.duration));
|
|
937
1029
|
}
|
|
938
1030
|
const onKeyDown = (e) => {
|
|
939
1031
|
if (!this.isVisible) return;
|
|
@@ -1001,23 +1093,13 @@ var FullPlayer = class extends EventEmitter {
|
|
|
1001
1093
|
if (this.trackNameEl) {
|
|
1002
1094
|
this.trackNameEl.textContent = `${episode.feedName}: ${episode.title}`;
|
|
1003
1095
|
}
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
}
|
|
1012
|
-
if (this.heroBg) {
|
|
1013
|
-
if (imageUrl) {
|
|
1014
|
-
this.heroBg.style.backgroundImage = `url("${imageUrl}")`;
|
|
1015
|
-
this.heroBg.classList.add("pw-active");
|
|
1016
|
-
} else {
|
|
1017
|
-
this.heroBg.classList.remove("pw-active");
|
|
1018
|
-
this.heroBg.style.backgroundImage = "";
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1096
|
+
this.setHeroBackground("");
|
|
1097
|
+
setArtwork(this.artworkEl, imageUrl);
|
|
1098
|
+
}
|
|
1099
|
+
setHeroBackground(url) {
|
|
1100
|
+
if (!this.heroBg) return;
|
|
1101
|
+
this.heroBg.style.backgroundImage = url ? `url("${url.replace(/"/g, "%22")}")` : "";
|
|
1102
|
+
this.heroBg.classList.toggle("pw-active", !!url);
|
|
1021
1103
|
}
|
|
1022
1104
|
updatePlayPauseState(playing) {
|
|
1023
1105
|
if (this.playBtn) this.playBtn.style.display = playing ? "none" : "flex";
|
|
@@ -1092,6 +1174,7 @@ export {
|
|
|
1092
1174
|
FullPlayer,
|
|
1093
1175
|
ICONS,
|
|
1094
1176
|
MiniPlayer,
|
|
1177
|
+
PLAYER_STATE_VERSION,
|
|
1095
1178
|
PlaybackStorage,
|
|
1096
1179
|
PlayerController,
|
|
1097
1180
|
PlayerStateStorage,
|