@dudgy/podcast-widget 0.2.0 → 0.3.1
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 +189 -103
- package/dist/index.d.cts +31 -5
- package/dist/index.d.ts +31 -5
- package/dist/index.js +158 -72
- package/dist/podcast-player.css +138 -36
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -61,7 +61,7 @@ podcast-widget/
|
|
|
61
61
|
│ │ ├── player-state.ts # localStorage for player state + speed preference
|
|
62
62
|
│ │ └── episode-provider.ts # FetchEpisodeProvider with caching + retry
|
|
63
63
|
│ ├── ui/
|
|
64
|
-
│ │ ├── utils.ts #
|
|
64
|
+
│ │ ├── utils.ts # Formatting, artwork fallback, seek tooltip
|
|
65
65
|
│ │ ├── html-templates.ts # SVG icons, playlist rendering, speed options
|
|
66
66
|
│ │ ├── player-controller.ts # Orchestrator: engine + storage + provider → events
|
|
67
67
|
│ │ ├── mini-player.ts # Mini mode with configurable controls + inline playlist
|
|
@@ -73,6 +73,8 @@ podcast-widget/
|
|
|
73
73
|
│ ├── styles/
|
|
74
74
|
│ │ └── podcast-player.css # Plain CSS with custom property theming (pw- prefix)
|
|
75
75
|
│ └── index.ts # Main barrel export
|
|
76
|
+
├── tests/ # Unit tests (Vitest + jsdom)
|
|
77
|
+
├── e2e/ # Browser tests (Playwright, Chrome + WebKit)
|
|
76
78
|
├── package.json # Dual ESM/CJS, subpath exports
|
|
77
79
|
├── tsconfig.json # Client-side TS config
|
|
78
80
|
├── tsconfig.server.json # Server-side (podcast-index) config
|
|
@@ -194,13 +196,15 @@ controller.playEpisode(2); // Load and play
|
|
|
194
196
|
controller.setSpeed(1.5);
|
|
195
197
|
controller.setVolume(0.8);
|
|
196
198
|
|
|
197
|
-
controller.on('episode-change', ({ episode, index }) => {});
|
|
199
|
+
controller.on('episode-change', ({ episode, index }) => {}); // index is -1 if not in the list
|
|
198
200
|
controller.on('episodes-loaded', ({ episodes }) => {});
|
|
199
201
|
controller.on('episode-display', ({ imageUrl, title, show }) => {});
|
|
200
202
|
|
|
201
203
|
controller.destroy();
|
|
202
204
|
```
|
|
203
205
|
|
|
206
|
+
**Restoring on page load.** `loadEpisodes()` restores the episode the listener last had loaded (paused, at its saved position). The episode is saved as a snapshot and matched by `id`, so episode IDs must be stable across fetches — use the feed's `guid` where possible rather than list position or a URL that may change. If the saved episode is still in the list, the fresh copy is used; if it has dropped out (e.g. its feed published something newer), it's restored from the snapshot with `getCurrentIndex() === -1`. With nothing saved, the first episode is cued. Saved resume positions are kept for listed episodes and the current one; others are cleaned up.
|
|
207
|
+
|
|
204
208
|
### EpisodeProvider
|
|
205
209
|
|
|
206
210
|
Interface for loading episodes. The package ships `FetchEpisodeProvider` which fetches from a URL with caching and retry.
|
|
@@ -304,9 +308,30 @@ const headers = createPodcastIndexHeaders(apiKey, apiSecret);
|
|
|
304
308
|
npm run build # Build
|
|
305
309
|
npm run dev # Build + watch
|
|
306
310
|
npm run typecheck # Type check
|
|
307
|
-
npm test #
|
|
311
|
+
npm test # Unit tests (Vitest + jsdom)
|
|
312
|
+
npm run test:e2e # Build, then browser tests in Chrome and WebKit
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### Browser tests
|
|
316
|
+
|
|
317
|
+
`e2e/` drives the built package in real browsers through a fixture page
|
|
318
|
+
(`e2e/fixture.html`). Requests are intercepted and answered from code — the page,
|
|
319
|
+
`dist/`, a test-controlled episode list, generated silent audio and test images — so
|
|
320
|
+
there's no server, network access or API keys, and results are repeatable.
|
|
321
|
+
|
|
322
|
+
They cover restoring the listener's episode and position, skip buttons, artwork
|
|
323
|
+
fallback, the seek tooltip, layout, and exact-match screenshots of the players
|
|
324
|
+
(`e2e/player.spec.ts-snapshots/`). After an intended visual change, regenerate the
|
|
325
|
+
screenshots and look at them before committing:
|
|
326
|
+
|
|
327
|
+
```bash
|
|
328
|
+
npm run test:e2e -- --update-snapshots=all
|
|
308
329
|
```
|
|
309
330
|
|
|
331
|
+
Requirements: Google Chrome installed (the `chrome` project uses the system
|
|
332
|
+
browser), and Playwright's WebKit (`npx playwright install webkit`) with its system
|
|
333
|
+
libraries (`npx playwright install-deps webkit`, needs sudo).
|
|
334
|
+
|
|
310
335
|
### Testing in a Consumer Before Publishing
|
|
311
336
|
|
|
312
337
|
```bash
|
package/dist/index.cjs
CHANGED
|
@@ -49,6 +49,7 @@ var AudioEngine = (_class2 = class extends EventEmitter {
|
|
|
49
49
|
this.onLoadedMetadata = () => {
|
|
50
50
|
this.audio.playbackRate = this._playbackRate;
|
|
51
51
|
this.emit("loaded-metadata", { duration: this.audio.duration });
|
|
52
|
+
this.onTimeUpdate();
|
|
52
53
|
};
|
|
53
54
|
this.onError = () => {
|
|
54
55
|
const err = this.audio.error;
|
|
@@ -58,6 +59,7 @@ var AudioEngine = (_class2 = class extends EventEmitter {
|
|
|
58
59
|
});
|
|
59
60
|
};
|
|
60
61
|
this.audio.addEventListener("timeupdate", this.onTimeUpdate);
|
|
62
|
+
this.audio.addEventListener("loadstart", this.onTimeUpdate);
|
|
61
63
|
this.audio.addEventListener("ended", this.onEnded);
|
|
62
64
|
this.audio.addEventListener("loadedmetadata", this.onLoadedMetadata);
|
|
63
65
|
this.audio.addEventListener("error", this.onError);
|
|
@@ -143,6 +145,7 @@ var AudioEngine = (_class2 = class extends EventEmitter {
|
|
|
143
145
|
// ─── Cleanup ───────────────────────────────────────────────────
|
|
144
146
|
destroy() {
|
|
145
147
|
this.audio.removeEventListener("timeupdate", this.onTimeUpdate);
|
|
148
|
+
this.audio.removeEventListener("loadstart", this.onTimeUpdate);
|
|
146
149
|
this.audio.removeEventListener("ended", this.onEnded);
|
|
147
150
|
this.audio.removeEventListener("loadedmetadata", this.onLoadedMetadata);
|
|
148
151
|
this.audio.removeEventListener("error", this.onError);
|
|
@@ -198,10 +201,11 @@ var PlaybackStorage = class {
|
|
|
198
201
|
} catch (e4) {
|
|
199
202
|
}
|
|
200
203
|
}
|
|
201
|
-
|
|
204
|
+
/** Remove saved positions for episodes whose IDs aren't in `keepIds`. */
|
|
205
|
+
cleanupPositions(keepIds) {
|
|
202
206
|
try {
|
|
203
207
|
const positions = this.getPositions();
|
|
204
|
-
const currentSet = new Set(
|
|
208
|
+
const currentSet = new Set(keepIds);
|
|
205
209
|
let changed = false;
|
|
206
210
|
for (const id of Object.keys(positions)) {
|
|
207
211
|
if (!currentSet.has(id)) {
|
|
@@ -217,6 +221,19 @@ var PlaybackStorage = class {
|
|
|
217
221
|
}
|
|
218
222
|
};
|
|
219
223
|
|
|
224
|
+
// src/core/types.ts
|
|
225
|
+
var PLAYER_STATE_VERSION = 2;
|
|
226
|
+
var DEFAULT_CONFIG = {
|
|
227
|
+
storagePrefix: "podcast",
|
|
228
|
+
maxStoredPositions: 100,
|
|
229
|
+
positionSaveInterval: 5e3,
|
|
230
|
+
skipSeconds: 30,
|
|
231
|
+
episodeCacheTTL: 60 * 60 * 1e3
|
|
232
|
+
};
|
|
233
|
+
function resolveConfig(config) {
|
|
234
|
+
return { ...DEFAULT_CONFIG, ...config };
|
|
235
|
+
}
|
|
236
|
+
|
|
220
237
|
// src/core/player-state.ts
|
|
221
238
|
var PlayerStateStorage = class {
|
|
222
239
|
|
|
@@ -231,11 +248,22 @@ var PlayerStateStorage = class {
|
|
|
231
248
|
} catch (e6) {
|
|
232
249
|
}
|
|
233
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* Load saved state, migrating older formats. Returns null if nothing usable
|
|
253
|
+
* is saved.
|
|
254
|
+
*
|
|
255
|
+
* Unversioned (v1) state stored only an index into the episode list, which
|
|
256
|
+
* can't be trusted once the list changes, so only its volume is kept.
|
|
257
|
+
*/
|
|
234
258
|
loadState() {
|
|
235
259
|
try {
|
|
236
260
|
const raw = localStorage.getItem(this.stateKey);
|
|
237
261
|
if (!raw) return null;
|
|
238
|
-
|
|
262
|
+
const data = JSON.parse(raw);
|
|
263
|
+
if (!data || typeof data !== "object") return null;
|
|
264
|
+
const volume = isVolume(data.volume) ? data.volume : 1;
|
|
265
|
+
const episode = data.v === PLAYER_STATE_VERSION && isEpisode(data.episode) ? data.episode : null;
|
|
266
|
+
return { v: PLAYER_STATE_VERSION, episode, volume };
|
|
239
267
|
} catch (e7) {
|
|
240
268
|
return null;
|
|
241
269
|
}
|
|
@@ -257,6 +285,14 @@ var PlayerStateStorage = class {
|
|
|
257
285
|
}
|
|
258
286
|
}
|
|
259
287
|
};
|
|
288
|
+
function isVolume(v) {
|
|
289
|
+
return typeof v === "number" && v >= 0 && v <= 1;
|
|
290
|
+
}
|
|
291
|
+
function isEpisode(e) {
|
|
292
|
+
if (!e || typeof e !== "object") return false;
|
|
293
|
+
const ep = e;
|
|
294
|
+
return typeof ep.id === "string" && typeof ep.audioUrl === "string" && typeof ep.title === "string" && typeof ep.feedName === "string";
|
|
295
|
+
}
|
|
260
296
|
|
|
261
297
|
// src/core/episode-provider.ts
|
|
262
298
|
var FetchEpisodeProvider = class {
|
|
@@ -314,18 +350,6 @@ var FetchEpisodeProvider = class {
|
|
|
314
350
|
}
|
|
315
351
|
};
|
|
316
352
|
|
|
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
353
|
// src/ui/utils.ts
|
|
330
354
|
function formatTime(seconds) {
|
|
331
355
|
if (isNaN(seconds) || seconds < 0) return "00:00";
|
|
@@ -368,20 +392,75 @@ function escapeHtml(str) {
|
|
|
368
392
|
function getEpisodeImage(episode) {
|
|
369
393
|
return episode.image || episode.feedImage || episode.artwork || "";
|
|
370
394
|
}
|
|
395
|
+
function setArtwork(img, url) {
|
|
396
|
+
if (!img) return;
|
|
397
|
+
img.hidden = !url;
|
|
398
|
+
if (url) img.src = url;
|
|
399
|
+
else img.removeAttribute("src");
|
|
400
|
+
}
|
|
401
|
+
function hideBrokenImages(root) {
|
|
402
|
+
const onError = (e) => {
|
|
403
|
+
const t = e.target;
|
|
404
|
+
if (t instanceof HTMLImageElement && _optionalChain([t, 'access', _13 => _13.parentElement, 'optionalAccess', _14 => _14.classList, 'access', _15 => _15.contains, 'call', _16 => _16("pw-art")])) t.hidden = true;
|
|
405
|
+
};
|
|
406
|
+
root.addEventListener("error", onError, true);
|
|
407
|
+
return () => root.removeEventListener("error", onError, true);
|
|
408
|
+
}
|
|
409
|
+
function attachSeekTooltip(bar, getDuration) {
|
|
410
|
+
const tip = document.createElement("div");
|
|
411
|
+
tip.className = "pw-seek-tooltip";
|
|
412
|
+
tip.setAttribute("aria-hidden", "true");
|
|
413
|
+
tip.hidden = true;
|
|
414
|
+
bar.appendChild(tip);
|
|
415
|
+
const onMove = (e) => {
|
|
416
|
+
const duration = getDuration();
|
|
417
|
+
if (e.pointerType === "touch" || !(duration > 0)) {
|
|
418
|
+
tip.hidden = true;
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
const rect = bar.getBoundingClientRect();
|
|
422
|
+
const frac = Math.min(1, Math.max(0, (e.clientX - rect.left) / rect.width));
|
|
423
|
+
tip.textContent = formatTime(frac * duration);
|
|
424
|
+
tip.hidden = false;
|
|
425
|
+
const half = tip.offsetWidth / 2;
|
|
426
|
+
tip.style.left = `${Math.min(rect.width - half, Math.max(half, frac * rect.width))}px`;
|
|
427
|
+
};
|
|
428
|
+
const onLeave = () => {
|
|
429
|
+
tip.hidden = true;
|
|
430
|
+
};
|
|
431
|
+
bar.addEventListener("pointermove", onMove);
|
|
432
|
+
bar.addEventListener("pointerleave", onLeave);
|
|
433
|
+
return () => {
|
|
434
|
+
bar.removeEventListener("pointermove", onMove);
|
|
435
|
+
bar.removeEventListener("pointerleave", onLeave);
|
|
436
|
+
tip.remove();
|
|
437
|
+
};
|
|
438
|
+
}
|
|
371
439
|
|
|
372
440
|
// src/ui/html-templates.ts
|
|
373
441
|
var ICONS = {
|
|
374
442
|
play: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>',
|
|
375
443
|
pause: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M6 19h4V5H6v14zm8-14v14h4V5h-4z"/></svg>',
|
|
376
|
-
|
|
377
|
-
|
|
444
|
+
// Plain circular arrows; the seconds are drawn as text on top (see renderSkipButton)
|
|
445
|
+
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>',
|
|
446
|
+
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
447
|
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
448
|
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
449
|
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
450
|
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
451
|
playlist: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M3 13h2v-2H3v2zm0 4h2v-2H3v2zm0-8h2V7H3v2zm4 4h14v-2H7v2zm0 4h14v-2H7v2zM7 7v2h14V7H7z"/></svg>',
|
|
452
|
+
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
453
|
download: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z"/></svg>'
|
|
384
454
|
};
|
|
455
|
+
function renderArtwork(className, imageUrl) {
|
|
456
|
+
const img = imageUrl ? `<img src="${escapeHtml(imageUrl)}" alt="">` : '<img alt="" hidden>';
|
|
457
|
+
return `<span class="pw-art ${className}">${img}${ICONS.note}</span>`;
|
|
458
|
+
}
|
|
459
|
+
function renderSkipButton(direction, seconds, extraClass = "") {
|
|
460
|
+
const label = `${direction === "back" ? "Back" : "Forward"} ${seconds} seconds`;
|
|
461
|
+
const icon = direction === "back" ? ICONS.skipBack : ICONS.skipForward;
|
|
462
|
+
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>`;
|
|
463
|
+
}
|
|
385
464
|
var SPEED_OPTIONS = [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.5, 3];
|
|
386
465
|
function renderPlaylistItem(episode, index, opts) {
|
|
387
466
|
const imageUrl = getEpisodeImage(episode);
|
|
@@ -397,7 +476,7 @@ function renderPlaylistItem(episode, index, opts) {
|
|
|
397
476
|
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
477
|
return `
|
|
399
478
|
<div class="pw-playlist-item ${opts.isPlaying ? "pw-playing" : ""} ${hasSaved ? "pw-has-saved" : ""}" data-index="${index}">
|
|
400
|
-
${
|
|
479
|
+
${renderArtwork("pw-episode-image", imageUrl)}
|
|
401
480
|
<div class="pw-episode-info">
|
|
402
481
|
<div class="pw-episode-show">${escapeHtml(episode.feedName || "Unknown Show")}</div>
|
|
403
482
|
<div class="pw-episode-title">${escapeHtml(episode.title)}</div>
|
|
@@ -433,11 +512,14 @@ var PlayerController = (_class3 = class extends EventEmitter {
|
|
|
433
512
|
|
|
434
513
|
|
|
435
514
|
__init4() {this.episodes = []}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
515
|
+
/** The loaded episode. May not be in `episodes` (e.g. restored after its feed moved on). */
|
|
516
|
+
__init5() {this.currentEpisode = null}
|
|
517
|
+
/** Index of `currentEpisode` in `episodes`, or -1 if it isn't in the list. */
|
|
518
|
+
__init6() {this.currentIndex = -1}
|
|
519
|
+
__init7() {this.saveInterval = null}
|
|
520
|
+
__init8() {this.cleanupFns = []}
|
|
439
521
|
constructor(engine, provider, config) {
|
|
440
|
-
super();_class3.prototype.__init4.call(this);_class3.prototype.__init5.call(this);_class3.prototype.__init6.call(this);_class3.prototype.__init7.call(this);;
|
|
522
|
+
super();_class3.prototype.__init4.call(this);_class3.prototype.__init5.call(this);_class3.prototype.__init6.call(this);_class3.prototype.__init7.call(this);_class3.prototype.__init8.call(this);;
|
|
441
523
|
this.config = resolveConfig(config);
|
|
442
524
|
this.engine = engine;
|
|
443
525
|
this.provider = provider;
|
|
@@ -448,12 +530,12 @@ var PlayerController = (_class3 = class extends EventEmitter {
|
|
|
448
530
|
this.engine.playbackRate = savedSpeed;
|
|
449
531
|
}
|
|
450
532
|
const savedState = this.stateStorage.loadState();
|
|
451
|
-
if (_optionalChain([savedState, 'optionalAccess',
|
|
533
|
+
if (_optionalChain([savedState, 'optionalAccess', _17 => _17.volume]) != null) {
|
|
452
534
|
this.engine.volume = savedState.volume;
|
|
453
535
|
}
|
|
454
536
|
this.engine.on("ended", () => {
|
|
455
|
-
if (this.
|
|
456
|
-
this.storage.removePosition(this.
|
|
537
|
+
if (this.currentEpisode) {
|
|
538
|
+
this.storage.removePosition(this.currentEpisode.id);
|
|
457
539
|
}
|
|
458
540
|
this.stopPositionSaving();
|
|
459
541
|
});
|
|
@@ -467,11 +549,17 @@ var PlayerController = (_class3 = class extends EventEmitter {
|
|
|
467
549
|
// ─── Episode management ────────────────────────────────────────
|
|
468
550
|
async loadEpisodes() {
|
|
469
551
|
this.episodes = await this.provider.getEpisodes();
|
|
470
|
-
|
|
552
|
+
const saved = _nullishCoalesce(_optionalChain([this, 'access', _18 => _18.stateStorage, 'access', _19 => _19.loadState, 'call', _20 => _20(), 'optionalAccess', _21 => _21.episode]), () => ( null));
|
|
553
|
+
const keepIds = this.episodes.map((ep) => ep.id);
|
|
554
|
+
if (saved) keepIds.push(saved.id);
|
|
555
|
+
this.storage.cleanupPositions(keepIds);
|
|
471
556
|
this.emit("episodes-loaded", { episodes: this.episodes });
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
this.loadEpisode(
|
|
557
|
+
if (saved) {
|
|
558
|
+
const index = this.episodes.findIndex((ep) => ep.id === saved.id);
|
|
559
|
+
if (index >= 0) this.loadEpisode(index, false);
|
|
560
|
+
else this.select(saved, -1, false);
|
|
561
|
+
} else if (this.episodes.length > 0) {
|
|
562
|
+
this.loadEpisode(0, false);
|
|
475
563
|
}
|
|
476
564
|
return this.episodes;
|
|
477
565
|
}
|
|
@@ -479,21 +567,22 @@ var PlayerController = (_class3 = class extends EventEmitter {
|
|
|
479
567
|
return this.episodes;
|
|
480
568
|
}
|
|
481
569
|
getCurrentEpisode() {
|
|
482
|
-
return this.
|
|
570
|
+
return this.currentEpisode;
|
|
483
571
|
}
|
|
572
|
+
/** Index of the current episode in the list, or -1 if none or not listed. */
|
|
484
573
|
getCurrentIndex() {
|
|
485
574
|
return this.currentIndex;
|
|
486
575
|
}
|
|
487
576
|
loadEpisode(index, autoPlay = false) {
|
|
488
577
|
if (index < 0 || index >= this.episodes.length) return;
|
|
489
|
-
|
|
578
|
+
this.select(this.episodes[index], index, autoPlay);
|
|
579
|
+
}
|
|
580
|
+
select(episode, index, autoPlay) {
|
|
581
|
+
this.currentEpisode = episode;
|
|
490
582
|
this.currentIndex = index;
|
|
491
583
|
const savedPosition = this.storage.getPosition(episode.id);
|
|
492
584
|
this.engine.load(episode.audioUrl, _nullishCoalesce(savedPosition, () => ( void 0)));
|
|
493
|
-
this.
|
|
494
|
-
currentEpisodeIndex: this.currentIndex,
|
|
495
|
-
volume: this.engine.volume
|
|
496
|
-
});
|
|
585
|
+
this.persistState();
|
|
497
586
|
this.emit("episode-change", { episode, index });
|
|
498
587
|
this.emit("episode-display", {
|
|
499
588
|
imageUrl: getEpisodeImage(episode),
|
|
@@ -508,9 +597,8 @@ var PlayerController = (_class3 = class extends EventEmitter {
|
|
|
508
597
|
this.loadEpisode(index, true);
|
|
509
598
|
}
|
|
510
599
|
async play() {
|
|
511
|
-
if (this.
|
|
512
|
-
|
|
513
|
-
this.playEpisode(0);
|
|
600
|
+
if (!this.currentEpisode) {
|
|
601
|
+
if (this.episodes.length > 0) this.playEpisode(0);
|
|
514
602
|
return;
|
|
515
603
|
}
|
|
516
604
|
await this.engine.play();
|
|
@@ -526,9 +614,13 @@ var PlayerController = (_class3 = class extends EventEmitter {
|
|
|
526
614
|
}
|
|
527
615
|
setVolume(v) {
|
|
528
616
|
this.engine.volume = v;
|
|
617
|
+
this.persistState();
|
|
618
|
+
}
|
|
619
|
+
persistState() {
|
|
529
620
|
this.stateStorage.saveState({
|
|
530
|
-
|
|
531
|
-
|
|
621
|
+
v: PLAYER_STATE_VERSION,
|
|
622
|
+
episode: this.currentEpisode,
|
|
623
|
+
volume: this.engine.volume
|
|
532
624
|
});
|
|
533
625
|
}
|
|
534
626
|
getPlaylistHtml(feedPageUrl) {
|
|
@@ -554,8 +646,8 @@ var PlayerController = (_class3 = class extends EventEmitter {
|
|
|
554
646
|
}
|
|
555
647
|
}
|
|
556
648
|
saveCurrentPosition() {
|
|
557
|
-
|
|
558
|
-
|
|
649
|
+
const episode = this.currentEpisode;
|
|
650
|
+
if (!episode || !this.engine.hasSrc) return;
|
|
559
651
|
if (this.engine.currentTime > 10) {
|
|
560
652
|
this.storage.savePosition(episode.id, this.engine.currentTime, episode.duration);
|
|
561
653
|
}
|
|
@@ -576,19 +668,19 @@ var MiniPlayer = (_class4 = class extends EventEmitter {
|
|
|
576
668
|
|
|
577
669
|
|
|
578
670
|
|
|
579
|
-
|
|
671
|
+
__init9() {this.cleanupFns = []}
|
|
580
672
|
// Element references (created during render)
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
673
|
+
__init10() {this.artworkEl = null}
|
|
674
|
+
__init11() {this.titleEl = null}
|
|
675
|
+
__init12() {this.showEl = null}
|
|
676
|
+
__init13() {this.playBtn = null}
|
|
677
|
+
__init14() {this.pauseBtn = null}
|
|
678
|
+
__init15() {this.progressBar = null}
|
|
679
|
+
__init16() {this.progressContainer = null}
|
|
680
|
+
__init17() {this.playlistContainer = null}
|
|
681
|
+
__init18() {this.playlistOpen = false}
|
|
590
682
|
constructor(opts) {
|
|
591
|
-
super();_class4.prototype.
|
|
683
|
+
super();_class4.prototype.__init9.call(this);_class4.prototype.__init10.call(this);_class4.prototype.__init11.call(this);_class4.prototype.__init12.call(this);_class4.prototype.__init13.call(this);_class4.prototype.__init14.call(this);_class4.prototype.__init15.call(this);_class4.prototype.__init16.call(this);_class4.prototype.__init17.call(this);_class4.prototype.__init18.call(this);;
|
|
592
684
|
this.container = opts.container;
|
|
593
685
|
this.controller = opts.controller;
|
|
594
686
|
this.controls = {
|
|
@@ -604,16 +696,16 @@ var MiniPlayer = (_class4 = class extends EventEmitter {
|
|
|
604
696
|
const c = this.controls;
|
|
605
697
|
let controlsHtml = "";
|
|
606
698
|
if (c.skipBackward) {
|
|
607
|
-
controlsHtml +=
|
|
699
|
+
controlsHtml += renderSkipButton("back", this.controller.config.skipSeconds, "pw-btn--mini");
|
|
608
700
|
}
|
|
609
701
|
if (c.playPause) {
|
|
610
702
|
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>
|
|
703
|
+
<button class="pw-btn pw-btn--mini pw-btn--play pw-play-btn" aria-label="Play">${ICONS.play}</button>
|
|
704
|
+
<button class="pw-btn pw-btn--mini pw-btn--play pw-pause-btn" aria-label="Pause" style="display:none">${ICONS.pause}</button>
|
|
613
705
|
`;
|
|
614
706
|
}
|
|
615
707
|
if (c.skipForward) {
|
|
616
|
-
controlsHtml +=
|
|
708
|
+
controlsHtml += renderSkipButton("fwd", this.controller.config.skipSeconds, "pw-btn--mini");
|
|
617
709
|
}
|
|
618
710
|
if (c.volume) {
|
|
619
711
|
controlsHtml += `
|
|
@@ -639,7 +731,7 @@ var MiniPlayer = (_class4 = class extends EventEmitter {
|
|
|
639
731
|
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
732
|
this.container.innerHTML = `
|
|
641
733
|
<div class="pw-mini">
|
|
642
|
-
|
|
734
|
+
${renderArtwork("pw-mini-artwork")}
|
|
643
735
|
<div class="pw-mini-info">
|
|
644
736
|
<div class="pw-mini-title">No episode playing</div>
|
|
645
737
|
<div class="pw-mini-show"></div>
|
|
@@ -649,7 +741,7 @@ var MiniPlayer = (_class4 = class extends EventEmitter {
|
|
|
649
741
|
</div>
|
|
650
742
|
${c.playlist ? '<div class="pw-mini-playlist" style="display:none"></div>' : ""}
|
|
651
743
|
`;
|
|
652
|
-
this.artworkEl = this.container.querySelector(".pw-mini-artwork");
|
|
744
|
+
this.artworkEl = this.container.querySelector(".pw-mini-artwork img");
|
|
653
745
|
this.titleEl = this.container.querySelector(".pw-mini-title");
|
|
654
746
|
this.showEl = this.container.querySelector(".pw-mini-show");
|
|
655
747
|
this.playBtn = this.container.querySelector(".pw-play-btn");
|
|
@@ -660,6 +752,7 @@ var MiniPlayer = (_class4 = class extends EventEmitter {
|
|
|
660
752
|
}
|
|
661
753
|
bindEvents() {
|
|
662
754
|
const { engine } = this.controller;
|
|
755
|
+
this.cleanupFns.push(hideBrokenImages(this.container));
|
|
663
756
|
this.addClick(".pw-play-btn", () => this.controller.play());
|
|
664
757
|
this.addClick(".pw-pause-btn", () => this.controller.pause());
|
|
665
758
|
this.addClick(".pw-btn--skip-back", () => engine.skipBackward());
|
|
@@ -675,7 +768,8 @@ var MiniPlayer = (_class4 = class extends EventEmitter {
|
|
|
675
768
|
engine.seekToPercentage(Math.max(0, Math.min(100, pct)));
|
|
676
769
|
};
|
|
677
770
|
this.progressContainer.addEventListener("click", handler);
|
|
678
|
-
this.cleanupFns.push(() => _optionalChain([this, 'access',
|
|
771
|
+
this.cleanupFns.push(() => _optionalChain([this, 'access', _22 => _22.progressContainer, 'optionalAccess', _23 => _23.removeEventListener, 'call', _24 => _24("click", handler)]));
|
|
772
|
+
this.cleanupFns.push(attachSeekTooltip(this.progressContainer, () => engine.duration));
|
|
679
773
|
}
|
|
680
774
|
const onTimeUpdate = (d) => {
|
|
681
775
|
if (this.progressBar) {
|
|
@@ -719,14 +813,7 @@ var MiniPlayer = (_class4 = class extends EventEmitter {
|
|
|
719
813
|
const imageUrl = getEpisodeImage(episode);
|
|
720
814
|
if (this.titleEl) this.titleEl.textContent = episode.title;
|
|
721
815
|
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
|
-
}
|
|
816
|
+
setArtwork(this.artworkEl, imageUrl);
|
|
730
817
|
}
|
|
731
818
|
updatePlayPauseState(playing) {
|
|
732
819
|
if (this.playBtn) this.playBtn.style.display = playing ? "none" : "flex";
|
|
@@ -793,19 +880,19 @@ var FullPlayer = (_class5 = class extends EventEmitter {
|
|
|
793
880
|
|
|
794
881
|
|
|
795
882
|
|
|
796
|
-
|
|
883
|
+
__init19() {this.cleanupFns = []}
|
|
797
884
|
// Element references
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
885
|
+
__init20() {this.artworkEl = null}
|
|
886
|
+
__init21() {this.trackNameEl = null}
|
|
887
|
+
__init22() {this.trackTimeEl = null}
|
|
888
|
+
__init23() {this.playBtn = null}
|
|
889
|
+
__init24() {this.pauseBtn = null}
|
|
890
|
+
__init25() {this.progressBar = null}
|
|
891
|
+
__init26() {this.progressContainer = null}
|
|
892
|
+
__init27() {this.playlistEl = null}
|
|
893
|
+
__init28() {this.heroBg = null}
|
|
807
894
|
constructor(opts) {
|
|
808
|
-
super();_class5.prototype.
|
|
895
|
+
super();_class5.prototype.__init19.call(this);_class5.prototype.__init20.call(this);_class5.prototype.__init21.call(this);_class5.prototype.__init22.call(this);_class5.prototype.__init23.call(this);_class5.prototype.__init24.call(this);_class5.prototype.__init25.call(this);_class5.prototype.__init26.call(this);_class5.prototype.__init27.call(this);_class5.prototype.__init28.call(this);;
|
|
809
896
|
this.container = opts.container;
|
|
810
897
|
this.backdrop = _nullishCoalesce(opts.backdrop, () => ( null));
|
|
811
898
|
this.controller = opts.controller;
|
|
@@ -845,7 +932,7 @@ var FullPlayer = (_class5 = class extends EventEmitter {
|
|
|
845
932
|
const c = this.controls;
|
|
846
933
|
let mainControlsHtml = "";
|
|
847
934
|
if (c.skipBackward) {
|
|
848
|
-
mainControlsHtml +=
|
|
935
|
+
mainControlsHtml += renderSkipButton("back", this.controller.config.skipSeconds);
|
|
849
936
|
}
|
|
850
937
|
if (c.playPause) {
|
|
851
938
|
mainControlsHtml += `
|
|
@@ -854,7 +941,7 @@ var FullPlayer = (_class5 = class extends EventEmitter {
|
|
|
854
941
|
`;
|
|
855
942
|
}
|
|
856
943
|
if (c.skipForward) {
|
|
857
|
-
mainControlsHtml +=
|
|
944
|
+
mainControlsHtml += renderSkipButton("fwd", this.controller.config.skipSeconds);
|
|
858
945
|
}
|
|
859
946
|
let secondaryHtml = "";
|
|
860
947
|
if (c.volume) {
|
|
@@ -882,7 +969,7 @@ var FullPlayer = (_class5 = class extends EventEmitter {
|
|
|
882
969
|
<div class="pw-hero-bg"></div>
|
|
883
970
|
<button class="pw-btn-close" aria-label="Minimize player">${ICONS.close}</button>
|
|
884
971
|
<div class="pw-now-playing">
|
|
885
|
-
|
|
972
|
+
${renderArtwork("pw-artwork")}
|
|
886
973
|
<div class="pw-track-info">
|
|
887
974
|
<div class="pw-track-name" aria-live="polite">Select an episode to play</div>
|
|
888
975
|
<div class="pw-track-time" aria-live="off">00:00 / 00:00</div>
|
|
@@ -896,7 +983,7 @@ var FullPlayer = (_class5 = class extends EventEmitter {
|
|
|
896
983
|
</div>
|
|
897
984
|
${playlistHtml}
|
|
898
985
|
`;
|
|
899
|
-
this.artworkEl = this.container.querySelector(".pw-artwork");
|
|
986
|
+
this.artworkEl = this.container.querySelector(".pw-artwork img");
|
|
900
987
|
this.trackNameEl = this.container.querySelector(".pw-track-name");
|
|
901
988
|
this.trackTimeEl = this.container.querySelector(".pw-track-time");
|
|
902
989
|
this.playBtn = this.container.querySelector(".pw-play-btn");
|
|
@@ -908,11 +995,18 @@ var FullPlayer = (_class5 = class extends EventEmitter {
|
|
|
908
995
|
}
|
|
909
996
|
bindEvents() {
|
|
910
997
|
const { engine } = this.controller;
|
|
998
|
+
this.cleanupFns.push(hideBrokenImages(this.container));
|
|
999
|
+
const art = this.artworkEl;
|
|
1000
|
+
if (art) {
|
|
1001
|
+
const onArtLoad = () => this.setHeroBackground(art.currentSrc || art.src);
|
|
1002
|
+
art.addEventListener("load", onArtLoad);
|
|
1003
|
+
this.cleanupFns.push(() => art.removeEventListener("load", onArtLoad));
|
|
1004
|
+
}
|
|
911
1005
|
this.addClick(".pw-btn-close", () => this.hide());
|
|
912
1006
|
if (this.backdrop) {
|
|
913
1007
|
const handler = () => this.hide();
|
|
914
1008
|
this.backdrop.addEventListener("click", handler);
|
|
915
|
-
this.cleanupFns.push(() => _optionalChain([this, 'access',
|
|
1009
|
+
this.cleanupFns.push(() => _optionalChain([this, 'access', _25 => _25.backdrop, 'optionalAccess', _26 => _26.removeEventListener, 'call', _27 => _27("click", handler)]));
|
|
916
1010
|
}
|
|
917
1011
|
const feedLinkHandler = (e) => {
|
|
918
1012
|
if (e.target.closest("[data-feed-link]")) this.hide();
|
|
@@ -933,7 +1027,8 @@ var FullPlayer = (_class5 = class extends EventEmitter {
|
|
|
933
1027
|
engine.seekToPercentage(Math.max(0, Math.min(100, pct)));
|
|
934
1028
|
};
|
|
935
1029
|
this.progressContainer.addEventListener("click", handler);
|
|
936
|
-
this.cleanupFns.push(() => _optionalChain([this, 'access',
|
|
1030
|
+
this.cleanupFns.push(() => _optionalChain([this, 'access', _28 => _28.progressContainer, 'optionalAccess', _29 => _29.removeEventListener, 'call', _30 => _30("click", handler)]));
|
|
1031
|
+
this.cleanupFns.push(attachSeekTooltip(this.progressContainer, () => engine.duration));
|
|
937
1032
|
}
|
|
938
1033
|
const onKeyDown = (e) => {
|
|
939
1034
|
if (!this.isVisible) return;
|
|
@@ -1001,23 +1096,13 @@ var FullPlayer = (_class5 = class extends EventEmitter {
|
|
|
1001
1096
|
if (this.trackNameEl) {
|
|
1002
1097
|
this.trackNameEl.textContent = `${episode.feedName}: ${episode.title}`;
|
|
1003
1098
|
}
|
|
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
|
-
}
|
|
1099
|
+
this.setHeroBackground("");
|
|
1100
|
+
setArtwork(this.artworkEl, imageUrl);
|
|
1101
|
+
}
|
|
1102
|
+
setHeroBackground(url) {
|
|
1103
|
+
if (!this.heroBg) return;
|
|
1104
|
+
this.heroBg.style.backgroundImage = url ? `url("${url.replace(/"/g, "%22")}")` : "";
|
|
1105
|
+
this.heroBg.classList.toggle("pw-active", !!url);
|
|
1021
1106
|
}
|
|
1022
1107
|
updatePlayPauseState(playing) {
|
|
1023
1108
|
if (this.playBtn) this.playBtn.style.display = playing ? "none" : "flex";
|
|
@@ -1104,4 +1189,5 @@ var FullPlayer = (_class5 = class extends EventEmitter {
|
|
|
1104
1189
|
|
|
1105
1190
|
|
|
1106
1191
|
|
|
1107
|
-
|
|
1192
|
+
|
|
1193
|
+
exports.AudioEngine = AudioEngine; exports.DEFAULT_CONFIG = DEFAULT_CONFIG; exports.EventEmitter = EventEmitter; exports.FetchEpisodeProvider = FetchEpisodeProvider; exports.FullPlayer = FullPlayer; exports.ICONS = ICONS; exports.MiniPlayer = MiniPlayer; exports.PLAYER_STATE_VERSION = PLAYER_STATE_VERSION; exports.PlaybackStorage = PlaybackStorage; exports.PlayerController = PlayerController; exports.PlayerStateStorage = PlayerStateStorage; exports.SPEED_OPTIONS = SPEED_OPTIONS; exports.escapeHtml = escapeHtml; exports.formatDate = formatDate; exports.formatDuration = formatDuration; exports.formatTime = formatTime; exports.getEpisodeImage = getEpisodeImage; exports.renderPlaylist = renderPlaylist; exports.renderPlaylistItem = renderPlaylistItem; exports.resolveConfig = resolveConfig;
|